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

Expose scene directional light data through the compositor effect callback #11264

Closed
BadMachine opened this issue Nov 29, 2024 · 5 comments
Closed

Comments

@BadMachine
Copy link

BadMachine commented Nov 29, 2024

Describe the project you are working on

Godot addon that adds realistic sky/post-processing effects.

Describe the problem or limitation you are having in your project

Scene directional light data

Currently, we can access render scene buffers using the following code:

	var render_scene_data : RenderSceneDataRD = p_render_data.get_render_scene_data()
	var scene_data_uniform_buffers: RID = render_scene_data.get_uniform_buffer();

However, this buffer lacks crucial light source data, such as directional light direction or color. This limitation forces developers to implement a workaround by manually passing the light data from the outside. Here's the an example of the process:

  1. Create a directional light.
  2. Set up a resource that creates a uniform buffer and updates it whenever the light attributes (e.g., direction, color) change.
  3. Pass this resource into your CompositorEffect and initialize a uniform set for the buffer.
  4. Use the buffer inside your compute shader.

This approach places the entire responsibility of managing light data on the developer, which is inefficient and error-prone. For a practical implementation example, you can refer to this excellent Godrays implementation

Shadow Atlases

Another critical issue is the inability to access shadowmaps (shadow atlases) within post-processing compute shaders. While the compositor hook provides access to render scene buffers and their layers:

	var render_scene_buffers : RenderSceneBuffersRD = p_render_data.get_render_scene_buffers()
	var color_image = render_scene_buffers.get_color_layer(view);
	var depth_image = render_scene_buffers.get_depth_layer(view);
	var motion_buffer = render_scene_buffers.get_velocity_texture();

Shadowmaps remain inaccessible, which severely limits advanced rendering effects. For example, it is impossible to exclude Mie scattering effects in atmospheric rendering without sampling the shadowmap:
Image

Why These Features Are Critical
Both directional light data and shadow atlas access are fundamental for modern visual effects in rendering pipelines. Without these, developers are forced to create custom, resource-intensive solutions to work around these limitations. Exposing this data directly to compositor effects would:

  • Simplify workflows.
  • Enhance rendering performance.
  • Enable higher fidelity visual effects like accurate atmospheric scattering, godrays, and shadow-based post-processing.

By addressing these issues, Godot’s rendering pipeline would become significantly more robust and developer-friendly.

I know that there is a separate PR for shader templates but as I understand its related to the gdshader only

There is also another PR with shader includes and I cant wait to finally get it, but it's not related to exposing light data.

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

Exposing Directional Light Data to Compositor Effects

Add a mechanism to directly expose directional light attributes (e.g., direction, color, and intensity) to the compositor effects. This could involve integrating the light data into the existing uniform buffers or providing a dedicated API for accessing light sources within the RenderSceneDataRD object.

Shadowmap (Shadow Atlas) Access for Post-Processing

Allow access to shadowmaps (also known as shadow atlases) within the compositor framework. This can be achieved by exposing the shadowmap textures through the RenderSceneDataRD interface, similar to how color, depth, and motion layers are currently handled.

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

Directional Light Data

 var scene_light_uniform_buffers: RID = render_scene_data.get_light_buffer();

Shadowmap (Shadow Atlas)

var shadow_atlass = render_scene_buffers.get_shadow_atlass();

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

Directional Light Data

Yes, it can be worked around with quite many lines of code :) Which as I explained above is not efficent and practically comfortable way.

Shadowmap (Shadow Atlas)

Unfortunatelly there is no option to work this around with script.

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

I assume the reason is the Compositor itself. It has been developed as solution for post processing effects.

@Calinou
Copy link
Member

Calinou commented Nov 29, 2024

@BadMachine
Copy link
Author

@Calinou
I played with my local build a bit and extended scene buffers with desired data
Image

Here is the exposed directional light buffer

RID RenderSceneDataRD::get_directional_light_buffer() const {
	return RendererRD::LightStorage::get_singleton()->get_directional_light_buffer();
}

Looks like kinda easy to implement.

But since there is a separate light_storage class, im not sure if it could be a part of the render_scene_data

@BastiaanOlij
Copy link

@BadMachine it was always my intention to expose more of the buffers used during rendering to compositor effects. #94193 is a first step in that process so you can include the structures Godot uses internally. Exposing the RIDs of the buffers is a next step.

@BadMachine
Copy link
Author

BadMachine commented Dec 3, 2024

@BastiaanOlij
Thank you for your reply.
Im kinda ready to close the proposal :) But before doing it, is there any ETA on the feature? I mean at least we know that "shader includes" is a feature planned for 4.4, but what about buffer RIDs?

@BastiaanOlij
Copy link

@BastiaanOlij Thank you for your reply. Im kinda ready to close the proposal :) But before doing it, is there any ETA on the feature? I mean at least we know that "shader includes" is a feature planned for 4.4, but what about buffer RIDs?

Hard to say at this point in time, my focus currently is on a few XR tasks so it's a question of when I find a bit of free time to take the next steps (and that will first be rebasing and touching up the custom templates work). Right now I'm waiting for the built-in includes PR to be merged, it's a royal PITA to maintain multiple PRs that are all dependent on another PR.

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

No branches or pull requests

3 participants