浏览代码

Make it work in full forward, fix other compil issue. Disney/Jimenez ok, transmission not working

/main
Sebastien Lagarde 7 年前
当前提交
13cec969
共有 12 个文件被更改,包括 152 次插入77 次删除
  1. 6
      ScriptableRenderPipeline/Core/ShaderLibrary/CommonLighting.hlsl
  2. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  4. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  5. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  6. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  7. 14
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  8. 70
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl
  9. 2
      ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawSssProfile.shader
  10. 1
      ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader
  11. 61
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/CommonSubsurfaceScattering.hlsl
  12. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/CommonSubsurfaceScattering.hlsl.meta

6
ScriptableRenderPipeline/Core/ShaderLibrary/CommonLighting.hlsl


return area;
}
// Ref: Steve McAuley - Energy-Conserving Wrapped Diffuse
float ComputeWrappedDiffuseLighting(float NdotL, float w)
{
return saturate((NdotL + w) / ((1 + w) * (1 + w)));
}
//-----------------------------------------------------------------------------
// Helper functions
//-----------------------------------------------------------------------------

17
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


// Combines specular lighting and diffuse lighting with subsurface scattering.
void SubsurfaceScatteringPass(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters)
{
// Currently, forward-rendered objects do not output split lighting required for the SSS pass.
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission || m_Asset.globalRenderingSettings.ShouldUseForwardRenderingOnly())
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission)
return;
using (new ProfilingSample(cmd, "Subsurface Scattering", GetSampler(CustomSamplerId.SubsurfaceScattering)))

if (pass == ForwardPass.Opaque)
{
// TODO: return this from the SSS manager with variable MRT + if SSS is enabled
RenderTargetIdentifier[] m_MRTCache4 = new RenderTargetIdentifier[4];
m_MRTCache4[0] = m_CameraColorBufferRT;
m_MRTCache4[1] = m_CameraSssDiffuseLightingBufferRT;
m_MRTCache4[2] = m_GbufferManager.GetGBuffers()[0];
RenderTargetIdentifier[] m_MRTCache3 = new RenderTargetIdentifier[3];
m_MRTCache3[0] = m_CameraColorBufferRT;
m_MRTCache3[1] = m_CameraSssDiffuseLightingBufferRT;
m_MRTCache3[2] = m_GbufferManager.GetGBuffers()[0];
CoreUtils.SetRenderTarget(cmd, m_MRTCache4, m_CameraDepthStencilBufferRT);
CoreUtils.SetRenderTarget(cmd, m_MRTCache3, m_CameraDepthStencilBufferRT);
if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled())
{

cmd.GetTemporaryRT(m_DepthPyramidBuffer, m_DepthPyramidBufferDesc, FilterMode.Trilinear);
// End
if (!m_Asset.globalRenderingSettings.ShouldUseForwardRenderingOnly())
// TODO: commented just to test forward SSS until we implement correct manager.
// In forward we need to allocate a target for SSSBuffer0
//if (!m_Asset.globalRenderingSettings.ShouldUseForwardRenderingOnly())
m_GbufferManager.InitGBuffers(w, h, m_DeferredMaterial, enableBakeShadowMask, cmd);
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Depth);

7
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


static ComputeBuffer s_GlobalLightListAtomic = null;
// clustered light list specific buffers and data end
bool m_isForwardRenderingOnly;
bool m_isFptlEnabled;
bool m_isFptlEnabledForForwardOpaque;

public bool GetFeatureVariantsEnabled()
{
return m_isFptlEnabled && m_TileSettings.enableComputeLightEvaluation && (m_TileSettings.enableComputeLightVariants || m_TileSettings.enableComputeMaterialVariants);
return !m_isForwardRenderingOnly && m_isFptlEnabled && m_TileSettings.enableComputeLightEvaluation &&
(m_TileSettings.enableComputeLightVariants || m_TileSettings.enableComputeMaterialVariants);
}
LightLoopSettings m_TileSettings = null;

// In HD, MSAA is only supported for forward only rendering, no MSAA in deferred mode (for code complexity reasons)
// If Deferred, enable Fptl. If we are forward renderer only and not using Fptl for forward opaque, disable Fptl
m_isFptlEnabled = !renderingSettings.ShouldUseForwardRenderingOnly() || tileSettings.enableFptlForForwardOpaque; // TODO: Disable if MSAA
m_isForwardRenderingOnly = renderingSettings.ShouldUseForwardRenderingOnly();
m_isFptlEnabled = !m_isForwardRenderingOnly || tileSettings.enableFptlForForwardOpaque; // TODO: Disable if MSAA
m_isFptlEnabledForForwardOpaque = tileSettings.enableFptlForForwardOpaque; // TODO: Disable if MSAA
m_Resources = renderPipelineResources;

14
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


Name "Forward" // Name is not used
Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
Cull[_CullMode]

{
Name "ForwardDebugDisplay" // Name is not used
Tags{ "LightMode" = "ForwardDebugDisplay" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]

14
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


Name "Forward" // Name is not used
Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]
Cull[_CullMode]

{
Name "ForwardDebugDisplay" // Name is not used
Tags{ "LightMode" = "ForwardDebugDisplay" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


Name "Forward" // Name is not used
Tags { "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]

{
Name "ForwardDebugDisplay" // Name is not used
Tags{ "LightMode" = "ForwardDebugDisplay" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]

14
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


Name "Forward" // Name is not used
Tags { "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull [_CullMode]

{
Name "ForwardDebugDisplay" // Name is not used
Tags{ "LightMode" = "ForwardDebugDisplay" } // This will be only for transparent object based on the RenderQueue index
Stencil
{
Ref[_StencilRef]
Comp Always
Pass Replace
}
Blend[_SrcBlend][_DstBlend]
ZWrite[_ZWrite]

70
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl


#include "SubsurfaceScatteringSettings.cs.hlsl"
#include "ShaderLibrary\Packing.hlsl"
#include "CommonSubsurfaceScattering.hlsl"
CBUFFER_START(UnitySSSParameters)
// Warning: Unity is not able to losslessly transfer integers larger than 2^24 to the shader system.

#define SSS_WRAP_LIGHT cos(PI/2 - SSS_WRAP_ANGLE)
// ----------------------------------------------------------------------------
// SSS/Transmittance helper
// helper functions
// Computes the fraction of light passing through the object.
// Evaluate Int{0, inf}{2 * Pi * r * R(sqrt(r^2 + d^2))}, where R is the diffusion profile.
// Note: 'volumeAlbedo' should be premultiplied by 0.25.
// Ref: Approximate Reflectance Profiles for Efficient Subsurface Scattering by Pixar (BSSRDF only).
float3 ComputeTransmittanceDisney(float3 S, float3 volumeAlbedo, float thickness, float radiusScale)
{
// Thickness and SSS radius are decoupled for artists.
// In theory, we should modify the thickness by the inverse of the radius scale of the profile.
// thickness /= radiusScale;
#if 0
float3 expOneThird = exp(((-1.0 / 3.0) * thickness) * S);
#else
// Help the compiler.
float k = (-1.0 / 3.0) * LOG2_E;
float3 p = (k * thickness) * S;
float3 expOneThird = exp2(p);
#endif
// Premultiply & optimize: T = (1/4 * A) * (e^(-t * S) + 3 * e^(-1/3 * t * S))
return volumeAlbedo * (expOneThird * expOneThird * expOneThird + 3 * expOneThird);
}
// Evaluates transmittance for a linear combination of two normalized 2D Gaussians.
// Ref: Real-Time Realistic Skin Translucency (2010), equation 9 (modified).
// Note: 'volumeAlbedo' should be premultiplied by 0.25, correspondingly 'lerpWeight' by 4,
// and 'halfRcpVariance1' should be prescaled by (0.1 * SssConstants.SSS_BASIC_DISTANCE_SCALE)^2.
float3 ComputeTransmittanceJimenez(float3 halfRcpVariance1, float lerpWeight1,
float3 halfRcpVariance2, float lerpWeight2,
float3 volumeAlbedo, float thickness, float radiusScale)
{
// Thickness and SSS radius are decoupled for artists.
// In theory, we should modify the thickness by the inverse of the radius scale of the profile.
// thickness /= radiusScale;
float t2 = thickness * thickness;
// T = A * lerp(exp(-t2 * halfRcpVariance1), exp(-t2 * halfRcpVariance2), lerpWeight2)
return volumeAlbedo * (exp(-t2 * halfRcpVariance1) * lerpWeight1 + exp(-t2 * halfRcpVariance2) * lerpWeight2);
}
// Ref: Steve McAuley - Energy-Conserving Wrapped Diffuse
float ComputeWrappedDiffuseLighting(float NdotL, float w)
{
return saturate((NdotL + w) / ((1 + w) * (1 + w)));
}
// In order to support subsurface scattering, we need to know which pixels have an SSS material.
// It can be accomplished by reading the stencil buffer.
// A faster solution (which avoids an extra texture fetch) is to simply make sure that
// all pixels which belong to an SSS material are not black (those that don't always are).
// We choose the blue color channel since it's perceptually the least noticeable.
float3 TagLightingForSSS(float3 subsurfaceLighting)
{
subsurfaceLighting.b = max(subsurfaceLighting.b, HALF_MIN);
return subsurfaceLighting;
}
// See TagLightingForSSS() for details.
bool TestLightingForSSS(float3 subsurfaceLighting)
{
return subsurfaceLighting.b > 0;
}
// Returns the modified albedo (diffuse color) for materials with subsurface scattering.
// Ref: Advanced Techniques for Realistic Real-Time Skin Rendering.
float3 ApplyDiffuseTexturingMode(float3 color, int subsurfaceProfile)

UnpackFloatInt8bit(inBuffer.a, 16.0, sssData.subsurfaceRadius, sssData.subsurfaceProfile);
}
#define OUTPUT_SSSBUFFER(NAME) out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0
// OUTPUT_SSSBUFFER start from SV_Target2 as SV_Target0 and SV_Target1 are used for lighting buffer
#define OUTPUT_SSSBUFFER(NAME) out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target2
#define ENCODE_INTO_SSSBUFFER(SURFACE_DATA, UNPOSITIONSS, NAME) EncodeIntoSSSBuffer(ConvertSurfaceDataToSSSData(SURFACE_DATA), UNPOSITIONSS, MERGE_NAME(NAME, 0))
#define DECODE_FROM_SSSBUFFER(UNPOSITIONSS, SSS_DATA) DecodeFromSSSBuffer(UNPOSITIONSS, SSS_DATA)

2
ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawSssProfile.shader


#define USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "../../ShaderVariables.hlsl"
#ifdef SSS_MODEL_BASIC
#include "../../Material/Lit/SubsurfaceScatteringSettings.cs.hlsl"
#include "../../Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.hlsl"
#endif
//-------------------------------------------------------------------------------------

1
ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader


#include "ShaderLibrary/CommonMaterial.hlsl"
#define USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "../../ShaderVariables.hlsl"
#include "../../Material/SubsurfaceScattering/CommonSubsurfaceScattering.hlsl"
//-------------------------------------------------------------------------------------
// Inputs & outputs

61
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/CommonSubsurfaceScattering.hlsl


// ----------------------------------------------------------------------------
// SSS/Transmittance helper
// ----------------------------------------------------------------------------
// Computes the fraction of light passing through the object.
// Evaluate Int{0, inf}{2 * Pi * r * R(sqrt(r^2 + d^2))}, where R is the diffusion profile.
// Note: 'volumeAlbedo' should be premultiplied by 0.25.
// Ref: Approximate Reflectance Profiles for Efficient Subsurface Scattering by Pixar (BSSRDF only).
float3 ComputeTransmittanceDisney(float3 S, float3 volumeAlbedo, float thickness, float radiusScale)
{
// Thickness and SSS radius are decoupled for artists.
// In theory, we should modify the thickness by the inverse of the radius scale of the profile.
// thickness /= radiusScale;
#if 0
float3 expOneThird = exp(((-1.0 / 3.0) * thickness) * S);
#else
// Help the compiler.
float k = (-1.0 / 3.0) * LOG2_E;
float3 p = (k * thickness) * S;
float3 expOneThird = exp2(p);
#endif
// Premultiply & optimize: T = (1/4 * A) * (e^(-t * S) + 3 * e^(-1/3 * t * S))
return volumeAlbedo * (expOneThird * expOneThird * expOneThird + 3 * expOneThird);
}
// Evaluates transmittance for a linear combination of two normalized 2D Gaussians.
// Ref: Real-Time Realistic Skin Translucency (2010), equation 9 (modified).
// Note: 'volumeAlbedo' should be premultiplied by 0.25, correspondingly 'lerpWeight' by 4,
// and 'halfRcpVariance1' should be prescaled by (0.1 * SssConstants.SSS_BASIC_DISTANCE_SCALE)^2.
float3 ComputeTransmittanceJimenez(float3 halfRcpVariance1, float lerpWeight1,
float3 halfRcpVariance2, float lerpWeight2,
float3 volumeAlbedo, float thickness, float radiusScale)
{
// Thickness and SSS radius are decoupled for artists.
// In theory, we should modify the thickness by the inverse of the radius scale of the profile.
// thickness /= radiusScale;
float t2 = thickness * thickness;
// T = A * lerp(exp(-t2 * halfRcpVariance1), exp(-t2 * halfRcpVariance2), lerpWeight2)
return volumeAlbedo * (exp(-t2 * halfRcpVariance1) * lerpWeight1 + exp(-t2 * halfRcpVariance2) * lerpWeight2);
}
// In order to support subsurface scattering, we need to know which pixels have an SSS material.
// It can be accomplished by reading the stencil buffer.
// A faster solution (which avoids an extra texture fetch) is to simply make sure that
// all pixels which belong to an SSS material are not black (those that don't always are).
// We choose the blue color channel since it's perceptually the least noticeable.
float3 TagLightingForSSS(float3 subsurfaceLighting)
{
subsurfaceLighting.b = max(subsurfaceLighting.b, HALF_MIN);
return subsurfaceLighting;
}
// See TagLightingForSSS() for details.
bool TestLightingForSSS(float3 subsurfaceLighting)
{
return subsurfaceLighting.b > 0;
}

9
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/CommonSubsurfaceScattering.hlsl.meta


fileFormatVersion: 2
guid: 36fe3aa095067a7488fddbb64cde2e3c
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存