Can I add behaviour to the light pass in shaders without rewriting it entirely?

Godot Version

4.3

Question

I’m trying to make a shader that calculates values before and after the light() pass. The idea is to be able to calculate how much the object’s color changed based on the lighting pass in order to calculate exposure*. The thing is that in order to do this I’d have to calculate the value before, which sounds doable in the fragment() function, but calculating the change AFTER the light() function has ran has me stumped.
Is there a way to wrap the light() function inside another function in order to save the ALBEDO and other values before and after the pass?

(*) Many people have suggested raycasting from light sources to the object surface and similar solutions. The idea is for the object to calculate this on itself, instead of depending on every light source (which could potentially be too many) to raycast to several parts of its mesh.

1 Like

I’m not aware of a way to do that. The light() function is injected in the light_compute() function of the final shader here godot/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl at master · godotengine/godot · GitHub which is called after the fragment() function in the final shader is added: The fragment() is added here godot/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl at master · godotengine/godot · GitHub and light_compute() is called here godot/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl at master · godotengine/godot · GitHub