godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Expose the world normals to the fragment shader in spatial materials #5140

Closed FroggEater closed 2 years ago

FroggEater commented 2 years ago

Describe the project you are working on

A 3D ARPG relying on a pixel-art style with the help of custom post-processing and materials.

Describe the problem or limitation you are having in your project

I'm currently trying to implement a good way to have full edge detection without using an inverted hull method. For that purpose, I need the depth at and around the current fragment (already doable with DEPTH_TEXTURE) and the normals at and around the current fragment.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Ideally, having the normals directly accessible would save either performance or an unneeded first pass on 3D materials, and would be more accurate than reconstruction in a post-processing context.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The user would be able to sample NORMAL_TEXTURE the same way as SCREEN_TEXTURE and DEPTH_TEXTURE in fragment shaders.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I have currently found two workarounds, both with their limitations:

Is there a reason why this should be core and not an add-on in the asset library?

Mainly because it feels in line with the way existing input sampler2Ds are handled in Godot, and normals are a pretty important (in my eye) information to have.

Calinou commented 2 years ago

Duplicate of https://github.com/godotengine/godot-proposals/issues/798.

clayjohn commented 2 years ago

Also, view space normals are available in 4.0 using NORMAL_ROUGHNESS_TEXTURE