浏览代码

Split lighting for all materials into diffuse and specular

/main
Evgenii Golubev 8 年前
当前提交
d1ed6394
共有 9 个文件被更改,包括 328 次插入102 次删除
  1. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  2. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs
  3. 33
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
  4. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute
  5. 214
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  6. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  7. 34
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  8. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
  9. 95
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs

18
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


// Bind material data
m_LitRenderLoop.Bind();
m_lightLoop.RenderDeferredLighting(hdCamera, renderContext, colorRTs);
// Output split lighting for materials tagged with the SSS stencil bit.
m_lightLoop.RenderDeferredLighting(hdCamera, renderContext, colorRTs, m_CameraDepthBufferRT, true);
/* TODO-READ_DEPTH-TEST_STENCIL
* In Unity, it is currently not possible to perform the stencil test while at the same time
* reading from the depth texture in the shader. It is legal in Direct3D.
* Therefore, we are forced to split lighting using MRT for all materials.
// Output combined lighting for all the other materials.
m_lightLoop.RenderDeferredLighting(hdCamera, renderContext, colorRTs, m_CameraDepthBufferRT, false);
*/
// Currently, forward-rendered objects do not output the split lighting information required for SSS.
// Currently, forward-rendered objects do not output split lighting required for the SSS pass.
if (debugParameters.ShouldUseForwardRenderingOnly()) return;
int screenWidth = (int)hdCamera.screenSize.x;

// We compute subsurface scattering here. Therefore, no objects rendered afterwards will exhibit SSS.
// Currently, there is no efficient way to switch between SRT and MRT for the forward pass;
// therefore, forward-rendered objects do not output the split lighting information required for SSS.
// therefore, forward-rendered objects do not output split lighting required for the SSS pass.
CombineSubsurfaceScattering(hdCamera, renderContext);
// For opaque forward we have split rendering in two categories

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/LightLoop.cs


public virtual void PushGlobalParams(Camera camera, ScriptableRenderContext loop) {}
public virtual void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier[] cameraColorBufferRTs) {}
public virtual void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthStencilBuffer,
bool outputSplitLighting) {}
public virtual void RenderForward(Camera camera, ScriptableRenderContext renderContext, bool renderOpaque) {}

33
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader


// We need to be able to control the blend mode for deferred shader in case we do multiple pass
_SrcBlend("", Float) = 1
_DstBlend("", Float) = 1
_StencilRef("_StencilRef", Int) = 0
}
SubShader

{
/* TODO-READ_DEPTH-TEST_STENCIL
* In Unity, it is currently not possible to perform the stencil test while at the same time
* reading from the depth texture in the shader. It is legal in Direct3D.
* Therefore, we are forced to split lighting using MRT for all materials.
Stencil
{
Ref [_StencilRef]
Comp Equal
Pass Keep
}
*/
Blend Off
Blend[_SrcBlend][_DstBlend]
ZTest Always
Blend [_SrcBlend][_DstBlend]
HLSLPROGRAM
#pragma target 5.0

// Chose supported lighting architecture in case of deferred rendering
#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS
//#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF
//#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF
// Split lighting is utilized during the SSS pass.
#pragma multi_compile _ OUTPUT_SPLIT_LIGHTING
//-------------------------------------------------------------------------------------
// Include

struct Outputs
{
#ifdef OUTPUT_SPLIT_LIGHTING
#else
float4 combinedLighting : SV_Target0;
#endif
};
Varyings Vert(Attributes input)

LightLoop(V, posInput, preLightData, bsdfData, bakeDiffuseLighting, diffuseLighting, specularLighting);
Outputs outputs;
#ifdef OUTPUT_SPLIT_LIGHTING
#else
outputs.combinedLighting = float4(diffuseLighting + specularLighting, 1.0);
#endif
return outputs;
}

18
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute


#pragma kernel ShadeOpaque_Fptl SHADE_OPAQUE_ENTRY=ShadeOpaque_Fptl USE_FPTL_LIGHTLIST=1
#pragma kernel ShadeOpaque_Clustered SHADE_OPAQUE_ENTRY=ShadeOpaque_Clustered USE_CLUSTERED_LIGHTLIST=1
// Split lighting is required for the SSS pass.
// Not currently possible since we need to access the stencil buffer from the compute shader.
// #pragma multi_compile _ OUTPUT_SPLIT_LIGHTING
#define LIGHTLOOP_TILE_PASS 1
#define LIGHTLOOP_TILE_DIRECT 1

//-------------------------------------------------------------------------------------
// Include

TEXTURE2D(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
RWTexture2D<float4> specularLightingUAV;
RWTexture2D<float3> diffuseLightingUAV;
#ifdef OUTPUT_SPLIT_LIGHTING
RWTexture2D<float4> specularLightingUAV;
RWTexture2D<float3> diffuseLightingUAV;
#else
RWTexture2D<float4> combinedLightingUAV;
#endif
[numthreads(TILE_SIZE, TILE_SIZE, 1)]
void SHADE_OPAQUE_ENTRY(uint2 dispatchThreadId : SV_DispatchThreadID, uint2 groupId : SV_GroupID)

float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, bakeDiffuseLighting, diffuseLighting, specularLighting);
specularLightingUAV[pixelCoord] = float4(diffuseLighting + specularLighting, 1.0);
#ifdef OUTPUT_SPLIT_LIGHTING
specularLightingUAV[pixelCoord] = float4(specularLighting, 1.0);
#else
combinedLightingUAV[pixelCoord] = float4(diffuseLighting + specularLighting, 1.0);
#endif
}

214
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


}
}
Material m_DeferredDirectMaterial = null;
Material m_DeferredIndirectMaterial = null;
Material m_DeferredAllMaterial = null;
Material m_DebugViewTilesMaterial = null;
Material m_DeferredDirectMaterialSRT = null;
Material m_DeferredDirectMaterialMRT = null;
Material m_DeferredIndirectMaterialSRT = null;
Material m_DeferredIndirectMaterialMRT = null;
Material m_DeferredAllMaterialSRT = null;
Material m_DeferredAllMaterialMRT = null;
Material m_DebugViewTilesMaterial = null;
Material m_SingleDeferredMaterial = null;
Material m_SingleDeferredMaterialSRT = null;
Material m_SingleDeferredMaterialMRT = null;
const int k_TileSize = 16;

s_LightList = null;
m_DeferredDirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredDirectMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredDirectMaterial.EnableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredDirectMaterial.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredDirectMaterial.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredDirectMaterialSRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredDirectMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredDirectMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredDirectMaterialSRT.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredDirectMaterialSRT.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredDirectMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredDirectMaterialSRT.SetInt("_StencilRef", (int)StencilBits.None);
m_DeferredDirectMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredDirectMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_DeferredDirectMaterialMRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredDirectMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredDirectMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredDirectMaterialMRT.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredDirectMaterialMRT.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredDirectMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredDirectMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_DeferredDirectMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredDirectMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_DeferredIndirectMaterialSRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredIndirectMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredIndirectMaterialSRT.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredIndirectMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredIndirectMaterialSRT.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredIndirectMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredIndirectMaterialSRT.SetInt("_StencilRef", (int)StencilBits.None);
m_DeferredIndirectMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredIndirectMaterialSRT.SetInt("_DstBlend", (int)BlendMode.One); // Additive
m_DeferredIndirectMaterialMRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredIndirectMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredIndirectMaterialMRT.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredIndirectMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredIndirectMaterialMRT.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredIndirectMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredIndirectMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_DeferredIndirectMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredIndirectMaterialMRT.SetInt("_DstBlend", (int)BlendMode.One); // Additive
m_DeferredIndirectMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredIndirectMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredIndirectMaterial.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredIndirectMaterial.EnableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredIndirectMaterial.DisableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredAllMaterialSRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredAllMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredAllMaterialSRT.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredAllMaterialSRT.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredAllMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredAllMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredAllMaterialSRT.SetInt("_StencilRef", (int)StencilBits.None);
m_DeferredAllMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredAllMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_DeferredAllMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredAllMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredAllMaterial.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredAllMaterial.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredAllMaterial.EnableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredAllMaterialMRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_DeferredAllMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredAllMaterialMRT.DisableKeyword("LIGHTLOOP_TILE_DIRECT");
m_DeferredAllMaterialMRT.DisableKeyword("LIGHTLOOP_TILE_INDIRECT");
m_DeferredAllMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_ALL");
m_DeferredAllMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredAllMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_DeferredAllMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredAllMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_SingleDeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_SingleDeferredMaterial.EnableKeyword("LIGHTLOOP_SINGLE_PASS");
m_SingleDeferredMaterialSRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_SingleDeferredMaterialSRT.EnableKeyword("LIGHTLOOP_SINGLE_PASS");
m_SingleDeferredMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_SingleDeferredMaterialSRT.SetInt("_StencilRef", (int)StencilBits.None);
m_SingleDeferredMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_SingleDeferredMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_SingleDeferredMaterialMRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
m_SingleDeferredMaterialMRT.EnableKeyword("LIGHTLOOP_SINGLE_PASS");
m_SingleDeferredMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_SingleDeferredMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_SingleDeferredMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_SingleDeferredMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_DefaultTexture2DArray = new Texture2DArray(1, 1, 1, TextureFormat.ARGB32, false);
m_DefaultTexture2DArray.SetPixels32(new Color32[1] { new Color32(128, 128, 128, 128) }, 0);

// enableClustered
Utilities.SafeRelease(s_GlobalLightListAtomic);
Utilities.Destroy(m_DeferredDirectMaterial);
Utilities.Destroy(m_DeferredIndirectMaterial);
Utilities.Destroy(m_DeferredAllMaterial);
Utilities.Destroy(m_DeferredDirectMaterialSRT);
Utilities.Destroy(m_DeferredDirectMaterialMRT);
Utilities.Destroy(m_DeferredIndirectMaterialSRT);
Utilities.Destroy(m_DeferredIndirectMaterialMRT);
Utilities.Destroy(m_DeferredAllMaterialSRT);
Utilities.Destroy(m_DeferredAllMaterialMRT);
Utilities.Destroy(m_SingleDeferredMaterial);
Utilities.Destroy(m_SingleDeferredMaterialSRT);
Utilities.Destroy(m_SingleDeferredMaterialMRT);
}
public override void NewFrame()

}
#endif
public override void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier[] cameraColorBufferRTs)
public override void RenderDeferredLighting(HDRenderPipeline.HDCamera hdCamera, ScriptableRenderContext renderContext,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthStencilBuffer,
bool outputSplitLighting)
{
var bUseClusteredForDeferred = !usingFptl;

if (disableTileAndCluster)
{
Utilities.SetupMaterialHDCamera(hdCamera, m_SingleDeferredMaterial);
m_SingleDeferredMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_SingleDeferredMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
if (outputSplitLighting)
{
/* TODO-READ_DEPTH-TEST_STENCIL
* In Unity, it is currently not possible to perform the stencil test while at the same time
* reading from the depth texture in the shader. It is legal in Direct3D.
* Therefore, we are forced to split lighting using MRT for all materials.
*/
Utilities.DrawFullscreen(cmd, m_SingleDeferredMaterial, cameraColorBufferRTs, 0);
Utilities.DrawFullscreen(cmd, m_SingleDeferredMaterialMRT, hdCamera, colorBuffers/*, depthStencilBuffer*/);
}
else
{
Utilities.DrawFullscreen(cmd, m_SingleDeferredMaterialSRT, hdCamera, colorBuffers[0], depthStencilBuffer);
}
}
else
{

cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_IESArray", IESArrayTexture ? IESArrayTexture : m_DefaultTexture2DArray);
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "_SkyTexture", skyTexture ? skyTexture : m_DefaultTexture2DArray);
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "specularLightingUAV", cameraColorBufferRTs[0]);
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "diffuseLightingUAV", cameraColorBufferRTs[1]);
// Since we need the stencil test, the compute path does not currently support SSS.
cmd.SetComputeTextureParam(shadeOpaqueShader, kernel, "combinedLightingUAV", colorBuffers[0]);
cmd.DispatchCompute(shadeOpaqueShader, kernel, numTilesX, numTilesY, 1);
}
else

{
Utilities.SetupMaterialHDCamera(hdCamera, m_DeferredDirectMaterial);
m_DeferredDirectMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredDirectMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m_DeferredDirectMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredDirectMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
if (outputSplitLighting)
{
m_DeferredDirectMaterialMRT.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredDirectMaterialMRT.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
/* TODO-READ_DEPTH-TEST_STENCIL
* In Unity, it is currently not possible to perform the stencil test while at the same time
* reading from the depth texture in the shader. It is legal in Direct3D.
* Therefore, we are forced to split lighting using MRT for all materials.
*/
Utilities.DrawFullscreen(cmd, m_DeferredDirectMaterialMRT, hdCamera, colorBuffers/*, depthStencilBuffer*/);
/* TODO-READ_DEPTH-TEST_STENCIL
* In Unity, it is currently not possible to perform the stencil test while at the same time
* reading from the depth texture in the shader. It is legal in Direct3D.
* Therefore, we are forced to split lighting using MRT for all materials.
*/
m_DeferredIndirectMaterialMRT.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredIndirectMaterialMRT.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.DrawFullscreen(cmd, m_DeferredIndirectMaterialMRT, hdCamera, colorBuffers/*, depthStencilBuffer*/);
}
else
{
m_DeferredDirectMaterialSRT.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredDirectMaterialSRT.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.DrawFullscreen(cmd, m_DeferredDirectMaterialSRT, hdCamera, colorBuffers[0], depthStencilBuffer);
Utilities.SetupMaterialHDCamera(hdCamera, m_DeferredIndirectMaterial);
m_DeferredIndirectMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredIndirectMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One); // Additive
m_DeferredIndirectMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredIndirectMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredIndirectMaterialSRT.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredIndirectMaterialSRT.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.DrawFullscreen(cmd, m_DeferredDirectMaterial, cameraColorBufferRTs, 0);
Utilities.DrawFullscreen(cmd, m_DeferredIndirectMaterial, cameraColorBufferRTs, 0);
Utilities.DrawFullscreen(cmd, m_DeferredIndirectMaterialSRT, hdCamera, colorBuffers, depthStencilBuffer);
}
Utilities.SetupMaterialHDCamera(hdCamera, m_DeferredAllMaterial);
m_DeferredAllMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredAllMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
m_DeferredAllMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredAllMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
if (outputSplitLighting)
{
m_DeferredAllMaterialMRT.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredAllMaterialMRT.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.DrawFullscreen(cmd, m_DeferredAllMaterial, cameraColorBufferRTs, 0);
/* TODO-READ_DEPTH-TEST_STENCIL
* In Unity, it is currently not possible to perform the stencil test while at the same time
* reading from the depth texture in the shader. It is legal in Direct3D.
* Therefore, we are forced to split lighting using MRT for all materials.
*/
Utilities.DrawFullscreen(cmd, m_DeferredAllMaterialMRT, hdCamera, colorBuffers/*, depthStencilBuffer*/);
}
else
{
m_DeferredAllMaterialSRT.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredAllMaterialSRT.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
Utilities.DrawFullscreen(cmd, m_DeferredAllMaterialSRT, hdCamera, colorBuffers[0], depthStencilBuffer);
}
}
}

m_DebugViewTilesMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DebugViewTilesMaterial.DisableKeyword(!bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
cmd.Blit(null, cameraColorBufferRTs[0], m_DebugViewTilesMaterial, 0);
cmd.Blit(null, colorBuffers[0], m_DebugViewTilesMaterial, 0);
}
}

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


public static GUIContent detailMapModeText = new GUIContent("Detail Map with Normal", "Detail Map with AO / Height");
public static GUIContent UVDetailMappingText = new GUIContent("UV set for Detail", "");
public static GUIContent subsurfaceScatteringText = new GUIContent("Subsurface Scattering", "Enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk");
public static GUIContent emissiveColorModeText = new GUIContent("Emissive Color Usage", "Use emissive color or emissive mask");
public static string InputsText = "Inputs";

34
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{

UseEmissiveMask,
}
public enum SubsurfaceScattering
{
Disabled,
Enabled
}
protected MaterialProperty smoothnessMapChannel = null;
protected const string kSmoothnessTextureChannel = "_SmoothnessTextureChannel";
protected MaterialProperty UVBase = null;

protected const string kUVDetail = "_UVDetail";
protected MaterialProperty UVDetailsMappingMask = null;
protected const string kUVDetailsMappingMask = "_UVDetailsMappingMask";
protected MaterialProperty subsurfaceScattering = null;
protected const string kSubsurfaceScattering = "_SubsurfaceScattering";
protected MaterialProperty emissiveColorMode = null;
protected const string kEmissiveColorMode = "_EmissiveColorMode";

ppdMinSamples = FindProperty(kPpdMinSamples, props);
ppdMaxSamples = FindProperty(kPpdMaxSamples, props);
detailMapMode = FindProperty(kDetailMapMode, props);
subsurfaceScattering = FindProperty(kSubsurfaceScattering, props);
emissiveColorMode = FindProperty(kEmissiveColorMode, props);
}

EditorGUI.indentLevel++;
GUILayout.Label(Styles.InputsOptionsText, EditorStyles.boldLabel);
m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText.text);
m_MaterialEditor.ShaderProperty(UVBase, enableUVDetail ? Styles.UVBaseDetailMappingText.text : Styles.UVBaseMappingText.text);
m_MaterialEditor.ShaderProperty(smoothnessMapChannel, Styles.smoothnessMapChannelText);
m_MaterialEditor.ShaderProperty(UVBase, enableUVDetail ? Styles.UVBaseDetailMappingText : Styles.UVBaseMappingText);
float X, Y, Z, W;
X = ((UVBaseMapping)UVBase.floatValue == UVBaseMapping.UV0) ? 1.0f : 0.0f;

{
EditorGUI.indentLevel++;
m_MaterialEditor.ShaderProperty(TexWorldScale, Styles.texWorldScaleText.text);
m_MaterialEditor.ShaderProperty(TexWorldScale, Styles.texWorldScaleText);
m_MaterialEditor.ShaderProperty(UVDetail, Styles.UVDetailMappingText.text);
m_MaterialEditor.ShaderProperty(UVDetail, Styles.UVDetailMappingText);
}
X = ((UVDetailMapping)UVDetail.floatValue == UVDetailMapping.UV0) ? 1.0f : 0.0f;

UVDetailsMappingMask.colorValue = new Color(X, Y, Z, W);
//m_MaterialEditor.ShaderProperty(detailMapMode, Styles.detailMapModeText.text);
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText.text);
m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText.text);
m_MaterialEditor.ShaderProperty(enablePerPixelDisplacement, Styles.enablePerPixelDisplacementText.text);
m_MaterialEditor.ShaderProperty(ppdMinSamples, Styles.ppdMinSamplesText.text);
m_MaterialEditor.ShaderProperty(ppdMaxSamples, Styles.ppdMaxSamplesText.text);
//m_MaterialEditor.ShaderProperty(detailMapMode, Styles.detailMapModeText);
m_MaterialEditor.ShaderProperty(normalMapSpace, Styles.normalMapSpaceText);
m_MaterialEditor.ShaderProperty(emissiveColorMode, Styles.emissiveColorModeText);
m_MaterialEditor.ShaderProperty(enablePerPixelDisplacement, Styles.enablePerPixelDisplacementText);
m_MaterialEditor.ShaderProperty(ppdMinSamples, Styles.ppdMinSamplesText);
m_MaterialEditor.ShaderProperty(ppdMaxSamples, Styles.ppdMaxSamplesText);
m_MaterialEditor.ShaderProperty(subsurfaceScattering, Styles.subsurfaceScatteringText);
EditorGUI.indentLevel--;
}

SetKeyword(material, "_TANGENTMAP", material.GetTexture(kTangentMap));
SetKeyword(material, "_ANISOTROPYMAP", material.GetTexture(kAnisotropyMap));
SetKeyword(material, "_DETAIL_MAP", material.GetTexture(kDetailMap));
bool enableSSS = material.GetFloat(kSubsurfaceScattering) != 0.0f;
material.SetInt("_StencilRef", (int)(enableSSS ? StencilBits.SSS : StencilBits.None));
bool needUV2 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV2 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0;
bool needUV3 = (UVDetailMapping)material.GetFloat(kUVDetail) == UVDetailMapping.UV3 && (UVBaseMapping)material.GetFloat(kUVBase) == UVBaseMapping.UV0;

13
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader


_DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(-2.0, 2.0)) = 1
_DetailHeightScale("_DetailHeightScale", Range(-2.0, 2.0)) = 1
_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1
_DetailAOScale("_DetailAOScale", Range(-2.0, 2.0)) = 1
[ToggleOff] _SubsurfaceScattering("Subsurface Scattering", Int) = 0
_SubSurfaceRadius("SubSurfaceRadius", Range(0.0, 1.0)) = 0
_SubSurfaceRadiusMap("SubSurfaceRadiusMap", 2D) = "white" {}
//_Thickness("Thickness", Range(0.0, 1.0)) = 0

[ToggleOff] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// Stencil state
[HideInInspector] _StencilRef("_StencilRef", Int) = 0
// Blending state
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0

Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
Cull [_CullMode]
Stencil
{
Ref [_StencilRef]
Comp Always
Pass Replace
}
HLSLPROGRAM

95
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


[Flags]
public enum ClearFlag
{
ClearNone = 0,
ClearNone = 0,
}
[Flags]
public enum StencilBits
{
None = 0,
SSS = 1,
All = 255
}
public class Utilities

cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
static Mesh m_ScreenSpaceTriangle = new Mesh
{
// Note: the vertex data is not actually used if the vertex shader computes vertices using 'SV_VertexID'.
// However, there is currently no way to bind a NULL vertex buffer.
vertices = new [] { new Vector3(-1, -1, 1), new Vector3(3, -1, 1), new Vector3(-1, 3, 1) },
triangles = new [] { 0, 1, 2 }
};
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
public static void DrawFullscreen(CommandBuffer commandBuffer, Material material, RenderTargetIdentifier colorBuffer, int shaderPassID = 0)
{
commandBuffer.SetRenderTarget(colorBuffer);
commandBuffer.DrawMesh(m_ScreenSpaceTriangle, Matrix4x4.identity, material, 0, shaderPassID);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
// Important: the first RenderTarget must be created with 0 depth bits!
public static void DrawFullscreen(CommandBuffer commandBuffer, Material material, RenderTargetIdentifier[] colorBuffers, int shaderPassID = 0)
{
// It is currently not possible to have MRT without also setting a depth target.
// To work around this deficiency of the CommandBuffer.SetRenderTarget() API,
// we pass the first color target as the depth target. If it has 0 depth bits,
// no depth target ends up being bound.
commandBuffer.SetRenderTarget(colorBuffers, colorBuffers[0]);
commandBuffer.DrawMesh(m_ScreenSpaceTriangle, Matrix4x4.identity, material, 0, shaderPassID);
}
// Miscellanous

}
return renderContext;
}
static Mesh m_ScreenSpaceTriangle = null;
public static Mesh GetScreenSpaceTriangle()
{
// If the assembly has been reloaded, the pointer will become NULL.
if (!m_ScreenSpaceTriangle)
{
m_ScreenSpaceTriangle = new Mesh
{
// Note: the vertex data is not actually used if the vertex shader computes vertices using 'SV_VertexID'.
// However, there is currently no way to bind a NULL vertex buffer.
vertices = new[] { new Vector3(-1, -1, 1), new Vector3(3, -1, 1), new Vector3(-1, 3, 1) },
triangles = new[] { 0, 1, 2 }
};
}
return m_ScreenSpaceTriangle;
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
public static void DrawFullscreen(CommandBuffer commandBuffer, Material material, HDRenderPipeline.HDCamera camera,
RenderTargetIdentifier colorBuffer, int shaderPassID = 0)
{
SetupMaterialHDCamera(camera, material);
commandBuffer.SetRenderTarget(colorBuffer);
commandBuffer.DrawMesh(GetScreenSpaceTriangle(), Matrix4x4.identity, material, 0, shaderPassID);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
public static void DrawFullscreen(CommandBuffer commandBuffer, Material material, HDRenderPipeline.HDCamera camera,
RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthStencilBuffer, int shaderPassID = 0)
{
SetupMaterialHDCamera(camera, material);
commandBuffer.SetRenderTarget(colorBuffer, depthStencilBuffer);
commandBuffer.DrawMesh(GetScreenSpaceTriangle(), Matrix4x4.identity, material, 0, shaderPassID);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
public static void DrawFullscreen(CommandBuffer commandBuffer, Material material, HDRenderPipeline.HDCamera camera,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthStencilBuffer, int shaderPassID = 0)
{
SetupMaterialHDCamera(camera, material);
commandBuffer.SetRenderTarget(colorBuffers, depthStencilBuffer);
commandBuffer.DrawMesh(GetScreenSpaceTriangle(), Matrix4x4.identity, material, 0, shaderPassID);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
// Important: the first RenderTarget must be created with 0 depth bits!
public static void DrawFullscreen(CommandBuffer commandBuffer, Material material, HDRenderPipeline.HDCamera camera,
RenderTargetIdentifier[] colorBuffers, int shaderPassID = 0)
{
// It is currently not possible to have MRT without also setting a depth target.
// To work around this deficiency of the CommandBuffer.SetRenderTarget() API,
// we pass the first color target as the depth target. If it has 0 depth bits,
// no depth target ends up being bound.
DrawFullscreen(commandBuffer, material, camera, colorBuffers, colorBuffers[0], shaderPassID);
}
}
}
正在加载...
取消
保存