浏览代码

Merge remote-tracking branch 'refs/remotes/origin/master' into Precompute-ShaderIds

# Conflicts:

#	Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
/RenderPassXR_Sandbox
sebastienlagarde 7 年前
当前提交
8ad5a2cb
共有 5 个文件被更改,包括 36 次插入19 次删除
  1. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  3. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/materialflags.compute
  4. 21
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CopyStencilBuffer.shader
  5. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


readonly GBufferManager m_gbufferManager = new GBufferManager();
Material m_CopyStencilBuffer;
Material m_CopyStencilForSplitLighting;
Material m_CopyStencilForRegularLighting;
// Various set of material use in render loop
ComputeShader m_SubsurfaceScatteringCS { get { return m_Asset.renderPipelineResources.subsurfaceScatteringCS; } }

CreateSssMaterials(sssSettings.useDisneySSS);
// <<< Old SSS Model
m_CopyStencilBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CopyStencilBuffer");
m_CameraMotionVectorsMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CameraMotionVectors");
m_CopyStencilForSplitLighting = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CopyStencilBuffer");
m_CopyStencilForSplitLighting.EnableKeyword("EXPORT_HTILE");
m_CopyStencilForSplitLighting.SetInt("_StencilRef", (int)StencilLightingUsage.SplitLighting);
m_CopyStencilForRegularLighting = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CopyStencilBuffer");
m_CopyStencilForRegularLighting.DisableKeyword("EXPORT_HTILE");
m_CopyStencilForRegularLighting.SetInt("_StencilRef", (int)StencilLightingUsage.RegularLighting);
m_CameraMotionVectorsMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CameraMotionVectors");
InitializeDebugMaterials();

using (new Utilities.ProfilingSample("Copy StencilBuffer", cmd))
{
cmd.SetRandomWriteTarget(1, GetHTile());
Utilities.DrawFullScreen(cmd, m_CopyStencilBuffer, m_CameraStencilBufferCopyRT, m_CameraDepthStencilBufferRT);
// Our method of exporting the stencil requires one pass per unique stencil value.
Utilities.DrawFullScreen(cmd, m_CopyStencilForSplitLighting, m_CameraStencilBufferCopyRT, m_CameraDepthStencilBufferRT);
Utilities.DrawFullScreen(cmd, m_CopyStencilForRegularLighting, m_CameraStencilBufferCopyRT, m_CameraDepthStencilBufferRT);
cmd.ClearRandomWriteTargets();
}
}

m_LightLoop.PrepareLightsForGPU(m_ShadowSettings, m_CullResults, camera);
m_LightLoop.RenderShadows(renderContext, cmd, m_CullResults);
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
m_LightLoop.BuildGPULightLists(camera, cmd, m_CameraDepthStencilBufferRT);
m_LightLoop.BuildGPULightLists(camera, cmd, m_CameraDepthStencilBufferRT, GetStencilTexture());
}
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


cmd.DispatchCompute(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, numTilesX, numTilesY, 1);
}
public void BuildGPULightLists(Camera camera, CommandBuffer cmd, RenderTargetIdentifier cameraDepthBufferRT)
public void BuildGPULightLists(Camera camera, CommandBuffer cmd, RenderTargetIdentifier cameraDepthBufferRT, RenderTargetIdentifier stencilTextureRT)
{
var w = camera.pixelWidth;
var h = camera.pixelHeight;

cmd.SetComputeIntParams(buildMaterialFlagsShader, HDShaderIDs.viDimensions, w, h);
cmd.SetComputeBufferParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.TileFeatureFlags, s_TileFeatureFlags);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.depth_tex, cameraDepthBufferRT);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.StencilTexture, cameraDepthBufferRT);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.GBufferTexture0, HDShaderIDs.GBufferTexture0);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.GBufferTexture1, HDShaderIDs.GBufferTexture1);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.GBufferTexture2, HDShaderIDs.GBufferTexture2);

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/materialflags.compute


#pragma kernel MaterialFlagsGen_Write MATERIALFLAGSGEN=MaterialFlagsGen_Write
#pragma kernel MaterialFlagsGen_Or MATERIALFLAGSGEN=MaterialFlagsGen_Or USE_OR
//#pragma #pragma enable_d3d11_debug_symbols
// #pragma enable_d3d11_debug_symbols
#include "../../../ShaderLibrary/common.hlsl"
#include "ShaderBase.hlsl"

#include "../../Material/Material.hlsl" // This includes Material.hlsl
#include "../../Lighting/LightDefinition.cs.hlsl"
#define USE_MATERIAL_FEATURE_FLAGS
#define NR_THREADS 64

uint g_BaseFeatureFlags;
CBUFFER_END
Texture2D g_depth_tex : register( t0 );
TEXTURE2D(_StencilTexture); // DXGI_FORMAT_R8_UINT is not supported by Unity
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
[numthreads(NR_THREADS, 1, 1)]

int idx = i * NR_THREADS + threadID;
uint2 uCrd = min( uint2(viTilLL.x + (idx & 0xf), viTilLL.y + (idx >> 4)), uint2(iWidth - 1, iHeight - 1));
if (FetchDepth(g_depth_tex, uCrd) < VIEWPORT_SCALE_Z) // This test is we are the sky/background or not
if (UnpackByte(LOAD_TEXTURE2D(_StencilTexture, uCrd).r) != STENCILLIGHTINGUSAGE_NO_LIGHTING) // This test is we are the sky/background or not
{
PositionInputs posInput = GetPositionInput(uCrd, invScreenSize);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);

21
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CopyStencilBuffer.shader


Shader "Hidden/HDRenderPipeline/CopyStencilBuffer"
{
Properties
{
[HideInInspector] _StencilRef("_StencilRef", Int) = 1
}
SubShader
{
Pass

Ref 1 // StencilLightingUsage.SplitLighting
Ref [_StencilRef]
Comp Equal
Pass Keep
}

HLSLPROGRAM
#pragma target 4.5
#pragma only_renderers d3d11 ps4 metal // TEMP: until we go further in dev
#pragma multi_compile _ EXPORT_HTILE
#include "../../../../ShaderLibrary/Common.hlsl"
#include "../../../../ShaderLibrary/Packing.hlsl"
int _StencilRef;
RW_TEXTURE2D(float, _HTile); // DXGI_FORMAT_R8_UINT is not supported by Unity
struct Attributes

{
uint2 positionSS = (uint2)input.positionCS.xy;
// There's no need for atomics as we are always writing the same value.
// Note: the GCN tile size is 8x8 pixels.
_HTile[positionSS / 8] = STENCILLIGHTINGUSAGE_SPLIT_LIGHTING;
#ifdef EXPORT_HTILE
// There's no need for atomics as we are always writing the same value.
// Note: the GCN tile size is 8x8 pixels.
_HTile[positionSS / 8] = _StencilRef;
#endif
return float4(STENCILLIGHTINGUSAGE_SPLIT_LIGHTING, 0, 0, 0);
return PackByte(_StencilRef);
}
ENDHLSL
}

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute


// Included headers
//--------------------------------------------------------------------------------------------------
#include "../../../../ShaderLibrary/Common.hlsl"
#include "../../../../ShaderLibrary/Packing.hlsl"
#include "../../../../ShaderLibrary/SpaceFillingCurves.hlsl"
#include "../../../ShaderVariables.hlsl"
#define UNITY_MATERIAL_LIT

{
// Unfortunately, our copy of HTile does not allow to accept at the tile rate.
// Therefore, we have to additionally perform the stencil test at the pixel rate.
passedStencilTest = stencilRef == LOAD_TEXTURE2D(_StencilTexture, pixelCoord).r;
passedStencilTest = stencilRef == UnpackByte(LOAD_TEXTURE2D(_StencilTexture, pixelCoord).r);
}
return passedStencilTest;

正在加载...
取消
保存