I've heard about this before, being a property of a forward renderer. But I thought there might be some changes to the renderer.
I wonder how this debug view is implemented, if it's just a this fragment shader you mention on every mesh.
Accessing per-pixel normals in Godot 4.0
- Edited
I think it does a fragment shader on every mesh to get the debug normal view, but I could be totally wrong about that. There was a proposal to expose other viewport modes like the debug modes for use at runtime, but I do not have a link to it and I do not think it was implemented.
Also, AFAIK those debug views are only available in debug mode. So when you ship a game in release mode they will not be there. Performance would probably also be bad trying to hack it, so that may not be a good plan.
- Edited
You didn't say from where you want to access them. GdScript, or Vertex Shader, or Fragment Shader?
Does this do what you want?
https://godotshaders.com/shader/uv-unwrap-and-normals-unwrapping-world-aligned/
- Edited
- Best Answerset by nilolo
While you can't get a normal pass from a forward renderer as far as I am aware, godot's is a depth pre-pass forward renderer, so you should be able to get a depth pass, and while the extra cost is not desirable, you could do some processing to produce a normal pass conversion from the depth pass.
Note that transparent objects don't get drawn to depth pre-pass, however that issue can be worked around by using a dithering shader instead of transparency. Further you can look into "Discontinuity Sensitive Filtering" to smooth out the dithering.
Honestly though I'm not sure it's worth the effort, might just be easier, well more performant anyways, to implement a deferred renderer plugin for godot on the source level.
- Edited
Oh, yeah, I forgot about that. You do have access to DEPTH_TEXTURE. It is relatively simple math to extract a normal from depth (and also world space position). See here, I think this is the best method.
https://wickedengine.net/2019/09/22/improved-normal-reconstruction-from-depth/
- Edited
Thank you both for your answers!
Implementing a Deferred render pipeline option for Godot would definitely be very interesting, but it's over my head for now. I've seen Bastiaan Olij mentioning in his PRs that he's working towards making this kind of customization possible.
Depth pass to normals leads to many results online, it seems to be a common problem for implementing SSAO as well.
Small addendum, the debug normal view does work in release-mode
nilolo it seems to be a common problem for implementing SSAO as well.
Sure, though 4.0 should already feature significantly improved AO compared to previous versions so not sure if it's even really worth the effort if it's about implementing better AO. Maybe, I'm just not sure.