Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR: Fix in orthographic mode #15067

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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