Skip to content

Commit

Permalink
feat: fixed vanilla ssr (doodlum#745)
Browse files Browse the repository at this point in the history
* feat: fixed vanilla ssr

* style: 🎨 apply clang-format changes

* fix: vr

* style: 🎨 apply clang-format changes

* chore: remove deltaUvDepthDR

---------

Co-authored-by: doodlum <doodlum@users.noreply.github.com>
  • Loading branch information
doodlum and doodlum authored Nov 14, 2024
1 parent 3acecbf commit 0269ac0
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions package/Shaders/ISReflectionsRayTracing.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ float hash(float2 p)
return frac(p.x * p.y * float2(0.5, 0.5).x);
}

float3 ViewToUVDepthHelper(float3 x, uint eyeIndex)
{
float4 newPosition = float4(x, 1.0);
float4 uv = mul(CameraProj[eyeIndex], newPosition);
uv.xyz /= uv.w;
float3 uvDepth = float3(uv.xy * float2(0.5, -0.5) + 0.5, uv.z);
uvDepth.xy = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(uvDepth.xy);
return uvDepth;
}

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
Expand Down Expand Up @@ -85,6 +95,12 @@ PS_OUTPUT main(PS_INPUT input)
float ssrPower = max(srcNormal.z >= 1e-5, srcNormal.w);
bool isSsrDisabled = ssrPower < 1e-5;

[branch] if (isSsrDisabled)
{
psout.Color = 0;
return psout;
}

# if defined(SPECMASK)
float3 color = ColorTex.Sample(ColorSampler, uvStartDR).xyz;

Expand Down Expand Up @@ -116,15 +132,14 @@ PS_OUTPUT main(PS_INPUT input)
float3 uvDepthFinish = ViewToUVDepth(vsFinish.xyz);
float3 deltaUvDepth = uvDepthFinish - uvDepthStart;

float3 uvDepthFinishDR = uvDepthStart + deltaUvDepth * (SSRParams.x * rcp(length(deltaUvDepth.xy)));
float3 uvDepthFinishDR = uvDepthStart + deltaUvDepth * SSRParams.x * rcp(length(deltaUvDepth.xy));
uvDepthFinishDR.xy = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(uvDepthFinishDR.xy);

# ifdef VR
uvStartDR.xy = FrameBuffer::GetDynamicResolutionAdjustedScreenPosition(uvDepthStart.xy);
# endif

float3 uvDepthStartDR = float3(uvStartDR, vsStart.z);
float3 deltaUvDepthDR = uvDepthFinishDR - uvDepthStartDR;

float3 uvDepthPreResultDR = uvDepthStartDR;
float3 uvDepthResultDR = float3(uvDepthStartDR.xy, depthStart);
Expand All @@ -142,7 +157,7 @@ PS_OUTPUT main(PS_INPUT input)
; // Adjust based on performance/quality tradeoff

for (; iterationIndex < maxIterations; iterationIndex++) {
float3 iterationUvDepthDR = uvDepthStartDR + (iterationIndex / (float)maxIterations) * deltaUvDepthDR;
float3 iterationUvDepthDR = ViewToUVDepthHelper(lerp(csStart.xyz, csFinish.xyz, (iterationIndex / (float)maxIterations) * SSRParams.x * rcp(length(deltaUvDepth.xy))), eyeIndex);
float3 iterationUvDepthSampleDR =
# ifdef VR
// Apply dynamic resolution adjustments and stereo UV conversions
Expand Down

0 comments on commit 0269ac0

Please sign in to comment.