浏览代码

Add an SSS_DISTANCE_SCALE to allow for a wider range of standard deviations

/Branch_Batching2
Evgenii Golubev 8 年前
当前提交
9c734442
共有 5 个文件被更改,包括 45 次插入37 次删除
  1. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  2. 17
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  3. 41
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs
  4. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawGaussianProfile.shader
  5. 13
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader

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


// SSS parameters
#define SSS_N_PROFILES 8
#define SSS_N_SAMPLES 11
#define SSS_DISTANCE_SCALE 3 // SSS distance units per centimeter
#define CENTIMETERS_TO_METERS 0.001
uint _EnableSSS; // Globally toggles subsurface scattering on/off

float3 halfRcpVariance2, float lerpWeight2,
float3 tintColor, float thickness, float radiusScale)
{
// thickness /= radiusScale;
thickness /= CENTIMETERS_TO_METERS;
// thickness *= SSS_DISTANCE_SCALE / radiusScale;
thickness *= SSS_DISTANCE_SCALE / CENTIMETERS_TO_METERS;
float t2 = thickness * thickness;

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


// Inputs & outputs
//-------------------------------------------------------------------------------------
#define N_PROFILES 8
#define N_SAMPLES 11
float4 _FilterKernels[SSS_N_PROFILES][SSS_N_SAMPLES]; // RGB = weights, A = radial distance
float4 _HalfRcpWeightedVariances[SSS_N_PROFILES]; // RGB for chromatic, A for achromatic
float4 _FilterKernels[N_PROFILES][N_SAMPLES]; // RGB = weights, A = radial distance
float4 _HalfRcpWeightedVariances[N_PROFILES]; // RGB for chromatic, A for achromatic
TEXTURE2D(_IrradianceSource); // RGB = irradiance on the back side of the object
DECLARE_GBUFFER_TEXTURE(_GBufferTexture); // Contains the albedo and SSS parameters
TEXTURE2D(_IrradianceSource); // RGB = irradiance on the back side of the object
DECLARE_GBUFFER_TEXTURE(_GBufferTexture); // Contains the albedo and SSS parameters
//-------------------------------------------------------------------------------------
// Implementation

DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, unused);
int profileID = bsdfData.subsurfaceProfile;
float distScale = bsdfData.subsurfaceRadius;
float distScale = bsdfData.subsurfaceRadius * rcp(SSS_DISTANCE_SCALE);
float invDistScale = rcp(distScale);
// Reconstruct the view-space position.

// We perform point sampling. Therefore, we can avoid the cost
// of filtering if we stay within the bounds of the current pixel.
float maxDistance = _FilterKernels[profileID][N_SAMPLES - 1].a;
float maxDistance = _FilterKernels[profileID][SSS_N_SAMPLES - 1].a;
[branch]
if (scaledStepSize * maxDistance < 0.5)

float3 totalWeight = sampleWeight;
[unroll]
for (int i = 1; i < N_SAMPLES; i++)
for (int i = 1; i < SSS_N_SAMPLES; i++)
{
samplePosition = posInput.unPositionSS + rotatedDirection * _FilterKernels[profileID][i].a;
sampleWeight = _FilterKernels[profileID][i].rgb;

41
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs


{
public enum TexturingMode : int { PreAndPostScatter = 0, PostScatter = 1 };
public const int numSamples = 11; // Must be an odd number
public const int numSamples = 11; // Must be an odd number
public const float distanceScale = 3; // SSS distance units per centimeter
[ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
public Color scatterDistance1;

public SubsurfaceScatteringProfile()
{
scatterDistance1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
scatterDistance2 = new Color(0.6f, 0.6f, 0.6f, 0.0f);
lerpWeight = 0.5f;
scatterDistance2 = new Color(0.5f, 0.5f, 0.5f, 0.0f);
lerpWeight = 1.0f;
thicknessRemap = new Vector2(0, 1);
thicknessRemap = new Vector2(0, 0.5f);
settingsIndex = SubsurfaceScatteringSettings.neutralProfileID; // Updated by SubsurfaceScatteringSettings.OnValidate() once assigned
UpdateKernelAndVarianceData();

m_HalfRcpVariances = new Vector3[2];
}
// Apply the three-sigma rule.
Color stdDev1 = scatterDistance1 * (1.0f / 3.0f);
Color stdDev2 = scatterDistance2 * (1.0f / 3.0f);
// Apply the three-sigma rule, and rescale.
// Increase the value a bit due to our (low) number of samples.
Color stdDev1 = ((1.0f / 3.0f) * (1.0f / 0.8f) * distanceScale) * scatterDistance1;
Color stdDev2 = ((1.0f / 3.0f) * (1.0f / 0.8f) * distanceScale) * scatterDistance2;
// Our goal is to blur the image using a filter which is represented
// as a product of a linear combination of two normalized 1D Gaussians

// A2(v1, v2, w, x, y) = A1(v1, v2, w, x) * A1(v1, v2, w, y).
// The resulting filter function is a non-Gaussian PDF.
// It is separable by design, but generally not radially symmetric.
// N.b.: our scattering distance is rather limited. Therefore, in order to allow
// for a greater range of standard deviation values for flatter profiles,
// we rescale the world using 'distanceScale', effectively reducing the SSS
// distance units from centimeters to (1 / distanceScale).
// Find the widest Gaussian across 3 color channels.
float maxStdDev1 = Mathf.Max(stdDev1.r, stdDev1.g, stdDev1.b);

EditorGUILayout.Space();
}
// Apply the three-sigma rule.
Vector4 stdDev1 = new Vector4((1.0f / 3.0f) * m_ScatterDistance1.colorValue.r,
(1.0f / 3.0f) * m_ScatterDistance1.colorValue.g,
(1.0f / 3.0f) * m_ScatterDistance1.colorValue.b);
Vector4 stdDev2 = new Vector4((1.0f / 3.0f) * m_ScatterDistance2.colorValue.r,
(1.0f / 3.0f) * m_ScatterDistance2.colorValue.g,
(1.0f / 3.0f) * m_ScatterDistance2.colorValue.b);
// Apply the three-sigma rule, and rescale.
// Increase the value a bit due to our (low) number of samples.
float s = (1.0f / 3.0f) * (1.0f / 0.8f) * SubsurfaceScatteringProfile.distanceScale;
Vector4 stdDev1 = new Vector4(s * m_ScatterDistance1.colorValue.r, s * m_ScatterDistance1.colorValue.g, s * m_ScatterDistance1.colorValue.b);
Vector4 stdDev2 = new Vector4(s * m_ScatterDistance2.colorValue.r, s * m_ScatterDistance2.colorValue.g, s * m_ScatterDistance2.colorValue.b);
Vector4 tintCol = new Vector4(m_TintColor.colorValue.r, m_TintColor.colorValue.g, m_TintColor.colorValue.b);
m_ProfileMaterial.SetVector("_StdDev1", stdDev1);
m_ProfileMaterial.SetVector("_StdDev2", stdDev2);
m_ProfileMaterial.SetVector("_StdDev1", stdDev1);
m_ProfileMaterial.SetVector("_StdDev2", stdDev2);
m_ProfileMaterial.SetFloat("_LerpWeight", m_LerpWeight.floatValue);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256, 256), m_ProfileImage, m_ProfileMaterial, ScaleMode.ScaleToFit, 1.0f);

m_TransmittanceMaterial.SetVector("_StdDev2", stdDev2);
m_TransmittanceMaterial.SetFloat("_LerpWeight", m_LerpWeight.floatValue);
m_TransmittanceMaterial.SetVector("_ThicknessRemap", m_ThicknessRemap.vector2Value);
m_TransmittanceMaterial.SetVector("_TintColor", m_TintColor.colorValue);
m_TransmittanceMaterial.SetVector("_TintColor", tintCol);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16, 16), m_TransmittanceImage, m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16.0f);
serializedObject.ApplyModifiedProperties();

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawGaussianProfile.shader


// Inputs & outputs
//-------------------------------------------------------------------------------------
#define SSS_DISTANCE_SCALE 3 // SSS distance units per centimeter
float4 _StdDev1, _StdDev2; float _LerpWeight; // See 'SubsurfaceScatteringParameters'
//-------------------------------------------------------------------------------------

float4 Frag(Varyings input) : SV_Target
{
float dist = length(input.texcoord - 0.5);
float dist = length(input.texcoord - 0.5) * SSS_DISTANCE_SCALE;
float3 var1 = _StdDev1.rgb * _StdDev1.rgb;
float3 var2 = _StdDev2.rgb * _StdDev2.rgb;

13
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader


{
Properties
{
[HideInInspector] _StdDev1("", Color) = (0, 0, 0)
[HideInInspector] _StdDev2("", Color) = (0, 0, 0)
[HideInInspector] _StdDev1("", Vector) = (0, 0, 0, 0)
[HideInInspector] _StdDev2("", Vector) = (0, 0, 0, 0)
[HideInInspector] _ThicknessScale("", Float) = 0
[HideInInspector] _TintColor("", Color) = (0, 0, 0)
[HideInInspector] _TintColor("", Vector) = (0, 0, 0, 0)
}
SubShader

// Inputs & outputs
//-------------------------------------------------------------------------------------
#define SSS_DISTANCE_SCALE 3 // SSS distance units per centimeter
float _LerpWeight; // See 'SubsurfaceScatteringParameters'
float _LerpWeight; // See 'SubsurfaceScatteringParameters'
//-------------------------------------------------------------------------------------
// Implementation

float4 Frag(Varyings input) : SV_Target
{
float thickness = _ThicknessRemap.x + input.texcoord.x * (_ThicknessRemap.y - _ThicknessRemap.x);
float thickness = (_ThicknessRemap.x + input.texcoord.x * (_ThicknessRemap.y - _ThicknessRemap.x)) * SSS_DISTANCE_SCALE;
float t2 = thickness * thickness;
float3 var1 = _StdDev1.rgb * _StdDev1.rgb;

正在加载...
取消
保存