Skip to content

Commit

Permalink
Merge pull request #15067 from Popov72/fix-ssr-orthocam
Browse files Browse the repository at this point in the history
SSR: Fix in orthographic mode
  • Loading branch information
sebavan authored May 4, 2024
2 parents bbc0571 + 2b90a8c commit c435979
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,12 @@ export class SSRRenderingPipeline extends PostProcessRenderPipeline {
defines.push("#define SSR_DECODE_NORMAL");
}

const camera = this._cameras?.[0];

if (camera && camera.mode === Constants.ORTHOGRAPHIC_CAMERA) {
defines.push("#define ORTHOGRAPHIC_CAMERA");
}

this._ssrPostProcess?.updateEffect(defines.join("\n"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,17 @@ vec3 computeViewPosFromUVDepth(vec2 texCoord, float depth, mat4 projection, mat4

ndc.xy = texCoord * 2.0 - 1.0;
#ifdef SSRAYTRACE_RIGHT_HANDED_SCENE
ndc.z = -projection[2].z - projection[3].z / depth;
#ifdef ORTHOGRAPHIC_CAMERA
ndc.z = -projection[2].z * depth + projection[3].z;
#else
ndc.z = -projection[2].z - projection[3].z / depth;
#endif
#else
ndc.z = projection[2].z + projection[3].z / depth;
#ifdef ORTHOGRAPHIC_CAMERA
ndc.z = projection[2].z * depth + projection[3].z;
#else
ndc.z = projection[2].z + projection[3].z / depth;
#endif
#endif
ndc.w = 1.0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ void main()
#endif
float depth = texelFetch(depthSampler, ivec2(vUV * texSize), 0).r;
vec3 csPosition = computeViewPosFromUVDepth(vUV, depth, projection, invProjectionMatrix);
vec3 csViewDirection = normalize(csPosition);
#ifdef ORTHOGRAPHIC_CAMERA
vec3 csViewDirection = vec3(0., 0., 1.);
#else
vec3 csViewDirection = normalize(csPosition);
#endif

vec3 csReflectedVector = reflect(csViewDirection, csNormal);

Expand Down

0 comments on commit c435979

Please sign in to comment.