浏览代码

(wip) Added linear blending for proxy mode

/main
Frédéric Vauchelles 6 年前
当前提交
045dee67
共有 8 个文件被更改,包括 86 次插入27 次删除
  1. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs
  2. 13
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ScreenSpaceLightingEditor.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  4. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceLighting.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceReflection.cs
  6. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceRefraction.cs
  7. 45
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ScreenSpaceTracing.hlsl
  8. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/HDScreenSpaceReflectionEditor.cs


break;
case Lit.ProjectionModel.Proxy:
EditorGUILayout.Separator();
PropertyField(m_RayLevel, CoreEditorUtils.GetContent("Linear Ray Level"));
PropertyField(m_RayMaxLinearIterationsLevel, CoreEditorUtils.GetContent("Linear Iterations"));
PropertyField(m_RayDepthSuccessBias, CoreEditorUtils.GetContent("Linear Ray Depth Success Bias"));
OnProxyInspectorGUI();
break;
}
}

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


{
protected SerializedDataParameter m_RayLevel;
protected SerializedDataParameter m_RayMaxLinearIterationsLevel;
protected SerializedDataParameter m_RayIterationBlending;
protected SerializedDataParameter m_RayMinLevel;
protected SerializedDataParameter m_RayMaxLevel;
protected SerializedDataParameter m_RayMaxIterations;

m_RayLevel = Unpack(o.Find(x => x.rayLevel));
m_RayMaxLinearIterationsLevel = Unpack(o.Find(x => x.rayMaxLinearIterationsLevel));
m_RayIterationBlending = Unpack(o.Find(x => x.rayIterationBlending));
m_RayMinLevel = Unpack(o.Find(x => x.rayMinLevel));
m_RayMaxLevel = Unpack(o.Find(x => x.rayMaxLevel));
m_RayMaxIterations = Unpack(o.Find(x => x.rayMaxIterations));

OnCommonInspectorGUI();
EditorGUILayout.Separator();
OnHiZInspectorGUI();
EditorGUILayout.Separator();
OnProxyInspectorGUI();
}
protected virtual void OnHiZInspectorGUI()

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"));
}
protected virtual void OnProxyInspectorGUI()
{
EditorGUILayout.LabelField(CoreEditorUtils.GetContent("Proxy Settings"));
PropertyField(m_RayLevel, CoreEditorUtils.GetContent("Linear Ray Level"));
PropertyField(m_RayMaxLinearIterationsLevel, CoreEditorUtils.GetContent("Linear Iterations"));
PropertyField(m_RayDepthSuccessBias, CoreEditorUtils.GetContent("Linear Ray Depth Success Bias"));
PropertyField(m_RayIterationBlending, CoreEditorUtils.GetContent("Linear Ray Iteration Blending"));
}
protected virtual void OnCommonInspectorGUI()

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


Shader.PropertyToID("_SSSBufferTexture3"),
};
public static readonly int _SSRefractionRayIterationBlending = Shader.PropertyToID("_SSRefractionRayIterationBlending");
public static readonly int _SSRefractionRayLevel = Shader.PropertyToID("_SSRefractionRayLevel");
public static readonly int _SSRefractionRayMaxLinearIterations = Shader.PropertyToID("_SSRefractionRayMaxLinearIterations");
public static readonly int _SSRefractionRayMinLevel = Shader.PropertyToID("_SSRefractionRayMinLevel");

public static readonly int _SSRefractionInvScreenWeightDistance = Shader.PropertyToID("_SSRefractionInvScreenWeightDistance");
public static readonly int _SSReflectionRayIterationBlending = Shader.PropertyToID("_SSReflectionRayIterationBlending");
public static readonly int _SSReflectionRayMaxLinearIterations = Shader.PropertyToID("_SSReflectionRayMaxLinearIterations");
public static readonly int _SSReflectionRayLevel = Shader.PropertyToID("_SSReflectionRayLevel");
public static readonly int _SSReflectionRayMinLevel = Shader.PropertyToID("_SSReflectionRayMinLevel");

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


{
int m_RayLevelID;
int m_RayMaxLinearIterationsID;
int m_RayIterationBlendingID;
int m_RayMinLevelID;
int m_RayMaxLevelID;
int m_RayMaxIterationsID;

public IntParameter rayLevel = new IntParameter(2);
public IntParameter rayMaxLinearIterationsLevel = new IntParameter(2);
public IntParameter rayIterationBlending = new IntParameter(2);
public IntParameter rayMinLevel = new IntParameter(2);
public IntParameter rayMaxLevel = new IntParameter(6);
public IntParameter rayMaxIterations = new IntParameter(32);

{
cmd.SetGlobalInt(m_RayLevelID, rayLevel.value);
cmd.SetGlobalInt(m_RayMaxLinearIterationsID, rayMaxLinearIterationsLevel.value);
cmd.SetGlobalInt(m_RayIterationBlendingID, rayIterationBlending.value);
cmd.SetGlobalInt(m_RayMinLevelID, rayMinLevel.value);
cmd.SetGlobalInt(m_RayMaxLevelID, rayMaxLevel.value);
cmd.SetGlobalInt(m_RayMaxIterationsID, rayMaxIterations.value);

protected abstract void FetchIDs(
out int rayLevelID,
out int rayMaxLinearIterationsLevelID,
out int rayIterationBlendingID,
out int rayMinLevelID,
out int rayMaxLevelID,
out int rayMaxIterationsID,

FetchIDs(
out m_RayLevelID,
out m_RayMaxLinearIterationsID,
out m_RayIterationBlendingID,
out m_RayMinLevelID,
out m_RayMaxLevelID,
out m_RayMaxIterationsID,

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


protected override void FetchIDs(
out int rayLevelID,
out int rayMaxLinearIterationsLevelID,
out int rayIterationBlending,
out int rayMinLevelID,
out int rayMaxLevelID,
out int rayMaxIterationsID,

{
rayLevelID = HDShaderIDs._SSReflectionRayLevel;
rayMaxLinearIterationsLevelID = HDShaderIDs._SSReflectionRayMaxLinearIterations;
rayIterationBlending = HDShaderIDs._SSReflectionRayIterationBlending;
rayMinLevelID = HDShaderIDs._SSReflectionRayMinLevel;
rayMaxLevelID = HDShaderIDs._SSReflectionRayMaxLevel;
rayMaxIterationsID = HDShaderIDs._SSReflectionRayMaxIterations;

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


protected override void FetchIDs(
out int rayLevelID,
out int rayMaxLinearIerationsID,
out int rayMaxLinearIterationsID,
out int rayIterationBlending,
out int rayMinLevelID,
out int rayMaxLevelID,
out int rayMaxIterationsID,

{
rayLevelID = HDShaderIDs._SSRefractionRayLevel;
rayMaxLinearIerationsID = HDShaderIDs._SSRefractionRayMaxLinearIterations;
rayMaxLinearIterationsID = HDShaderIDs._SSRefractionRayMaxLinearIterations;
rayIterationBlending = HDShaderIDs._SSRefractionRayIterationBlending;
rayMinLevelID = HDShaderIDs._SSRefractionRayMinLevel;
rayMaxLevelID = HDShaderIDs._SSRefractionRayMaxLevel;
rayMaxIterationsID = HDShaderIDs._SSRefractionRayMaxIterations;

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


float rayEndDepth, // Linear depth of the end point used to calculate raySS.
uint2 bufferSize, // Texture size of screen buffers
// Out
out ScreenSpaceRayHit hit
out ScreenSpaceRayHit hit,
out uint iteration
uint iteration = 0u;
iteration = 0u;
int mipLevel = min(max(settingRayLevel, 0), int(_DepthPyramidScale.z));
uint maxIterations = settingsRayMaxIterations;

// Settings (linear)
int settingRayLevel, // Mip level to use to ray march depth buffer
uint settingsRayMaxIterations, // Maximum number of iterations (= max number of depth samples)
uint settingsIterationBlending, // Number of linear raymarching iterations to blend with proxy raycast
out ScreenSpaceRayHit hit
out ScreenSpaceRayHit linearHit, // Linear raymarching hit
out ScreenSpaceRayHit proxyHit, // Proxy raycasting hit
float hitBlending // hit = linearHit * (1.0 - hitBlending) + proxyHit * hitBlending
)
{
// Perform linear raymarch

rayEndDepth
);
uint iteration;
bool hitSuccessful = ScreenSpaceLinearRaymarch(
inputLinear,
// Settings

rayEndDepth,
bufferSize,
// Out
hit
linearHit,
iteration
if (!hitSuccessful)
hitBlending = settingsIterationBlending > 0
? 1.0 + (int(iteration) - int(settingsRayMaxIterations)) / float(settingsIterationBlending)
: 0;
if (!hitSuccessful || hitBlending > 0)
hitSuccessful = ScreenSpaceProxyRaycast(
bool proxyHitSuccessful = ScreenSpaceProxyRaycast(
hit
proxyHit
hitSuccessful = hitSuccessful && proxyHitSuccessful;
}
return hitSuccessful;

rayEndDepth,
bufferSize,
// out
hit
hit,
iteration
))
return true;

float debugIterationLinearDepthBuffer = 0;
#endif
iteration = 0u;
int intersectionKind = 0;
float raySSLength = length(raySS.xy);
raySS /= raySSLength;

int SSRT_SETTING(RayMaxLevel, SSRTID);
int SSRT_SETTING(RayMaxLinearIterations, SSRTID);
int SSRT_SETTING(RayMaxIterations, SSRTID);
int SSRT_SETTING(RayIterationBlending, SSRTID);
float SSRT_SETTING(RayDepthSuccessBias, SSRTID);
#ifdef DEBUG_DISPLAY

rayEndDepth
);
uint iteration;
return ScreenSpaceLinearRaymarch(
input,
// settings

rayEndDepth,
bufferSize,
// out
hit
hit,
iteration
);
}

bool MERGE_NAME(ScreenSpaceProxyRaycast, SSRTID)(
ScreenSpaceProxyRaycastInput input,
out ScreenSpaceRayHit hit
out ScreenSpaceRayHit primaryHit,
out ScreenSpaceRayHit secondaryHit,
out float hitBlending
hitBlending = 0;
SSRT_SETTING(RayIterationBlending, SSRTID),
// Settings (common)
#if DEBUG_DISPLAY
SSRT_SETTING(DebuggedAlgorithm, SSRTID),

// Out
hit
primaryHit,
secondaryHit,
hitBlending
);
}

36
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


// -------------------------------
// Screen space tracing query
// -------------------------------
ScreenSpaceRayHit hit;
ZERO_INITIALIZE(ScreenSpaceRayHit, hit);
ScreenSpaceRayHit primaryHit, secondaryHit;
float hitBlending = 0;
ZERO_INITIALIZE(ScreenSpaceRayHit, primaryHit);
ZERO_INITIALIZE(ScreenSpaceRayHit, secondaryHit);
bool hitSuccessful = false;
// -------------------------------

#if HAS_REFRACTION
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
hitSuccessful = ScreenSpaceProxyRaycastRefraction(ssRayInput, hit);
hitSuccessful = ScreenSpaceProxyRaycastRefraction(ssRayInput, primaryHit, secondaryHit, hitBlending);
hitSuccessful = ScreenSpaceProxyRaycastReflection(ssRayInput, hit);
hitSuccessful = ScreenSpaceProxyRaycastReflection(ssRayInput, primaryHit, secondaryHit, hitBlending);
}
// -------------------------------

#if HAS_REFRACTION
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
hitSuccessful = ScreenSpaceHiZRaymarchRefraction(ssRayInput, hit);
hitSuccessful = ScreenSpaceHiZRaymarchRefraction(ssRayInput, primaryHit);
hitSuccessful = ScreenSpaceHiZRaymarchReflection(ssRayInput, hit);
hitSuccessful = ScreenSpaceHiZRaymarchReflection(ssRayInput, primaryHit);
}
// Debug screen space tracing

float weight = 1.0;
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
lighting.specularTransmitted = hit.debugOutput;
lighting.specularTransmitted = primaryHit.debugOutput;
lighting.specularReflected = hit.debugOutput;
lighting.specularReflected = primaryHit.debugOutput;
return lighting;
}
#endif

// -------------------------------
// Resolve weight and color
// -------------------------------
float2 weightNDC = clamp(min(hit.positionNDC, 1 - hit.positionNDC) * invScreenWeightDistance, 0, 1);
float2 weightNDC = clamp(min(primaryHit.positionNDC, 1 - primaryHit.positionNDC) * invScreenWeightDistance, 0, 1);
float hitDeviceDepth = LOAD_TEXTURE2D_LOD(_DepthPyramidTexture, hit.positionSS, 0).r;
float hitDeviceDepth = LOAD_TEXTURE2D_LOD(_DepthPyramidTexture, primaryHit.positionSS, 0).r;
float hitLinearDepth = LinearEyeDepth(hitDeviceDepth, _ZBufferParams);
// Exit if texel is out of color buffer

float3 preLD = SAMPLE_TEXTURE2D_LOD(
_ColorPyramidTexture,
s_trilinear_clamp_sampler,
hit.positionNDC * _ColorPyramidScale.xy,
primaryHit.positionNDC * _ColorPyramidScale.xy,
if (hitBlending > 0)
{
float3 preLD2 = SAMPLE_TEXTURE2D_LOD(
_ColorPyramidTexture,
s_trilinear_clamp_sampler,
secondaryHit.positionNDC * _ColorPyramidScale.xy,
mipLevel
).rgb;
preLD = preLD * (1.0 - hitBlending) + preLD2 * hitBlending;
}
// We use specularFGD as an approximation of the fresnel effect (that also handle smoothness)
float3 F = preLightData.specularFGD;

正在加载...
取消
保存