浏览代码

Draft 2

/main
Sebastien Lagarde 7 年前
当前提交
2d0640a5
共有 37 个文件被更改,包括 437 次插入265 次删除
  1. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/API/D3D11.hlsl
  2. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/API/Metal.hlsl
  3. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/API/PSSL.hlsl
  4. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/API/Vulkan.hlsl
  5. 68
      ScriptableRenderPipeline/Core/ShaderLibrary/CommonMaterial.hlsl
  6. 35
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  7. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  8. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader
  9. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  10. 86
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  11. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  12. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  13. 16
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute
  14. 17
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.shader
  15. 29
      ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl
  16. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering.meta
  17. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor.meta
  18. 20
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs
  19. 11
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs.meta
  20. 225
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl
  21. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl.meta
  22. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.hlsl.meta
  23. 11
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.meta
  24. 11
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs.meta
  25. 11
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.cs.meta
  26. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs.meta
  27. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs.meta
  28. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.meta
  29. 10
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.hlsl.meta
  30. 42
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringUtilities.hlsl
  31. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.cs
  32. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs
  33. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SSSProfile.meta
  34. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SSSProfile
  35. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs
  36. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.hlsl

2
ScriptableRenderPipeline/Core/ShaderLibrary/API/D3D11.hlsl


#define SAMPLERCUBE_SHADOW(samplerName) SamplerComparisonState samplerName
#define TEXTURE2D_ARGS(textureName, samplerName) Texture2D textureName, SamplerState samplerName
#define TEXTURE2D_ARGS_NOSAMPLER(textureName) Texture2D textureName
#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) Texture2DArray textureName, SamplerState samplerName
#define TEXTURECUBE_ARGS(textureName, samplerName) TextureCube textureName, SamplerState samplerName
#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) TextureCubeArray textureName, SamplerState samplerName

#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) TextureCube textureName, SamplerComparisonState samplerName
#define TEXTURE2D_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_PARAM_NOSAMPLER(textureName) textureName
#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) textureName, samplerName

2
ScriptableRenderPipeline/Core/ShaderLibrary/API/Metal.hlsl


#define SAMPLERCUBE_SHADOW(samplerName) SamplerComparisonState samplerName
#define TEXTURE2D_ARGS(textureName, samplerName) Texture2D textureName, SamplerState samplerName
#define TEXTURE2D_ARGS_NOSAMPLER(textureName) Texture2D textureName
#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) Texture2DArray textureName, SamplerState samplerName
#define TEXTURECUBE_ARGS(textureName, samplerName) TextureCube textureName, SamplerState samplerName
#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) TextureCubeArray textureName, SamplerState samplerName

#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) TextureCube textureName, SamplerComparisonState samplerName
#define TEXTURE2D_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_PARAM_NOSAMPLER(textureName) textureName
#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) textureName, samplerName

2
ScriptableRenderPipeline/Core/ShaderLibrary/API/PSSL.hlsl


#define SAMPLERCUBE_SHADOW(samplerName) SamplerComparisonState samplerName
#define TEXTURE2D_ARGS(textureName, samplerName) Texture2D textureName, SamplerState samplerName
#define TEXTURE2D_ARGS_NOSAMPLER(textureName) Texture2D textureName
#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) Texture2DArray textureName, SamplerState samplerName
#define TEXTURECUBE_ARGS(textureName, samplerName) TextureCube textureName, SamplerState samplerName
#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) TextureCubeArray textureName, SamplerState samplerName

#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) TextureCube textureName, SamplerComparisonState samplerName
#define TEXTURE2D_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_PARAM_NOSAMPLER(textureName) textureName
#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) textureName, samplerName

2
ScriptableRenderPipeline/Core/ShaderLibrary/API/Vulkan.hlsl


#define SAMPLERCUBE_SHADOW(samplerName) SamplerComparisonState samplerName
#define TEXTURE2D_ARGS(textureName, samplerName) Texture2D textureName, SamplerState samplerName
#define TEXTURE2D_ARGS_NOSAMPLER(textureName) Texture2D textureName
#define TEXTURE2D_ARRAY_ARGS(textureName, samplerName) Texture2DArray textureName, SamplerState samplerName
#define TEXTURECUBE_ARGS(textureName, samplerName) TextureCube textureName, SamplerState samplerName
#define TEXTURECUBE_ARRAY_ARGS(textureName, samplerName) TextureCubeArray textureName, SamplerState samplerName

#define TEXTURECUBE_SHADOW_ARGS(textureName, samplerName) TextureCube textureName, SamplerComparisonState samplerName
#define TEXTURE2D_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURE2D_PARAM_NOSAMPLER(textureName) textureName
#define TEXTURE2D_ARRAY_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_PARAM(textureName, samplerName) textureName, samplerName
#define TEXTURECUBE_ARRAY_PARAM(textureName, samplerName) textureName, samplerName

68
ScriptableRenderPipeline/Core/ShaderLibrary/CommonMaterial.hlsl


return float3(oneMinusT, oneMinusT, oneMinusT) + b * t;
}
// ----------------------------------------------------------------------------
// SSS/Transmittance
// ----------------------------------------------------------------------------
// 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;
}
#endif // UNITY_COMMON_MATERIAL_INCLUDED

35
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Color | ClearFlag.Depth);
RenderOpaqueRenderList(m_CullResults, camera, renderContext, cmd, HDShaderPassNames.s_ForwardName);
RenderTransparentRenderList(m_CullResults, camera, renderContext, cmd, HDShaderPassNames.s_ForwardName, false);
RenderTransparentRenderList(m_CullResults, camera, renderContext, cmd, HDShaderPassNames.s_ForwardName, false);
}
renderContext.ExecuteCommandBuffer(cmd);

RenderDeferredLighting(hdCamera, cmd);
// 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 split lighting required for the SSS pass.
SubsurfaceScatteringPass(hdCamera, cmd, sssSettings);
// SSS pass here handle both SSS material from deferred and forward
SubsurfaceScatteringPass(hdCamera, cmd, sssSettings);
RenderSky(hdCamera, cmd);

cmd.SetComputeVectorArrayParam(m_SubsurfaceScatteringCS, HDShaderIDs._FilterKernels, sssParameters.filterKernels);
cmd.SetComputeVectorArrayParam(m_SubsurfaceScatteringCS, HDShaderIDs._ShapeParams, sssParameters.shapeParams);
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._GBufferTexture0, m_GbufferManager.GetGBuffers()[0]);
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._GBufferTexture1, m_GbufferManager.GetGBuffers()[1]);
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._GBufferTexture2, m_GbufferManager.GetGBuffers()[2]);
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._GBufferTexture3, m_GbufferManager.GetGBuffers()[3]);
// TODO: abstract this in SSS manager
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._SSSBufferTexture0, m_GbufferManager.GetGBuffers()[2]);
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._SSSBufferTexture1, m_GbufferManager.GetGBuffers()[0]);
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._DepthTexture, GetDepthTexture());
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._HTile, GetHTile());
cmd.SetComputeTextureParam(m_SubsurfaceScatteringCS, m_SubsurfaceScatteringKernel, HDShaderIDs._IrradianceSource, m_CameraSssDiffuseLightingBufferRT);

}
else
{
// TODO: abstract this in SSS manager
cmd.SetGlobalTexture(HDShaderIDs._SSSBufferTexture0, m_GbufferManager.GetGBuffers()[2]);
cmd.SetGlobalTexture(HDShaderIDs._SSSBufferTexture1, m_GbufferManager.GetGBuffers()[0]);
cmd.SetGlobalTexture(HDShaderIDs._IrradianceSource, m_CameraSssDiffuseLightingBufferRT); // Cannot set a RT on a material
m_SssVerticalFilterPass.SetVectorArray(HDShaderIDs._WorldScales, sssParameters.worldScales);
m_SssVerticalFilterPass.SetVectorArray(HDShaderIDs._FilterKernelsBasic, sssParameters.filterKernelsBasic);

using (new ProfilingSample(cmd, profileName, GetSampler(CustomSamplerId.ForwardPassName)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);
// 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()[2];
m_MRTCache4[3] = m_GbufferManager.GetGBuffers()[0];
CoreUtils.SetRenderTarget(cmd, m_MRTCache4, m_CameraDepthStencilBufferRT);
if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled())
{
m_ForwardAndForwardOnlyPassNames[0] = m_ForwardOnlyPassNames[0] = HDShaderPassNames.s_ForwardOnlyDebugDisplayName;

}
else
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);
var passNames = m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ? m_AllTransparentDebugDisplayPassNames : m_AllTransparentPassNames;
RenderTransparentRenderList(cullResults, camera, renderContext, cmd, passNames, pass == ForwardPass.PreRefraction, m_currentRendererConfigurationBakedLighting);
}

9
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int _GBufferTexture1 = Shader.PropertyToID("_GBufferTexture1");
public static readonly int _GBufferTexture2 = Shader.PropertyToID("_GBufferTexture2");
public static readonly int _GBufferTexture3 = Shader.PropertyToID("_GBufferTexture3");
public static readonly int _GBufferTexture4 = Shader.PropertyToID("_GBufferTexture4");
public static readonly int _GBufferTexture5 = Shader.PropertyToID("_GBufferTexture5");
public static readonly int _GBufferTexture6 = Shader.PropertyToID("_GBufferTexture6");
public static readonly int _GBufferTexture7 = Shader.PropertyToID("_GBufferTexture7");
public static readonly int _SSSBufferTexture0 = Shader.PropertyToID("_SSSBufferTexture0");
public static readonly int _SSSBufferTexture1 = Shader.PropertyToID("_SSSBufferTexture1");
public static readonly int _SSSBufferTexture2 = Shader.PropertyToID("_SSSBufferTexture2");
public static readonly int _SSSBufferTexture3 = Shader.PropertyToID("_SSSBufferTexture3");
public static readonly int g_DispatchIndirectBuffer = Shader.PropertyToID("g_DispatchIndirectBuffer");
public static readonly int g_TileList = Shader.PropertyToID("g_TileList");

5
ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader


// This shader support vertex modification
#define HAVE_VERTEX_MODIFICATION
// If we use subsurface scattering, enable output split lighting (for forward pass)
#if defined(_MATID_SSS) && !defined(_SURFACE_TYPE_TRANSPARENT)
#define OUTPUT_SPLIT_LIGHTING
#endif
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------

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


#define HAVE_VERTEX_MODIFICATION
#define HAVE_TESSELLATION_MODIFICATION
// If we use subsurface scattering, enable output split lighting (for forward pass)
#if defined(_MATID_SSS) && !defined(_SURFACE_TYPE_TRANSPARENT)
#define OUTPUT_SPLIT_LIGHTING
#endif
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------

86
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


// SurfaceData is define in Lit.cs which generate Lit.cs.hlsl
#include "Lit.cs.hlsl"
#include "SubsurfaceScatteringSettings.cs.hlsl"
#include "../SubsurfaceScattering/SubsurfaceScatteringUtilities.hlsl"
#include "../SubsurfaceScattering/SubsurfaceScattering.hlsl"
// Define refraction keyword helpers
#define HAS_REFRACTION (defined(_REFRACTION_PLANE) || defined(_REFRACTION_SPHERE))

#define GBufferType1 float4
#define GBufferType2 float4
#define GBufferType3 float4
#define SSSBufferType0 GBufferType2
#define SSSBufferType1 GBufferType0
// GBuffer texture declaration
TEXTURE2D(_GBufferTexture0);

#define LTC_LUT_SIZE 64
#define LTC_LUT_SCALE ((LTC_LUT_SIZE - 1) * rcp(LTC_LUT_SIZE))
#define LTC_LUT_OFFSET (0.5 * rcp(LTC_LUT_SIZE))
// Subsurface scattering constant
#define SSS_WRAP_ANGLE (PI/12) // 15 degrees
#define SSS_WRAP_LIGHT cos(PI/2 - SSS_WRAP_ANGLE)
CBUFFER_START(UnitySSSParameters)
// Warning: Unity is not able to losslessly transfer integers larger than 2^24 to the shader system.
// Therefore, we bitcast uint to float in C#, and bitcast back to uint in the shader.
uint _EnableSSSAndTransmission; // Globally toggles subsurface and transmission scattering on/off
float _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
float _TransmissionFlags; // 2 bit/profile; 0 = inf. thick, 1 = thin, 2 = regular
// Old SSS Model >>>
uint _UseDisneySSS;
float4 _HalfRcpVariancesAndWeights[SSS_N_PROFILES][2]; // 2x Gaussians in RGB, A is interpolation weights
// <<< Old SSS Model
// Use float4 to avoid any packing issue between compute and pixel shaders
float4 _ThicknessRemaps[SSS_N_PROFILES]; // R: start, G = end - start, BA unused
float4 _ShapeParams[SSS_N_PROFILES]; // RGB = S = 1 / D, A = filter radius
float4 _TransmissionTints[SSS_N_PROFILES]; // RGB = 1/4 * color, A = unused
CBUFFER_END
//-----------------------------------------------------------------------------
// Helper for cheap screen space raycasting

}
}
// Returns the modified albedo (diffuse color) for materials with subsurface scattering.
// Ref: Advanced Techniques for Realistic Real-Time Skin Rendering.
float3 ApplyDiffuseTexturingMode(BSDFData bsdfData)
{
float3 albedo = bsdfData.diffuseColor;
if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
#if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_SUBSURFACE_SCATTERING)
// If the SSS pass is executed, we know we have SSS enabled.
bool enableSssAndTransmission = true;
#else
bool enableSssAndTransmission = _EnableSSSAndTransmission != 0;
#endif
if (enableSssAndTransmission)
{
bool performPostScatterTexturing = IsBitSet(asuint(_TexturingModeFlags), bsdfData.subsurfaceProfile);
if (performPostScatterTexturing)
{
// Post-scatter texturing mode: the albedo is only applied during the SSS pass.
#if !defined(SHADERPASS) || (SHADERPASS != SHADERPASS_SUBSURFACE_SCATTERING)
albedo = float3(1, 1, 1);
#endif
}
else
{
// Pre- and pos- scatter texturing mode.
albedo = sqrt(albedo);
}
}
}
return albedo;
}
void FillMaterialIdClearCoatData(float3 coatNormalWS, float coatCoverage, float coatIOR, inout BSDFData bsdfData)
{
bsdfData.coatNormalWS = lerp(bsdfData.normalWS, coatNormalWS, coatCoverage);

#endif
}
SSSData ConvertSurfaceDataToSSSData(Surface surfaceData)
{
SSSData sssData;
sssData.diffuseColor = surfaceData.baseColor;
sssData.subsurfaceRadius = surfaceData.subsurfaceRadius;
sssData.subsurfaceProfile = surfaceData.subsurfaceProfile;
}
//-----------------------------------------------------------------------------
// conversion function for forward
//-----------------------------------------------------------------------------

}
else if (surfaceData.materialId == MATERIALID_LIT_SSS)
{
outGBuffer2 = EncodeSSSDataToBuffer(surfaceData.baseColor, surfaceData.subsurfaceRadius, surfaceData.subsurfaceProfile, surfaceData.thickness, positionSS);
#ifdef USE_COMPACT_SSS_BUFFER
EncodeIntoSSSBuffer(ConvertSurfaceDataToSSSData(surfaceData), positionSS, outGBuffer2);
#else
// in this configuration, outGbuffer0 match the second Gbuffer encoding
float4 unused;
EncodeIntoSSSBuffer(ConvertSurfaceDataToSSSData(surfaceData), positionSS, outGBuffer2, unused);
#endif
outGBuffer2.a = surfaceData.thickness;
}
else if (surfaceData.materialId == MATERIALID_LIT_ANISO)
{

float subsurfaceRadius;
float thickness;
int subsurfaceProfile;
DecodeSSSProfileFromSSSBuffer(inGBuffer2, positionSS, subsurfaceProfile);
thickness = inGBuffer2.a;
DecodeSSSDataFromBuffer(TEXTURE2D_PARAM_NOSAMPLER(_GBufferTexture2), positionSS, inGBuffer2, unusedColor, surfaceData.subsurfaceRadius, surfaceData.subsurfaceProfile, surfaceData.thickness);
FillMaterialIdSSSData(baseColor, subsurfaceProfile, subsurfaceRadius, thickness, bsdfData);
}

// This function require the 3 structure surfaceData, builtinData, bsdfData because it may require both the engine side data, and data that will not be store inside the gbuffer.
float3 GetBakedDiffuseLigthing(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData, PreLightData preLightData)
{
bsdfData.diffuseColor = ApplyDiffuseTexturingMode(bsdfData);
bsdfData.diffuseColor = ApplyDiffuseTexturingMode(bsdfData.diffuseColor, bsdfData.materialId == MATERIALID_LIT_SSS, bsdfData.subsurfaceProfile);
// Premultiply bake diffuse lighting information with DisneyDiffuse pre-integration
return builtinData.bakeDiffuseLighting * preLightData.diffuseFGD * surfaceData.ambientOcclusion * bsdfData.diffuseColor + builtinData.emissiveColor;

lerp(_AmbientOcclusionParam.rgb, float3(1.0, 1.0, 1.0), directAmbientOcclusion);
#endif
float3 modifiedDiffuseColor = ApplyDiffuseTexturingMode(bsdfData);
float3 modifiedDiffuseColor = ApplyDiffuseTexturingMode(bsdfData.diffuseColor, bsdfData.materialId == MATERIALID_LIT_SSS, bsdfData.subsurfaceProfile);
// Apply the albedo to the direct diffuse lighting (only once). The indirect (baked)
// diffuse lighting has already had the albedo applied in GetBakedDiffuseLigthing().

5
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


// This shader support vertex modification
#define HAVE_VERTEX_MODIFICATION
// If we use subsurface scattering, enable output split lighting (for forward pass)
#if defined(_MATID_SSS) && !defined(_SURFACE_TYPE_TRANSPARENT)
#define OUTPUT_SPLIT_LIGHTING
#endif
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------

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


#define HAVE_VERTEX_MODIFICATION
#define HAVE_TESSELLATION_MODIFICATION
// If we use subsurface scattering, enable output split lighting (for forward pass)
#if defined(_MATID_SSS) && !defined(_SURFACE_TYPE_TRANSPARENT)
#define OUTPUT_SPLIT_LIGHTING
#endif
//-------------------------------------------------------------------------------------
// Include
//-------------------------------------------------------------------------------------

16
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute


#include "ShaderLibrary/Packing.hlsl"
#include "ShaderLibrary/SpaceFillingCurves.hlsl"
#include "../../../ShaderVariables.hlsl"
#define UNITY_MATERIAL_LIT
#include "../../../Material/Material.hlsl"
#include "../../SubsurfaceScattering/SubsurfaceScattering.hlsl"
//--------------------------------------------------------------------------------------------------
// Inputs & outputs

[branch] if (!passedStencilTest || isOffScreen) { return; }
PositionInputs posInput = GetPositionInput(pixelCoord, _ScreenSize.zw);
PositionInputs posInput = GetPositionInput(pixelCoord, _ScreenSize.zw);
BSDFData bsdfData;
float3 unused;
DECODE_FROM_GBUFFER(pixelCoord, MATERIALFEATUREFLAGS_LIT_SSS, bsdfData, unused);
SSSData sssData;
DECODE_FROM_SSSBUFFER(pixelCoord, sssData);
int profileID = bsdfData.subsurfaceProfile;
float distScale = bsdfData.subsurfaceRadius;
int profileID = sssData.subsurfaceProfile;
float distScale = sssData.subsurfaceRadius;
float3 shapeParam = _ShapeParams[profileID].rgb;
float maxDistance = _ShapeParams[profileID].a;

// divergence of execution across the warp.
float maxDistInPixels = maxDistance * max(pixelsPerMm.x, pixelsPerMm.y);
float3 albedo = ApplyDiffuseTexturingMode(bsdfData);
float3 albedo = ApplyDiffuseTexturingMode(sssData.diffuseColor, true, profileID);
[branch] if (distScale == 0 || maxDistInPixels < 1)
{

17
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.shader


#include "ShaderLibrary/Common.hlsl"
#include "../../../ShaderVariables.hlsl"
#define UNITY_MATERIAL_LIT // Needs to be defined before including Material.hlsl
#include "../../../Material/Material.hlsl"
#include "../../SubsurfaceScattering/SubsurfaceScattering.hlsl"
//-------------------------------------------------------------------------------------
// Inputs & outputs

float4 Frag(Varyings input) : SV_Target
{
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
// Note: When we are in this SubsurfaceScattering shader we know that we are a SSS material. This shader is strongly coupled with the deferred Lit.shader.
// We can use the material classification facility to help the compiler to know we use SSS material and optimize the code (and don't require to read gbuffer with materialId).
uint featureFlags = MATERIALFEATUREFLAGS_LIT_SSS;
BSDFData bsdfData;
float3 unused;
DECODE_FROM_GBUFFER(posInput.positionSS, featureFlags, bsdfData, unused);
// Note: When we are in this SubsurfaceScattering shader we know that we are a SSS material.
SSSData sssData;
DECODE_FROM_SSSBUFFER(pixelCoord, sssData);
int profileID = bsdfData.subsurfaceProfile;
float distScale = bsdfData.subsurfaceRadius;

float halfRcpVariance = _HalfRcpWeightedVariances[profileID].a;
#endif
float3 albedo = ApplyDiffuseTexturingMode(bsdfData);
float3 albedo = ApplyDiffuseTexturingMode(sssData.diffuseColor, true, profileID);
#ifndef SSS_FILTER_HORIZONTAL_AND_COMBINE
albedo = float3(1, 1, 1);

29
ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPassForward.hlsl


#endif // TESSELLATION_ON
void Frag(PackedVaryingsToPS packedInput,
out float4 outColor : SV_Target0
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif
#ifdef OUTPUT_SPLIT_LIGHTING
out float4 outColor : SV_Target0, // outSpecularLighting
out float4 outDiffuseLighting : SV_Target1,
OUTPUT_SSSBUFFER(outSSSBuffer)
#else
out float4 outColor : SV_Target0
#endif
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif
)
{
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);

bakeLightingData.bakeShadowMask = float4(builtinData.shadowMask0, builtinData.shadowMask1, builtinData.shadowMask2, builtinData.shadowMask3);
#endif
LightLoop(V, posInput, preLightData, bsdfData, bakeLightingData, featureFlags, diffuseLighting, specularLighting);
#ifdef OUTPUT_SPLIT_LIGHTING
if (_EnableSSSAndTransmission != 0)
{
outColor = float4(specularLighting, 1.0);
outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0);
}
else
{
outColor = float4(diffuseLighting + specularLighting, 1.0);
outDiffuseLighting = 0;
}
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
#else
#endif
}
#ifdef _DEPTHOFFSET_ON

8
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering.meta


fileFormatVersion: 2
guid: 25455a79ee8c96d4fb3ca2e64d8092e1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor.meta


fileFormatVersion: 2
guid: fb3f658c087068440b2c5063fc3abaed
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

20
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs


using UnityEngine.Rendering;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SubsurfaceScatteringManager
{
public const int k_MaxGbuffer = 2;
public int sssbufferCount { get; set; }
RenderTargetIdentifier[] m_ColorMRTs;
RenderTargetIdentifier[] m_RTIDs = new RenderTargetIdentifier[k_MaxGbuffer];
// public RenderTargetIdentifier SSSBuffer[2];
// public SetSSSBuffer();
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.cs.meta


fileFormatVersion: 2
guid: 26e79cea58f13e241ba3ecee1a281ebc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

225
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl


#include "SubsurfaceScatteringSettings.cs.hlsl"
CBUFFER_START(UnitySSSParameters)
// Warning: Unity is not able to losslessly transfer integers larger than 2^24 to the shader system.
// Therefore, we bitcast uint to float in C#, and bitcast back to uint in the shader.
uint _EnableSSSAndTransmission; // Globally toggles subsurface and transmission scattering on/off
float _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
float _TransmissionFlags; // 2 bit/profile; 0 = inf. thick, 1 = thin, 2 = regular
// Old SSS Model >>>
uint _UseDisneySSS;
float4 _HalfRcpVariancesAndWeights[SSS_N_PROFILES][2]; // 2x Gaussians in RGB, A is interpolation weights
// <<< Old SSS Model
// Use float4 to avoid any packing issue between compute and pixel shaders
float4 _ThicknessRemaps[SSS_N_PROFILES]; // R: start, G = end - start, BA unused
float4 _ShapeParams[SSS_N_PROFILES]; // RGB = S = 1 / D, A = filter radius
float4 _TransmissionTints[SSS_N_PROFILES]; // RGB = 1/4 * color, A = unused
CBUFFER_END
// Subsurface scattering constant
#define SSS_WRAP_ANGLE (PI/12) // 15 degrees
#define SSS_WRAP_LIGHT cos(PI/2 - SSS_WRAP_ANGLE)
// ----------------------------------------------------------------------------
// 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);
}
// 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, bool isSSSMaterial, int subsurfaceProfile)
{
float3 albedo = color;
if (isSSSMaterial)
{
#if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_SUBSURFACE_SCATTERING)
// If the SSS pass is executed, we know we have SSS enabled.
bool enableSssAndTransmission = true;
#else
bool enableSssAndTransmission = _EnableSSSAndTransmission != 0;
#endif
if (enableSssAndTransmission)
{
bool performPostScatterTexturing = IsBitSet(asuint(_TexturingModeFlags), subsurfaceProfile);
if (performPostScatterTexturing)
{
// Post-scatter texturing mode: the albedo is only applied during the SSS pass.
#if !defined(SHADERPASS) || (SHADERPASS != SHADERPASS_SUBSURFACE_SCATTERING)
albedo = float3(1, 1, 1);
#endif
}
else
{
// Pre- and post- scatter texturing mode.
albedo = sqrt(albedo);
}
}
}
return albedo;
}
// ----------------------------------------------------------------------------
// Encoding/decoding SSS buffer functions
// ----------------------------------------------------------------------------
struct SSSData
{
float3 diffuseColor;
float subsurfaceRadius;
float subsurfaceProfile;
};
//#define USE_COMPACT_SSS_BUFFER
#ifdef USE_COMPACT_SSS_BUFFER
// SSSBuffer texture declaration
TEXTURE2D(_SSSBufferTexture0);
void EncodeIntoSSSBuffer(SSSData sssData, uint2 positionSS, out SSSBufferType0 outSSSBuffer0)
{
// RGBToYCoCg have better precision with a sRGB color, use cheap gamma 2 instead
// Take care that the render target use linear format
float3 YCoCg = RGBToYCoCg(LinearToGamma20(sssData.diffuseColor));
// Note: when we are in forward we don't need to store the thickness as it is already apply. So a potential optimization
// when we know that we are in full forward only is to not store the thickness and store the full baseColor (so not cost at decode)
// as this function aim to be share between hybrid deferred/forward, we can't assume it.
// subsurfaceRadius is like a mask (a bit like metal parameters and don't need a lot of precision, store it on 4 bit
// currently we support up to 16 SSS profile (SSS_N_PROFILES) - caution if this number change (for a higher value), code below must change!
outSSSBuffer0 = float4((positionSS.x & 1) == (positionSS.y & 1) ? YCoCg.rb : YCoCg.rg, PackFloatInt8bit(sssData.subsurfaceRadius, sssData.subsurfaceProfile, 16.0), 0.0);
}
void DecodeSSSProfileFromSSSBuffer(SSSBufferType0 inSSSBuffer0, uint2 positionSS, out int subsurfaceProfile)
{
float unused;
UnpackFloatInt8bit(inSSSBuffer0.b, 16.0, unused, subsurfaceProfile);
}
void DecodeFromSSSBuffer(uint2 positionSS, out SSSData sssData)
{
// unpack
float4 inBuffer = LOAD_TEXTURE2D(_SSSBufferTexture0, positionSS);
float2 YChroma0 = inBuffer.rg;
UnpackFloatInt8bit(inBuffer.b, 16.0, sssData.subsurfaceRadius, sssData.subsurfaceProfile);
// Note: nothing in a, reserved for thickness in case of GBuffer rendering
// Reconstruct color
// Note: We don't care about pixel at border, will be handled by the edge filter (as it will be black)
float2 a0 = LOAD_TEXTURE2D(_SSSBufferTexture0, positionSS + uint2(1, 0)).rg;
float2 a1 = LOAD_TEXTURE2D(_SSSBufferTexture0, positionSS - uint2(1, 0)).rg;
float2 a2 = LOAD_TEXTURE2D(_SSSBufferTexture0, positionSS + uint2(0, 1)).rg;
float2 a3 = LOAD_TEXTURE2D(_SSSBufferTexture0, positionSS - uint2(0, 1)).rg;
float chroma1 = YCoCgCheckBoardEdgeFilter(YChroma0.r, a0, a1, a2, a3);
float3 YCoCg = (positionSS.x & 1) == (positionSS.y & 1) ? float3(YChroma0.r, chroma1, YChroma0.g) : float3(YChroma0.rg, chroma1);
sssData.diffuseColor = Gamma20ToLinear(YCoCgToRGB(YCoCg));
}
#define OUTPUT_SSSBUFFER(NAME) out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0
#define ENCODE_INTO_SSSBUFFER(SURFACE_DATA, UNPOSITIONSS, NAME) EncodeIntoSSSBuffer(SURFACE_DATA, UNPOSITIONSS, MERGE_NAME(NAME, 0))
#else
// SSSBuffer texture declaration
TEXTURE2D(_SSSBufferTexture0);
TEXTURE2D(_SSSBufferTexture1);
void EncodeIntoSSSBuffer(SSSData sssData, uint2 positionSS, out SSSBufferType0 outSSSBuffer0, out SSSBufferType1 outSSSBuffer1)
{
outSSSBuffer0 = float4(0.0, sssData.subsurfaceRadius, PackByte(sssData.subsurfaceProfile), 0.0);
outSSSBuffer1 = float4(sssData.diffuseColor, 0.0);
}
void DecodeSSSProfileFromSSSBuffer(SSSBufferType0 inSSSBuffer0, uint2 positionSS, out int subsurfaceProfile)
{
subsurfaceProfile = UnpackByte(inSSSBuffer0.b);
}
void DecodeFromSSSBuffer(uint2 positionSS, out SSSData sssData)
{
// unpack
float4 inBuffer = LOAD_TEXTURE2D(_SSSBufferTexture0, positionSS);
sssData.subsurfaceRadius = inBuffer.g;
sssData.subsurfaceProfile = UnpackByte(inBuffer.b);
// Note: nothing in a, reserved for thickness in case of GBuffer rendering
sssData.diffuseColor = LOAD_TEXTURE2D(_SSSBufferTexture1, positionSS).rgb;
}
#define OUTPUT_SSSBUFFER(NAME) \
out GBufferType0 MERGE_NAME(NAME, 0) : SV_Target0, \
out GBufferType1 MERGE_NAME(NAME, 1) : SV_Target1
#define ENCODE_INTO_SSSBUFFER(SURFACE_DATA, UNPOSITIONSS, NAME) EncodeIntoSSSBuffer(ConvertSurfaceDataToSSSData(SURFACE_DATA), UNPOSITIONSS, MERGE_NAME(NAME, 0), MERGE_NAME(NAME, 1))
#endif
#define DECODE_FROM_SSSBUFFER(UNPOSITIONSS, SSS_DATA) DecodeFromSSSBuffer(UNPOSITIONSS, SSS_DATA)

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


fileFormatVersion: 2
guid: a9f89d53a380e274590d02ddfabce53e
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.hlsl.meta


fileFormatVersion: 2
guid: a68623b64163f324da6b52463c8a8aa7
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

11
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.meta


fileFormatVersion: 2
guid: b2686e09ec7aef44bad2843e4416f057
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs.meta


fileFormatVersion: 2
guid: 4073853f945109f47901ba54281a18af
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.cs.meta


fileFormatVersion: 2
guid: 5fbf42188568d5247aae2304fc8c805e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs.meta


fileFormatVersion: 2
guid: 95517c3b2f4a014468289c3f5eb6d03c
timeCreated: 1507562538
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs.meta


fileFormatVersion: 2
guid: a61a2437dcee4e54393f8f65ccf726ab
timeCreated: 1507562486
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.meta


fileFormatVersion: 2
guid: 3418a08abd15e9a49af3ccbc9e15b5ea
timeCreated: 1507538042
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.hlsl.meta


fileFormatVersion: 2
guid: 86fe0068e2ac49e4d99882aaa40fa522
timeCreated: 1507935155
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

42
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringUtilities.hlsl


// To use in case the color have already been encoded in checkboard YCoCg
float4 EncodeSSSDataToBuffer(float2 Ychroma, float subsurfaceRadius, uint subsurfaceProfile, float thickness)
{
// subsurfaceRadius is like a mask (a bit like metal parameters and don't need a lot of precision, store it on 4 bit
// currently we support up to 16 SSS profile (SSS_N_PROFILES) - caution if this number change (for a higher value), code below must change!
return float4(Ychroma, thickness, PackFloatInt8bit(subsurfaceRadius, subsurfaceProfile, 16.0));
}
// This function encode all data require for ScreenSpace SubsurfaceScattering (SSSSS)
// Aim to be use with a GBuffer
float4 EncodeSSSDataToBuffer(float3 color, float subsurfaceRadius, uint subsurfaceProfile, float thickness, uint2 positionSS)
{
// RGBToYCoCg have better precision with a sRGB color, use cheap gamma 2 instead
// Take care that the render target use linear format
float3 YCoCg = RGBToYCoCg(LinearToGamma20(color));
// Note: when we are in forward we don't need to store the thickness as it is already apply. So a potential optimization
// when we know that we are in full forward only is to not store the thickness and store the full baseColor (so not cost at decode)
// as this function aim to be share between hybrid deferred/forward, we can't assume it.
// subsurfaceRadius is like a mask (a bit like metal parameters and don't need a lot of precision, store it on 4 bit
// currently we support up to 16 SSS profile (SSS_N_PROFILES) - caution if this number change (for a higher value), code below must change!
return EncodeSSSDataToBuffer((positionSS.x & 1) == (positionSS.y & 1) ? YCoCg.rb : YCoCg.rg, subsurfaceRadius, thickness, subsurfaceProfile, thickness);
}
float4 DecodeSSSDataFromBuffer(TEXTURE2D_ARGS_NOSAMPLER(SSSBuffer), uint2 positionSS, float4 inBuffer, out float3 color, out float subsurfaceRadius, out int subsurfaceProfileout, out float thickness)
{
// unpack
float2 YChroma0 = inBuffer.rg;
thickness = inBuffer.b;
UnpackFloatInt8bit(inBuffer.a, 16.0, subsurfaceRadius, subsurfaceProfile);
// Reconstruct color
// Note: We don't care about pixel at border, will be handled by the edge filter (as it will be black)
float2 a0 = LOAD_TEXTURE2D(SSSBuffer, positionSS + uint2(1, 0)).rg;
float2 a1 = LOAD_TEXTURE2D(SSSBuffer, positionSS - uint2(1, 0)).rg;
float2 a2 = LOAD_TEXTURE2D(SSSBuffer, positionSS + uint2(0, 1)).rg;
float2 a3 = LOAD_TEXTURE2D(SSSBuffer, positionSS - uint2(0, 1)).rg;
float chroma1 = YCoCgCheckBoardEdgeFilter(YChroma0.r, a0, a1, a2, a3);
float3 YCoCg = (positionSS.x & 1) == (positionSS.y & 1) ? float3(YChroma0.r, chroma1, YChroma0.g) : float3(YChroma0.rg, chroma1);
color = Gamma20ToLinear(YCoCgToRGB(YCoCg));
}

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.cs

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile.meta → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SSSProfile.meta

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SSSProfile

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.hlsl → /ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs.hlsl

正在加载...
取消
保存