-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
SDFRaymarch - Read the depth value #491
Comments
Oh, my bad indeed! It seems that some WebGL Implementations do not like the
It should be fixed @gkjohnson 👍 https://codesandbox.io/s/romantic-sunset-uqhc13?file=/src/RayMarchSDFMayerial.js |
Looks like I get a correct result with float cameraNear = 0.1;
float cameraFar = 5.0;
gl_FragDepth = viewZToPerspectiveDepth(-(fragCoordZ / gl_FragCoord.w), cameraNear, cameraFar); |
Thanks @CodyJasonBennett this is great! A few changes to make still, I think. You shouldn't need to do anything with fragCoord.w since the raymarching is happening in view space (no projection matrix applied) and the w coordinate should be 1.0 anyway since it's just a full screen quad being rendered in that pass. And I believe the fragCoordZ should be set to float fragCoordZ = - 1.0;
// ...
if ( intersectsSurface ) {
fragCoordZ = - point.z;
// ...
}
// ...
gl_FragDepth = viewZToPerspectiveDepth( - fragCoordZ, cameraNear, cameraFar ); The depth visually matches a lot more precisely after these changes though more testing should still be done to make sure the type of shifting you originally showed me is addressed @RenaudRohlinger. For performance reasons in the raymarch loop, though, I would transform the scene depth from the existing depth buffer beforehand to check in the for loop. |
Awesome, I had to set |
Oops - you're right. I'd inadvertently been taking the absolute value of point.z. I've updated my notes above to specify your change. Thanks! Tough I guess we could just remove the negation in all the places, instead 😅 |
Awesome! Thank you so much for this guys, it's working perfectly 😊 |
Twitter pics please! 🙏 |
I'm looking for a way to get the correct depth value of a raymarching result. I will open an issue here as I think it could benefit other developers too.
I made an example with a post process splitting the screen into 4 sections:
1 - scene albedo
2 - raymarching albedo
3 - scene depth
4 - raymarching depth (using custom
gl_FragDepth
=length(point.xyz)
)https://codesandbox.io/s/romantic-sunset-uqhc13?file=/src/RayMarchSDFMayerial.js
The text was updated successfully, but these errors were encountered: