浏览代码

Add an option to globally disable SSS

/Branch_Batching2
Evgenii Golubev 8 年前
当前提交
c444fb8a
共有 12 个文件被更改,包括 93 次插入19 次删除
  1. 24
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop.cs
  3. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader
  4. 20
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 20
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
  6. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  7. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  8. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  9. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  10. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs
  11. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs
  12. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources.meta

24
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


Shader.SetGlobalFloatArray("_ThicknessScales", sssParameters.thicknessScales);
Shader.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights);
if (sssParameters.enableSSS)
{
Shader.EnableKeyword("_SUBSURFACE_SCATTERING");
}
else
{
Shader.DisableKeyword("_SUBSURFACE_SCATTERING");
}
var cmd = new CommandBuffer {name = "Push Global Parameters"};
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);

// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, renderContext);
RenderDeferredLighting(hdCamera, renderContext);
RenderDeferredLighting(hdCamera, renderContext, m_Owner.sssParameters.enableSSS);
// 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;

}
}
void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext)
void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext, bool enableSSS)
{
if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly() || m_LightLoop == null)
{

RenderTargetIdentifier[] colorRTs = { m_CameraColorBufferRT, m_CameraSubsurfaceBufferRT };
// Output split lighting for materials tagged with the SSS stencil bit.
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugParameters.lightingDebugParameters, colorRTs, m_CameraStencilBufferRT, true);
if (enableSSS)
{
// Output split lighting for materials tagged with the SSS stencil bit.
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugParameters.lightingDebugParameters, colorRTs, m_CameraStencilBufferRT, true, enableSSS);
}
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugParameters.lightingDebugParameters, colorRTs, m_CameraStencilBufferRT, false);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugParameters.lightingDebugParameters, colorRTs, m_CameraStencilBufferRT, false, enableSSS);
}
// Combines specular lighting and diffuse lighting with subsurface scattering.

if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly()) return;
if (!sssParameters.enableSSS) return;
var cmd = new CommandBuffer() { name = "Subsurface Scattering Pass" };

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop.cs


public virtual void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext,
LightingDebugParameters lightDebugParameters,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier stencilBuffer,
bool outputSplitLighting) {}
bool outputSplitLightingForSSS, bool enableSSS) {}
public virtual void RenderForward(Camera camera, ScriptableRenderContext renderContext, bool renderOpaque) {}

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader


_SrcBlend("", Float) = 1
_DstBlend("", Float) = 1
_StencilRef("_StencilRef", Int) = 0
_StencilRef("", Int) = 0
_StencilCmp("", Int) = 3
}
SubShader

Stencil
{
Ref [_StencilRef]
Comp Equal
Comp [_StencilCmp]
Pass Keep
}

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


m_DeferredDirectMaterialSRT.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredDirectMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredDirectMaterialSRT.SetInt("_StencilRef", (int)StencilBits.Standard);
m_DeferredDirectMaterialSRT.SetInt("_StencilCmp", 7 /* GEqual */);
m_DeferredDirectMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredDirectMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);

m_DeferredDirectMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredDirectMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_DeferredDirectMaterialMRT.SetInt("_StencilCmp", 3 /* Equal */);
m_DeferredDirectMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredDirectMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);

m_DeferredIndirectMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredIndirectMaterialSRT.SetInt("_StencilRef", (int)StencilBits.Standard);
m_DeferredIndirectMaterialSRT.SetInt("_StencilCmp", 7 /* GEqual */);
m_DeferredIndirectMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredIndirectMaterialSRT.SetInt("_DstBlend", (int)BlendMode.One); // Additive color & alpha source

m_DeferredIndirectMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredIndirectMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_DeferredIndirectMaterialMRT.SetInt("_StencilCmp", 3 /* Equal */);
m_DeferredIndirectMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredIndirectMaterialMRT.SetInt("_DstBlend", (int)BlendMode.One); // Additive color & alpha source

m_DeferredAllMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredAllMaterialSRT.SetInt("_StencilRef", (int)StencilBits.Standard);
m_DeferredAllMaterialSRT.SetInt("_StencilCmp", 7 /* GEqual */);
m_DeferredAllMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredAllMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);

m_DeferredAllMaterialMRT.EnableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredAllMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_DeferredAllMaterialMRT.SetInt("_StencilCmp", 3 /* Equal */);
m_DeferredAllMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredAllMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);

m_SingleDeferredMaterialSRT.EnableKeyword("LIGHTLOOP_SINGLE_PASS");
m_SingleDeferredMaterialSRT.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_SingleDeferredMaterialSRT.SetInt("_StencilRef", (int)StencilBits.Standard);
m_SingleDeferredMaterialSRT.SetInt("_StencilCmp", 7 /* GEqual */);
m_SingleDeferredMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_SingleDeferredMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);

m_SingleDeferredMaterialMRT.SetInt("_StencilRef", (int)StencilBits.SSS);
m_SingleDeferredMaterialMRT.SetInt("_StencilCmp", 3 /* Equal */);
m_SingleDeferredMaterialMRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_SingleDeferredMaterialMRT.SetInt("_DstBlend", (int)BlendMode.Zero);

public override void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext,
LightingDebugParameters lightDebugParameters,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier stencilBuffer,
bool outputSplitLighting)
bool outputSplitLightingForSSS, bool enableSSS)
{
var bUseClusteredForDeferred = !usingFptl;

if (m_PassSettings.disableTileAndCluster)
{
// This is a debug brute force renderer to debug tile/cluster which render all the lights
if (outputSplitLighting)
if (outputSplitLightingForSSS)
m_SingleDeferredMaterialSRT.SetInt("_StencilRef", (int)(enableSSS ? StencilBits.Standard : StencilBits.SSS));
Utilities.DrawFullScreen(cmd, m_SingleDeferredMaterialSRT, hdCamera, colorBuffers[0], stencilBuffer);
}
}

// Pixel shader evaluation
if (m_PassSettings.enableSplitLightEvaluation)
{
if (outputSplitLighting)
if (outputSplitLightingForSSS)
{
Utilities.SelectKeyword(m_DeferredDirectMaterialMRT, "USE_CLUSTERED_LIGHTLIST", "USE_FPTL_LIGHTLIST", bUseClusteredForDeferred);
Utilities.DrawFullScreen(cmd, m_DeferredDirectMaterialMRT, hdCamera, colorBuffers, stencilBuffer);

}
else
{
m_DeferredDirectMaterialSRT.SetInt("_StencilRef", (int)(enableSSS ? StencilBits.Standard : StencilBits.SSS));
m_DeferredIndirectMaterialSRT.SetInt("_StencilRef", (int)(enableSSS ? StencilBits.Standard : StencilBits.SSS));
Utilities.SelectKeyword(m_DeferredIndirectMaterialSRT, "USE_CLUSTERED_LIGHTLIST", "USE_FPTL_LIGHTLIST", bUseClusteredForDeferred);
Utilities.DrawFullScreen(cmd, m_DeferredIndirectMaterialSRT, hdCamera, colorBuffers[0], stencilBuffer);
}

if (outputSplitLighting)
if (outputSplitLightingForSSS)
{
Utilities.SelectKeyword(m_DeferredAllMaterialMRT, "USE_CLUSTERED_LIGHTLIST", "USE_FPTL_LIGHTLIST", bUseClusteredForDeferred);
Utilities.DrawFullScreen(cmd, m_DeferredAllMaterialMRT, hdCamera, colorBuffers, stencilBuffer);

m_DeferredAllMaterialSRT.SetInt("_StencilRef", (int)(enableSSS ? StencilBits.Standard : StencilBits.SSS));
Utilities.SelectKeyword(m_DeferredAllMaterialSRT, "USE_CLUSTERED_LIGHTLIST", "USE_FPTL_LIGHTLIST", bUseClusteredForDeferred);
Utilities.DrawFullScreen(cmd, m_DeferredAllMaterialSRT, hdCamera, colorBuffers[0], stencilBuffer);
}

20
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs


SetKeyword(material, "_DEPTHOFFSET_ON", depthOffsetEnable);
if (material.HasProperty(kMaterialID))
material.SetInt("_StencilRef", 1 + (int)material.GetFloat(kMaterialID)); // See 'StencilBits'.
{
int materialID = (int)material.GetFloat(kMaterialID);
int stencilRef; // See 'StencilBits'.
switch (materialID)
{
case (int)UnityEngine.Experimental.Rendering.HDPipeline.Lit.MaterialId.LitSSS:
stencilRef = (int)UnityEngine.Experimental.Rendering.HDPipeline.StencilBits.SSS;
break;
case (int)UnityEngine.Experimental.Rendering.HDPipeline.Lit.MaterialId.LitStandard:
stencilRef = (int)UnityEngine.Experimental.Rendering.HDPipeline.StencilBits.Standard;
break;
default:
stencilRef = 1 + materialID;
break;
}
material.SetInt("_StencilRef", stencilRef);
}
bool enablePerPixelDisplacement = material.GetFloat(kEnablePerPixelDisplacement) > 0.0f;
SetKeyword(material, "_PER_PIXEL_DISPLACEMENT", enablePerPixelDisplacement);

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma shader_feature _SUBSURFACE_SCATTERING
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


// This part of the code is not used in case of layered shader but we keep the same macro system for simplicity
#if !defined(LAYERED_LIT_SHADER)
#ifdef _SUBSURFACE_SCATTERING
#else
surfaceData.materialId = (_MaterialID == MATERIALID_LIT_SSS) ? 0 : _MaterialID;
#endif
// TODO: think about using BC5
#ifdef _TANGENTMAP

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma shader_feature _SUBSURFACE_SCATTERING
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


{
Stencil
{
Ref 2 // StencilBits.SSS
Ref 1 // StencilBits.SSS
Comp Equal
Pass Keep
}

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs


public const int maxNumProfiles = 8;
[SerializeField]
bool m_EnableSSS;
[SerializeField]
int m_NumProfiles;
[SerializeField]
int m_TransmittanceFlags;

public SubsurfaceScatteringParameters()
{
m_EnableSSS = true;
m_NumProfiles = 1;
m_Profiles = new SubsurfaceScatteringProfile[m_NumProfiles];

}
OnValidate();
}
public bool enableSSS {
// Set via serialization.
get { return m_EnableSSS; }
}
public SubsurfaceScatteringProfile[] profiles {

{
public readonly GUIContent category = new GUIContent("Subsurface scattering parameters");
public readonly GUIContent[] profiles = new GUIContent[SubsurfaceScatteringParameters.maxNumProfiles] { new GUIContent("Profile #0"), new GUIContent("Profile #1"), new GUIContent("Profile #2"), new GUIContent("Profile #3"), new GUIContent("Profile #4"), new GUIContent("Profile #5"), new GUIContent("Profile #6"), new GUIContent("Profile #7") };
public readonly GUIContent profilePreview = new GUIContent("Profile preview. Note that the intensity of the region in the center may be clamped.");
public readonly GUIContent numProfiles = new GUIContent("Number of profiles");
public readonly GUIContent profileStdDev1 = new GUIContent("Standard deviation #1", "Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent profileStdDev2 = new GUIContent("Standard deviation #2", "Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");

}
private static Styles s_Styles;
private SerializedProperty m_Profiles, m_NumProfiles;
private SerializedProperty m_EnableSSS, m_Profiles, m_NumProfiles;
private Material m_ProfileMaterial;
private RenderTexture[] m_ProfileImages;

void OnEnable()
{
m_EnableSSS = serializedObject.FindProperty("m_EnableSSS");
m_Profiles = serializedObject.FindProperty("m_Profiles");
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
m_ProfileMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawGaussianProfile");

// Validate the data before displaying it.
((SubsurfaceScatteringParameters)serializedObject.targetObject).OnValidate();
EditorGUILayout.LabelField(styles.category);
EditorGUILayout.LabelField(styles.category, EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_EnableSSS);
EditorGUILayout.PropertyField(m_NumProfiles, styles.numProfiles);
EditorGUILayout.PropertyField(m_Profiles);

m_ProfileMaterial.SetFloat("_LerpWeight", profileLerpWeight.floatValue);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256, 256), m_ProfileImages[i], m_ProfileMaterial, ScaleMode.ScaleToFit);
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.profilePreview, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
EditorGUI.indentLevel--;

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs


public enum StencilBits
{
None = 0,
Standard = 1 + Lit.MaterialId.LitStandard,
SSS = 1 + Lit.MaterialId.LitSSS,
ClearCoat = 1 + Lit.MaterialId.LitClearCoat,
SSS = 0 + Lit.MaterialId.LitSSS, // 1
Standard = 2 + Lit.MaterialId.LitStandard, // 2
ClearCoat = 1 + Lit.MaterialId.LitClearCoat, // 3
All = 255 // 0xff
}

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources.meta


fileFormatVersion: 2
guid: 12566b1a9c5807b4f8d3d0409255095a
folderAsset: yes
timeCreated: 1487178659
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存