浏览代码

Add Fresnel term to SSS profile

/namespace
Sebastien Lagarde 7 年前
当前提交
30b2b456
共有 9 个文件被更改,包括 21 次插入16 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/SubsurfaceScattering/SubsurfaceScatteringSettingsEditor.Styles.cs
  2. 3
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/SubsurfaceScattering/SubsurfaceScatteringSettingsEditor.cs
  3. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl
  7. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl
  9. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringSettings.cs

1
ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/SubsurfaceScattering/SubsurfaceScatteringSettingsEditor.Styles.cs


public readonly GUIContent profileMinMaxThickness = new GUIContent("Min-Max Thickness (mm)", "Shows the values of the thickness remap below (in millimeters).");
public readonly GUIContent profileThicknessRemap = new GUIContent("Thickness Remap (mm)", "Remaps the thickness parameter from [0, 1] to the desired range (in millimeters).");
public readonly GUIContent profileWorldScale = new GUIContent("World Scale", "Size of the world unit in meters.");
public readonly GUIContent profileFresnel0 = new GUIContent("Specular", "Percentage of light reflected at incident angle. Typical skin value is 0.028");
// Old SSS Model >>>
public readonly GUIContent profileScatterDistance1 = new GUIContent("Scattering Distance #1", "The radius (in centimeters) of the 1st Gaussian filter, one per color channel. Alpha is ignored. The blur is energy-preserving, so a wide filter results in a large area with small contributions of individual samples. Smaller values increase the sharpness.");
public readonly GUIContent profileScatterDistance2 = new GUIContent("Scattering Distance #2", "The radius (in centimeters) of the 2nd Gaussian filter, one per color channel. Alpha is ignored. The blur is energy-preserving, so a wide filter results in a large area with small contributions of individual samples. Smaller values increase the sharpness.");

3
ScriptableRenderPipeline/HDRenderPipeline/Editor/Material/SubsurfaceScattering/SubsurfaceScatteringSettingsEditor.cs


internal SerializedProperty transmissionMode;
internal SerializedProperty thicknessRemap;
internal SerializedProperty worldScale;
internal SerializedProperty fresnel0;
// Old SSS Model >>>
internal SerializedProperty scatterDistance1;

transmissionMode = rp.Find(x => x.transmissionMode),
thicknessRemap = rp.Find(x => x.thicknessRemap),
worldScale = rp.Find(x => x.worldScale),
fresnel0 = rp.Find(x => x.fresnel0),
scatterDistance1 = rp.Find(x => x.scatterDistance1),
scatterDistance2 = rp.Find(x => x.scatterDistance2),

EditorGUILayout.MinMaxSlider(s_Styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0f, 50f);
profile.thicknessRemap.vector2Value = thicknessRemap;
EditorGUILayout.PropertyField(profile.worldScale, s_Styles.profileWorldScale);
EditorGUILayout.Slider(profile.fresnel0, 0.0f, 0.1f, s_Styles.profileFresnel0);
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.profilePreview0, s_Styles.centeredMiniBoldLabel);

10
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


cmd.SetGlobalFloat(HDShaderIDs._TexturingModeFlags, *(float*)&texturingModeFlags);
cmd.SetGlobalFloat(HDShaderIDs._TransmissionFlags, *(float*)&transmissionFlags);
}
cmd.SetGlobalVectorArray(HDShaderIDs._ThicknessRemaps, sssParameters.thicknessRemaps);
cmd.SetGlobalVectorArray(HDShaderIDs._ShapeParams, sssParameters.shapeParams);
cmd.SetGlobalVectorArray(HDShaderIDs._HalfRcpVariancesAndWeights, sssParameters.halfRcpVariancesAndWeights);
cmd.SetGlobalVectorArray(HDShaderIDs._TransmissionTints, sssParameters.transmissionTints);
cmd.SetGlobalVectorArray(HDShaderIDs._WorldScales, sssParameters.worldScales);
cmd.SetGlobalVectorArray(HDShaderIDs._ThicknessRemaps, sssParameters.thicknessRemaps);
cmd.SetGlobalVectorArray(HDShaderIDs._ShapeParams, sssParameters.shapeParams);
cmd.SetGlobalVectorArray(HDShaderIDs._HalfRcpVariancesAndWeights, sssParameters.halfRcpVariancesAndWeights);
cmd.SetGlobalVectorArray(HDShaderIDs._TransmissionTintsAndFresnel0, sssParameters.transmissionTintsAndFresnel0);
cmd.SetGlobalVectorArray(HDShaderIDs._WorldScales, sssParameters.worldScales);
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int _ThicknessRemaps = Shader.PropertyToID("_ThicknessRemaps");
public static readonly int _ShapeParams = Shader.PropertyToID("_ShapeParams");
public static readonly int _HalfRcpVariancesAndWeights = Shader.PropertyToID("_HalfRcpVariancesAndWeights");
public static readonly int _TransmissionTints = Shader.PropertyToID("_TransmissionTints");
public static readonly int _TransmissionTintsAndFresnel0 = Shader.PropertyToID("_TransmissionTintsAndFresnel0");
public static readonly int specularLightingUAV = Shader.PropertyToID("specularLightingUAV");
public static readonly int diffuseLightingUAV = Shader.PropertyToID("diffuseLightingUAV");

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


public static int s_GBufferLitStandardSpecularColorId = 1;
public static float s_DefaultSpecularValue = 0.04f;
public static float s_SkinSpecularValue = 0.028f;
}
[GenerateHLSL(PackingRules.Exact)]

1
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs.hlsl


#define GBUFFER_LIT_STANDARD_REGULAR_ID (0)
#define GBUFFER_LIT_STANDARD_SPECULAR_COLOR_ID (1)
#define DEFAULT_SPECULAR_VALUE (0.04)
#define SKIN_SPECULAR_VALUE (0.028)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+RefractionMode: static fields

8
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


if (_UseDisneySSS != 0)
{
bsdfData.transmittance = ComputeTransmittanceDisney(_ShapeParams[subsurfaceProfile].rgb,
_TransmissionTints[subsurfaceProfile].rgb,
_TransmissionTintsAndFresnel0[subsurfaceProfile].rgb,
bsdfData.thickness, bsdfData.subsurfaceRadius);
}
else

_HalfRcpVariancesAndWeights[subsurfaceProfile][1].rgb,
_HalfRcpVariancesAndWeights[subsurfaceProfile][1].a,
_TransmissionTints[subsurfaceProfile].rgb,
_TransmissionTintsAndFresnel0[subsurfaceProfile].rgb,
bsdfData.thickness, bsdfData.subsurfaceRadius);
}
}

else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = SKIN_SPECULAR_VALUE; // TODO: take from the SSS profile
bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[surfaceData.subsurfaceProfile].a;
uint transmissionMode = BitFieldExtract(asuint(_TransmissionFlags), 2u, 2u * surfaceData.subsurfaceProfile);
FillMaterialIdSssData(surfaceData.subsurfaceProfile,

radius = sssData.subsurfaceRadius;
thickness = inGBuffer2.g;
dielectricF0 = SKIN_SPECULAR_VALUE; // TODO: take from the SSS profile
dielectricF0 = _TransmissionTintsAndFresnel0[subsurfaceProfile].a;
}
FillMaterialIdSssData(subsurfaceProfile, radius, thickness, transmissionMode, bsdfData);

2
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl


// 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
float4 _TransmissionTintsAndFresnel0[SSS_N_PROFILES]; // RGB = 1/4 * color, A = fresnel0
float4 _WorldScales[SSS_N_PROFILES]; // X = meters per world unit; Y = world units per meter
CBUFFER_END

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


public TransmissionMode transmissionMode;
public Vector2 thicknessRemap; // X = min, Y = max (in millimeters)
public float worldScale; // Size of the world unit in meters
public float fresnel0; // Fresnel0, 0.028 for skin
// Old SSS Model >>>
[ColorUsage(false, true)]

transmissionMode = TransmissionMode.None;
thicknessRemap = new Vector2(0f, 5f);
worldScale = 1f;
fresnel0 = 0.028f; // TYpical value for skin specular reflectance
// Old SSS Model >>>
scatterDistance1 = new Color(0.3f, 0.3f, 0.3f, 0f);

thicknessRemap.y = Mathf.Max(thicknessRemap.y, 0f);
thicknessRemap.x = Mathf.Clamp(thicknessRemap.x, 0f, thicknessRemap.y);
worldScale = Mathf.Max(worldScale, 0.001f);
fresnel0 = Mathf.Clamp(fresnel0, 0.0f, 0.1f);
// Old SSS Model >>>
scatterDistance1 = new Color

[NonSerialized] public Vector4[] thicknessRemaps; // Remap: 0 = start, 1 = end - start
[NonSerialized] public Vector4[] worldScales; // X = meters per world unit; Y = world units per meter
[NonSerialized] public Vector4[] shapeParams; // RGB = S = 1 / D, A = filter radius
[NonSerialized] public Vector4[] transmissionTints; // RGB = color, A = unused
[NonSerialized] public Vector4[] transmissionTintsAndFresnel0; // RGB = color, A = fresnel0
[NonSerialized] public Vector4[] filterKernels; // XY = near field, ZW = far field; 0 = radius, 1 = reciprocal of the PDF
// Old SSS Model >>>

ValidateArray(ref thicknessRemaps, SssConstants.SSS_N_PROFILES);
ValidateArray(ref worldScales, SssConstants.SSS_N_PROFILES);
ValidateArray(ref shapeParams, SssConstants.SSS_N_PROFILES);
ValidateArray(ref transmissionTints, SssConstants.SSS_N_PROFILES);
ValidateArray(ref transmissionTintsAndFresnel0, SssConstants.SSS_N_PROFILES);
ValidateArray(ref filterKernels, SssConstants.SSS_N_PROFILES * SssConstants.SSS_N_SAMPLES_NEAR_FIELD);
// Old SSS Model >>>

worldScales[i] = new Vector4(profiles[p].worldScale, 1.0f / profiles[p].worldScale, 0f, 0f);
shapeParams[i] = profiles[p].shapeParam;
shapeParams[i].w = profiles[p].maxRadius;
transmissionTints[i] = profiles[p].transmissionTint * 0.25f; // Premultiplied
transmissionTintsAndFresnel0[i] = new Vector4(profiles[p].transmissionTint.r * 0.25f, profiles[p].transmissionTint.g * 0.25f, profiles[p].transmissionTint.b * 0.25f, profiles[p].fresnel0); // Premultiplied
for (int j = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++)
{

正在加载...
取消
保存