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

PostProcessingUtils: Add method for normal reconstruction. #29703

Merged
merged 3 commits into from
Oct 20, 2024

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Oct 20, 2024

Related issue: -

Description

This PR introduces PostProcessingUtils.getNormalFromDepth() which can be used to compute normals from depth. This can be useful if MRT is too costly for some reason (e.g. bandwidth restrictions).

I've updated the AO modules to use this new code path if no normal render target is available.

I want to make clear that reconstructed normals are slightly different compared to our current normal render target since it represents the actual flat surface of the geometry. This technique is inadequate for stuff like SSR since you end up with a flat-shaded, facetted look. However, it is actually the better pick for AO which is explained in https://wickedengine.net/2019/09/improved-normal-reconstruction-from-depth/comment-page-1/.

@sunag The quality difference is barely visible in webgpu_postprocessing_ao but we should keep in mind this issue when using transformedNormalView for normal texture input.

@Mugen87 Mugen87 added this to the r170 milestone Oct 20, 2024
Copy link

github-actions bot commented Oct 20, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 692.71
171.44
692.71
171.44
+0 B
+0 B
WebGPU 817.37
220.29
818.16
220.56
+791 B
+262 B
WebGPU Nodes 816.88
220.17
817.67
220.43
+791 B
+262 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.93
112.2
464.93
112.2
+0 B
+0 B
WebGPU 539.13
145.56
539.13
145.56
+0 B
+0 B
WebGPU Nodes 495.16
135.43
495.16
135.43
+0 B
+0 B

@Mugen87 Mugen87 merged commit 4d08201 into mrdoob:dev Oct 20, 2024
12 checks passed
const size = textureSize( textureLoad( depthTexture ) );
const p = ivec2( uv.mul( size ) ).toVar();

const c0 = textureLoad( depthTexture, p ).toVar();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunag It seems there is an issue when using depth textures with textureLoad() and the WebGL backend. There are no issues in WebGPU. The following shader errors occur:

ERROR: 0:149: '=' : dimension mismatch
ERROR: 0:149: 'assign' : cannot convert from 'highp 4-component vector of float' to 'highp float'

Live example: https://jsfiddle.net/1tkpy5ja/

I think this is related to the fact that texelFetch always returns a four-component vector. textureLoad is more flexibel and can also return f32 values. When I read the code correctly, this difference between GLSL and WGSL isn't honored yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant