godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Access more common buffers in RenderSceneBuffersRD #10396

Open nekotogd opened 1 month ago

nekotogd commented 1 month ago

Describe the project you are working on

A post-processing outline shader using the new CompositorEffect API that uses sobel filtering on the depth and normals buffer to detect edges.

Describe the problem or limitation you are having in your project

RenderSceneBuffersRD default context doesn't provide access to the normals buffer.

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

Allow access to more buffers in the default rendering context such as the normals / roughness buffer, maybe lighting buffer, unshaded color (albedo) buffer etc.

Ideally whatever buffers we can see from the viewport debug views to be accessible, if it is possible to provide them for use with the CompositorEffect API.

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

Have RenderSceneBuffersRD provide something like:

var normals_image : RID = render_scene_buffers.get_buffer_layer(0, RenderSceneBuffersRD.NORMALS_ROUGHNESS_BUFFER)
var albedo_image : RID = render_scene_buffers.get_buffer_layer(0, RenderSceneBuffersRD.UNSHADED_BUFFER)

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

You can access the normals + roughness buffer through spatial shaders but this requires you to set up a full screen quad and it becomes really difficult to stack post-processing effects, which I believe is exactly what the CompositorEffect API aims to solve.

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

There is currently no way to access these buffers without modifying the engine, so you cannot actually build this as an add-on for the asset library.

Calinou commented 1 month ago
nekotogd commented 1 month ago

Did some snooping around, apparently I am actually able to access the normal / roughness buffer from the "forward clustered" context.

image

Calinou commented 1 month ago

I don't think the engine keeps an unshaded buffer for you to use, as Godot uses forward rendering. Such buffers are generally only available in a deferred renderer (which is planned at some point in the future).