浏览代码

Renamed properly SSR settings

/main
Frédéric Vauchelles 6 年前
当前提交
225851ea
共有 6 个文件被更改,包括 39 次插入40 次删除
  1. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  3. 14
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceLighting.cs
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceReflection.cs
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceRefraction.cs
  6. 41
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs


protected SerializedDataParameter m_RayMinLevel;
protected SerializedDataParameter m_RayMaxLevel;
protected SerializedDataParameter m_RayMaxIterations;
protected SerializedDataParameter m_RayDepthSuccessBias;
protected SerializedDataParameter m_DepthBufferThickness;
protected SerializedDataParameter m_ScreenWeightDistance;
protected SerializedDataParameter m_RayMaxScreenDistance;
protected SerializedDataParameter m_RayBlendScreenDistance;

m_RayMinLevel = Unpack(o.Find(x => x.rayMinLevel));
m_RayMaxLevel = Unpack(o.Find(x => x.rayMaxLevel));
m_RayMaxIterations = Unpack(o.Find(x => x.rayMaxIterations));
m_RayDepthSuccessBias = Unpack(o.Find(x => x.rayDepthSuccessBias));
m_DepthBufferThickness = Unpack(o.Find(x => x.depthBufferThickness));
m_ScreenWeightDistance = Unpack(o.Find(x => x.screenWeightDistance));
m_RayMaxScreenDistance = Unpack(o.Find(x => x.rayMaxScreenDistance));
m_RayBlendScreenDistance = Unpack(o.Find(x => x.rayBlendScreenDistance));

PropertyField(m_RayMinLevel, CoreEditorUtils.GetContent("Ray Min Level"));
PropertyField(m_RayMaxLevel, CoreEditorUtils.GetContent("Ray Max Level"));
PropertyField(m_RayMaxIterations, CoreEditorUtils.GetContent("Ray Max Iterations"));
PropertyField(m_RayDepthSuccessBias, CoreEditorUtils.GetContent("Ray Depth Success Bias"));
PropertyField(m_RayMaxScreenDistance, CoreEditorUtils.GetContent("Ray Maximum Raymarched Screen Distance"));
PropertyField(m_RayBlendScreenDistance, CoreEditorUtils.GetContent("Ray Blended Raymarched Screen Distance"));
PropertyField(m_DepthBufferThickness, CoreEditorUtils.GetContent("Depth Buffer Thickness"));
PropertyField(m_RayMaxScreenDistance, CoreEditorUtils.GetContent("Max Raymarched Distance (NDC)"));
PropertyField(m_RayBlendScreenDistance, CoreEditorUtils.GetContent("Blended Raymarched Distance (NDC)"));
m_RayLevel.value.intValue = Mathf.Max(0, m_RayLevel.value.intValue);
m_RayMaxLinearIterationsLevel.value.intValue = Mathf.Max(0, m_RayMaxLinearIterationsLevel.value.intValue);

m_RayDepthSuccessBias.value.floatValue = Mathf.Max(0.001f, m_RayDepthSuccessBias.value.floatValue);
m_DepthBufferThickness.value.floatValue = Mathf.Max(0.001f, m_DepthBufferThickness.value.floatValue);
m_RayMaxScreenDistance.value.floatValue = Mathf.Clamp(m_RayMaxScreenDistance.value.floatValue, 0.001f, 1.0f);
m_RayBlendScreenDistance.value.floatValue = Mathf.Clamp(m_RayBlendScreenDistance.value.floatValue, 0.0f, m_RayMaxScreenDistance.value.floatValue);
}

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _SSRefractionRayMinLevel = Shader.PropertyToID("_SSRefractionRayMinLevel");
public static readonly int _SSRefractionRayMaxLevel = Shader.PropertyToID("_SSRefractionRayMaxLevel");
public static readonly int _SSRefractionRayMaxIterations = Shader.PropertyToID("_SSRefractionRayMaxIterations");
public static readonly int _SSRefractionRayDepthSuccessBias = Shader.PropertyToID("_SSRefractionRayDepthSuccessBias");
public static readonly int _SSRefractionDepthBufferThickness = Shader.PropertyToID("_SSRefractionDepthBufferThickness");
public static readonly int _SSRefractionInvScreenWeightDistance = Shader.PropertyToID("_SSRefractionInvScreenWeightDistance");
public static readonly int _SSReflectionRayMaxScreenDistance = Shader.PropertyToID("_SSReflectionRayMaxScreenDistance");

public static readonly int _SSReflectionRayMinLevel = Shader.PropertyToID("_SSReflectionRayMinLevel");
public static readonly int _SSReflectionRayMaxLevel = Shader.PropertyToID("_SSReflectionRayMaxLevel");
public static readonly int _SSReflectionRayMaxIterations = Shader.PropertyToID("_SSReflectionRayMaxIterations");
public static readonly int _SSReflectionRayDepthSuccessBias = Shader.PropertyToID("_SSReflectionRayDepthSuccessBias");
public static readonly int _SSReflectionDepthBufferThickness = Shader.PropertyToID("_SSReflectionDepthBufferThickness");
public static readonly int _SSReflectionInvScreenWeightDistance = Shader.PropertyToID("_SSReflectionInvScreenWeightDistance");
public static readonly int _SSReflectionProjectionModel = Shader.PropertyToID("_SSReflectionProjectionModel");
public static readonly int _SSReflectionEnabled = Shader.PropertyToID("_SSReflectionEnabled");

14
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceLighting.cs


int m_RayMinLevelID;
int m_RayMaxLevelID;
int m_RayMaxIterationsID;
int m_RayDepthSuccessBiasID;
int m_DepthBufferThicknessID;
int m_InvScreenWeightDistanceID;
int m_RayMaxScreenDistanceID;
int m_RayBlendScreenDistanceID;

public IntParameter rayMinLevel = new IntParameter(2);
public IntParameter rayMaxLevel = new IntParameter(6);
public IntParameter rayMaxIterations = new IntParameter(32);
public FloatParameter rayDepthSuccessBias = new FloatParameter(0.1f);
public FloatParameter depthBufferThickness = new FloatParameter(1f);
public FloatParameter rayMaxScreenDistance = new FloatParameter(0.3f);
public FloatParameter rayBlendScreenDistance = new FloatParameter(0.1f);
public ClampedFloatParameter rayMaxScreenDistance = new ClampedFloatParameter(0.3f, 0, 1);
public ClampedFloatParameter rayBlendScreenDistance = new ClampedFloatParameter(0.1f, 0, 1);
public virtual void PushShaderParameters(CommandBuffer cmd)
{

cmd.SetGlobalInt(m_RayMaxLevelID, rayMaxLevel.value);
cmd.SetGlobalInt(m_RayMaxIterationsID, rayMaxIterations.value);
cmd.SetGlobalFloat(m_RayDepthSuccessBiasID, rayDepthSuccessBias.value);
cmd.SetGlobalFloat(m_DepthBufferThicknessID, depthBufferThickness.value);
cmd.SetGlobalFloat(m_InvScreenWeightDistanceID, 1f / screenWeightDistance.value);
cmd.SetGlobalFloat(m_RayMaxScreenDistanceID, rayMaxScreenDistance.value);
cmd.SetGlobalFloat(m_RayBlendScreenDistanceID, rayBlendScreenDistance.value);

out int rayMinLevelID,
out int rayMaxLevelID,
out int rayMaxIterationsID,
out int rayDepthSuccessBiasID,
out int DepthBufferThicknessID,
out int invScreenWeightDistanceID,
out int rayMaxScreenDistanceID,
out int rayBlendScreenDistanceID

out m_RayMinLevelID,
out m_RayMaxLevelID,
out m_RayMaxIterationsID,
out m_RayDepthSuccessBiasID,
out m_DepthBufferThicknessID,
out m_InvScreenWeightDistanceID,
out m_RayMaxScreenDistanceID,
out m_RayBlendScreenDistanceID

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceReflection.cs


out int rayMinLevelID,
out int rayMaxLevelID,
out int rayMaxIterationsID,
out int rayDepthSuccessBiasID,
out int depthBufferThicknessID,
out int screenWeightDistanceID,
out int rayMaxScreenDistanceID,
out int rayBlendScreenDistanceID

rayMinLevelID = HDShaderIDs._SSReflectionRayMinLevel;
rayMaxLevelID = HDShaderIDs._SSReflectionRayMaxLevel;
rayMaxIterationsID = HDShaderIDs._SSReflectionRayMaxIterations;
rayDepthSuccessBiasID = HDShaderIDs._SSReflectionRayDepthSuccessBias;
depthBufferThicknessID = HDShaderIDs._SSReflectionDepthBufferThickness;
screenWeightDistanceID = HDShaderIDs._SSReflectionInvScreenWeightDistance;
rayMaxScreenDistanceID = HDShaderIDs._SSReflectionRayMaxScreenDistance;
rayBlendScreenDistanceID = HDShaderIDs._SSReflectionRayBlendScreenDistance;

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceRefraction.cs


out int rayMinLevelID,
out int rayMaxLevelID,
out int rayMaxIterationsID,
out int rayDepthSuccessBiasID,
out int depthBufferThicknessID,
out int invScreenWeightDistanceID,
out int rayMaxScreenDistanceID,
out int rayBlendScreenDistanceID

rayMinLevelID = HDShaderIDs._SSRefractionRayMinLevel;
rayMaxLevelID = HDShaderIDs._SSRefractionRayMaxLevel;
rayMaxIterationsID = HDShaderIDs._SSRefractionRayMaxIterations;
rayDepthSuccessBiasID = HDShaderIDs._SSRefractionRayDepthSuccessBias;
depthBufferThicknessID = HDShaderIDs._SSRefractionDepthBufferThickness;
invScreenWeightDistanceID = HDShaderIDs._SSRefractionInvScreenWeightDistance;
rayMaxScreenDistanceID = HDShaderIDs._SSRefractionRayMaxScreenDistance;
rayBlendScreenDistanceID = HDShaderIDs._SSRefractionRayBlendScreenDistance;

41
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl


ScreenSpaceRayHit hit,
float2 startPositionSS,
float minLinearDepth,
float settingsRayDepthSuccessBias,
float settingsDepthBufferThickness,
float thicknessWeight = clamp(1 - (hit.linearDepth - minLinearDepth) / settingsRayDepthSuccessBias, 0, 1);
return thicknessWeight;
float thicknessWeight = clamp(1 - (hit.linearDepth - minLinearDepth) / settingsDepthBufferThickness, 0, 1);
// float2 screenDistanceNDC = abs(hit.positionSS.xy - startPositionSS) * _ScreenSize.zw;
// float2 screenDistanceWeights = clamp((settingsRayMaxScreenDistance - screenDistanceNDC) / settingsRayBlendScreenDistance, 0, 1);
// float screenDistanceWeight = min(screenDistanceWeights.x, screenDistanceWeights.y);
float2 screenDistanceNDC = abs(hit.positionSS.xy - startPositionSS) * _ScreenSize.zw;
float2 screenDistanceWeights = clamp((settingsRayMaxScreenDistance - screenDistanceNDC) / settingsRayBlendScreenDistance, 0, 1);
float screenDistanceWeight = min(screenDistanceWeights.x, screenDistanceWeights.y);
// return thicknessWeight * screenDistanceWeight;
return thicknessWeight * screenDistanceWeight;
}
#ifdef DEBUG_DISPLAY

// Settings
int settingRayLevel, // Mip level to use to ray march depth buffer
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples)
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface
float settingsDepthBufferThickness, // Bias to use when trying to detect whenever we raymarch behind a surface
float settingsRayMaxScreenDistance, // Maximum screen distance raymarched
float settingsRayBlendScreenDistance, // Distance to blend before maximum screen distance is reached
int settingsDebuggedAlgorithm, // currently debugged algorithm (see PROJECTIONMODEL defines)

invLinearDepth = LoadInvDepth(positionSS.xy, mipLevel);
minLinearDepth = 1 / invLinearDepth.r;
minLinearDepthWithThickness = minLinearDepth + settingsRayDepthSuccessBias;
minLinearDepthWithThickness = minLinearDepth + settingsDepthBufferThickness;
positionLinearDepth = 1 / positionSS.z;
bool isAboveDepth = positionLinearDepth < minLinearDepth;
bool isAboveThickness = positionLinearDepth < minLinearDepthWithThickness;

hit,
startPositionSS.xy,
invLinearDepth,
settingsRayDepthSuccessBias,
settingsDepthBufferThickness,
settingsRayMaxScreenDistance,
settingsRayBlendScreenDistance
);

// Settings (linear)
int settingRayLevel, // Mip level to use to ray march depth buffer
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples)
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface
float settingsDepthBufferThickness, // Bias to use when trying to detect whenever we raymarch behind a surface
float settingsRayMaxScreenDistance, // Maximum screen distance raymarched
float settingsRayBlendScreenDistance, // Distance to blend before maximum screen distance is reached
// Settings (common)

// Settings
settingRayLevel,
settingsRayMaxIterations,
settingsRayDepthSuccessBias,
settingsDepthBufferThickness,
settingsRayMaxScreenDistance,
settingsRayBlendScreenDistance,
settingsDebuggedAlgorithm,

uint settingsRayMaxLevel, // Maximum mip level to use for ray marching the depth buffer in HiZ
uint settingsRayMaxIterations, // Maximum number of iteration for the HiZ raymarching (= number of depth sample for HiZ)
uint settingsRayMaxLinearIterations, // Maximum number of iteration for the linear raymarching (= number of depth sample for linear)
float settingsRayDepthSuccessBias, // Bias to use when trying to detect whenever we raymarch behind a surface
float settingsDepthBufferThickness, // Bias to use when trying to detect whenever we raymarch behind a surface
float settingsRayMaxScreenDistance, // Maximum screen distance raymarched
float settingsRayBlendScreenDistance, // Distance to blend before maximum screen distance is reached
int settingsDebuggedAlgorithm, // currently debugged algorithm (see PROJECTIONMODEL defines)

// settings
settingsRayLevel,
settingsRayMaxLinearIterations,
settingsRayDepthSuccessBias,
settingsDepthBufferThickness,
settingsRayMaxScreenDistance,
settingsRayBlendScreenDistance,
settingsDebuggedAlgorithm,

positionLinearDepth = 1 / positionSS.z;
minLinearDepth = 1 / invLinearDepth.r;
minLinearDepthWithThickness = minLinearDepth + settingsRayDepthSuccessBias;
minLinearDepthWithThickness = minLinearDepth + settingsDepthBufferThickness;
bool isAboveDepth = positionLinearDepth < minLinearDepth;
bool isAboveThickness = positionLinearDepth < minLinearDepthWithThickness;
bool isBehindDepth = !isAboveThickness;

debugLoopMipMaxUsedLevel = max(debugLoopMipMaxUsedLevel, currentLevel);
debugIterationPositionSS = positionSS;
debugIterationLinearDepthBufferMin = 1 / invLinearDepth.r;
debugIterationLinearDepthBufferMinThickness = 1 / invLinearDepth.r + settingsRayDepthSuccessBias;
debugIterationLinearDepthBufferMinThickness = 1 / invLinearDepth.r + settingsDepthBufferThickness;
debugIterationLinearDepthBufferMax = 1 / invLinearDepth.g;
debugIteration = iteration;
debugIterationIntersectionKind = intersectionKind;

// hit,
// startPositionSS.xy,
// invLinearDepth,
// settingsRayDepthSuccessBias,
// settingsDepthBufferThickness,
// settingsRayMaxScreenDistance,
// settingsRayBlendScreenDistance
// );

startPositionSS.xy,
minLinearDepth,
settingsRayDepthSuccessBias,
settingsDepthBufferThickness,
settingsRayMaxScreenDistance,
settingsRayBlendScreenDistance
);

int SSRT_SETTING(RayMaxLevel, SSRTID);
int SSRT_SETTING(RayMaxLinearIterations, SSRTID);
int SSRT_SETTING(RayMaxIterations, SSRTID);
float SSRT_SETTING(RayDepthSuccessBias, SSRTID);
float SSRT_SETTING(DepthBufferThickness, SSRTID);
float SSRT_SETTING(RayMaxScreenDistance, SSRTID);
float SSRT_SETTING(RayBlendScreenDistance, SSRTID);

// settings
SSRT_SETTING(RayLevel, SSRTID),
SSRT_SETTING(RayMaxIterations, SSRTID),
max(0.01, SSRT_SETTING(RayDepthSuccessBias, SSRTID)),
max(0.01, SSRT_SETTING(DepthBufferThickness, SSRTID)),
SSRT_SETTING(RayMaxScreenDistance, SSRTID),
SSRT_SETTING(RayBlendScreenDistance, SSRTID),
#ifdef DEBUG_DISPLAY

SSRT_SETTING(RayMaxLevel, SSRTID),
SSRT_SETTING(RayMaxIterations, SSRTID),
SSRT_SETTING(RayMaxLinearIterations, SSRTID),
max(0.01, SSRT_SETTING(RayDepthSuccessBias, SSRTID)),
max(0.01, SSRT_SETTING(DepthBufferThickness, SSRTID)),
SSRT_SETTING(RayMaxScreenDistance, SSRTID),
SSRT_SETTING(RayBlendScreenDistance, SSRTID),
#ifdef DEBUG_DISPLAY

正在加载...
取消
保存