Skip to content

Commit 2e0c7fb

Browse files
committed
Make the SSS texturing mode a profile-local property
1 parent bb8462b commit 2e0c7fb

7 files changed

Lines changed: 88 additions & 104 deletions

File tree

Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ private class Styles
3535
// Subsurface Scattering Settings
3636
public readonly GUIContent[] sssProfiles = new GUIContent[SubsurfaceScatteringSettings.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") };
3737
public readonly GUIContent sssNumProfiles = new GUIContent("Number of profiles");
38-
public readonly GUIContent sssTexturingMode = new GUIContent("Texturing mode", "Specifies when the diffuse texture should be applied.");
39-
public readonly GUIContent[] sssTexturingModeOptions = new GUIContent[3] { new GUIContent("Pre-scatter", "Before the blurring pass. Effectively results in the diffuse texture getting blurred together with the lighting."), new GUIContent("Post-scatter", "After the blurring pass. Effectively preserves the sharpness of the diffuse texture."), new GUIContent("Pre- and post-scatter", "Both before and after the blurring pass.") };
4038

4139
// Tile pass Settings
4240
public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop Settings");
@@ -124,7 +122,6 @@ private static Styles styles
124122
SerializedProperty m_RenderingUseDepthPrepass = null;
125123

126124
// Subsurface Scattering Settings
127-
SerializedProperty m_TexturingMode = null;
128125
SerializedProperty m_Profiles = null;
129126
SerializedProperty m_NumProfiles = null;
130127

@@ -161,9 +158,8 @@ private void InitializeProperties()
161158
m_RenderingUseDepthPrepass = FindProperty(x => x.renderingSettings.useDepthPrepass);
162159

163160
// Subsurface Scattering Settings
164-
m_TexturingMode = FindProperty(x => x.sssSettings.texturingMode);
165-
m_Profiles = FindProperty(x => x.sssSettings.profiles);
166-
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
161+
m_Profiles = FindProperty(x => x.sssSettings.profiles);
162+
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
167163
}
168164

169165
SerializedProperty FindProperty<TValue>(Expression<Func<HDRenderPipeline, TValue>> expr)
@@ -340,7 +336,6 @@ private void SssSettingsUI(HDRenderPipeline pipe)
340336
EditorGUI.BeginChangeCheck();
341337

342338
EditorGUILayout.PropertyField(m_NumProfiles, styles.sssNumProfiles);
343-
m_TexturingMode.intValue = EditorGUILayout.Popup(styles.sssTexturingMode, m_TexturingMode.intValue, styles.sssTexturingModeOptions, (GUILayoutOption[])null);
344339

345340
for (int i = 0, n = Math.Min(m_Profiles.arraySize, SubsurfaceScatteringSettings.maxNumProfiles); i < n; i++)
346341
{

Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -455,26 +455,11 @@ public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderCo
455455
}
456456

457457
// Broadcast SSS parameters to all shaders.
458-
Shader.SetGlobalInt("_TransmissionFlags", sssParameters.transmissionFlags);
458+
Shader.SetGlobalInt("_TransmissionFlags", sssParameters.transmissionFlags);
459+
Shader.SetGlobalInt("_TexturingModeFlags", sssParameters.texturingModeFlags);
459460
cmd.SetGlobalFloatArray("_ThicknessRemaps", sssParameters.thicknessRemaps);
460461
cmd.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights);
461462

462-
switch (sssParameters.texturingMode)
463-
{
464-
case SubsurfaceScatteringSettings.TexturingMode.PreScatter:
465-
cmd.EnableShaderKeyword("SSS_PRE_SCATTER_TEXTURING");
466-
cmd.DisableShaderKeyword("SSS_POST_SCATTER_TEXTURING");
467-
break;
468-
case SubsurfaceScatteringSettings.TexturingMode.PostScatter:
469-
cmd.DisableShaderKeyword("SSS_PRE_SCATTER_TEXTURING");
470-
cmd.EnableShaderKeyword("SSS_POST_SCATTER_TEXTURING");
471-
break;
472-
case SubsurfaceScatteringSettings.TexturingMode.PreAndPostScatter:
473-
cmd.DisableShaderKeyword("SSS_PRE_SCATTER_TEXTURING");
474-
cmd.DisableShaderKeyword("SSS_POST_SCATTER_TEXTURING");
475-
break;
476-
}
477-
478463
if (globalDebugSettings.renderingDebugSettings.enableSSS)
479464
{
480465
cmd.EnableShaderKeyword("_SUBSURFACE_SCATTERING");

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ TEXTURE2D_ARRAY(_LtcData); // We pack the 3 Ltc data inside a texture array
4949
// SSS parameters
5050
#define SSS_N_PROFILES 8
5151
#define SSS_UNIT_CONVERSION (1.0 / 300.0) // From meters to 1/3 centimeters
52-
uint _TransmissionFlags; // One bit per profile; 1 = enabled
52+
uint _TransmissionFlags; // 1 bit/profile; 0 = inf. thick, 1 = supports transmission
53+
uint _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
5354
float _ThicknessRemaps[SSS_N_PROFILES][2]; // Remap: 0 = start, 1 = end - start
5455
float4 _HalfRcpVariancesAndLerpWeights[SSS_N_PROFILES][2]; // 2x Gaussians per color channel, A is the the associated interpolation weight
5556

@@ -112,13 +113,11 @@ void ApplyDebugToBSDFData(inout BSDFData bsdfData)
112113

113114
void ConfigureTexturingForSSS(inout BSDFData bsdfData)
114115
{
115-
#ifdef SSS_PRE_SCATTER_TEXTURING
116-
bsdfData.diffuseColor = bsdfData.diffuseColor;
117-
#elif SSS_POST_SCATTER_TEXTURING
118-
bsdfData.diffuseColor = float3(1, 1, 1);
119-
#else // combine pre-scatter and post-scatter texturing
120-
bsdfData.diffuseColor = sqrt(bsdfData.diffuseColor);
121-
#endif
116+
bool performPostScatterTexturing = IsBitSet(_TexturingModeFlags, bsdfData.subsurfaceProfile);
117+
118+
// It's either post-scatter, or pre- and post-scatter texturing.
119+
bsdfData.diffuseColor = performPostScatterTexturing ? float3(1, 1, 1)
120+
: sqrt(bsdfData.diffuseColor);
122121
}
123122

124123
// Evaluates transmittance for a linear combination of two normalized 2D Gaussians.
@@ -177,7 +176,7 @@ BSDFData ConvertSurfaceDataToBSDFData(SurfaceData surfaceData)
177176
bsdfData.subsurfaceRadius = SSS_UNIT_CONVERSION * surfaceData.subsurfaceRadius;
178177
bsdfData.thickness = SSS_UNIT_CONVERSION * (_ThicknessRemaps[bsdfData.subsurfaceProfile][0] +
179178
_ThicknessRemaps[bsdfData.subsurfaceProfile][1] * surfaceData.thickness);
180-
bsdfData.enableTransmission = (1 << bsdfData.subsurfaceProfile) & _TransmissionFlags;
179+
bsdfData.enableTransmission = IsBitSet(_TransmissionFlags, bsdfData.subsurfaceProfile);
181180
if (bsdfData.enableTransmission)
182181
{
183182
bsdfData.transmittance = ComputeTransmittance(_HalfRcpVariancesAndLerpWeights[bsdfData.subsurfaceProfile][0].xyz,
@@ -375,7 +374,7 @@ void DecodeFromGBuffer(
375374
bsdfData.subsurfaceRadius = SSS_UNIT_CONVERSION * inGBuffer2.r;
376375
bsdfData.thickness = SSS_UNIT_CONVERSION * (_ThicknessRemaps[bsdfData.subsurfaceProfile][0] +
377376
_ThicknessRemaps[bsdfData.subsurfaceProfile][1] * inGBuffer2.g);
378-
bsdfData.enableTransmission = (1 << bsdfData.subsurfaceProfile) & _TransmissionFlags;
377+
bsdfData.enableTransmission = IsBitSet(_TransmissionFlags, bsdfData.subsurfaceProfile);
379378
if (bsdfData.enableTransmission)
380379
{
381380
bsdfData.transmittance = ComputeTransmittance(_HalfRcpVariancesAndLerpWeights[bsdfData.subsurfaceProfile][0].xyz,

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,12 @@ Shader "Hidden/HDRenderPipeline/CombineSubsurfaceScattering"
154154
totalWeight += sampleWeight;
155155
}
156156

157-
#ifdef SSS_PRE_SCATTER_TEXTURING
158-
float3 diffuseContrib = float3(1, 1, 1);
159-
#elif SSS_POST_SCATTER_TEXTURING
160-
float3 diffuseColor = DecodeGBuffer0(LOAD_TEXTURE2D(_GBufferTexture0, posInput.unPositionSS)).rgb;
161-
float3 diffuseContrib = diffuseColor;
162-
#else // combine pre-scatter and post-scatter texturing
163-
float3 diffuseColor = DecodeGBuffer0(LOAD_TEXTURE2D(_GBufferTexture0, posInput.unPositionSS)).rgb;
164-
float3 diffuseContrib = sqrt(diffuseColor);
165-
#endif
166-
167157
#ifdef FILTER_HORIZONTAL_AND_COMBINE
158+
bool performPostScatterTexturing = IsBitSet(_TexturingModeFlags, profileID);
159+
160+
// It's either post-scatter, or pre- and post-scatter texturing.
161+
float3 diffuseContrib = performPostScatterTexturing ? bsdfData.diffuseColor
162+
: sqrt(bsdfData.diffuseColor);
168163
return float4(diffuseContrib * totalIrradiance / totalWeight, 1.0);
169164
#else
170165
return float4(totalIrradiance / totalWeight, 1.0);

0 commit comments

Comments
 (0)