• Godot HelpProgramming
  • Is it possible, in a spatial shader's light function, to modify how ATTENUATION is calculated?

In a spatial shader's light function you get an ATTENUATION value which accounts for attenuation from both light falloff and shadows.

But the problem is this attenuation value assumes that the fragment's world position is the position I want to use for lighting calculations. But because I'm projecting a texture onto the depth buffer I want to use a position other than the fragments actual world position.

Is this possible?

Could I just write my own lighting code using just fragment() and not use the light() function at all?

Welcome to the forums @cha5m!

I'm not sure if there is a way to alter the attenuation, and I have no experience writing custom light shaders in Godot myself, but based on this Godot QA answer, you may be able to remove it by writing a custom light function and either ignoring the built-in ATTENUATION variable or by inputting your own variable instead.

Edit: Also, in Godot 4.0 attenuation is changing a bit so its more physically correct, which may also be expose more options for more control:

https://twitter.com/reduzio/status/1346475548218781699

2 years later