-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Custom Shader: Lighting artifacts are produced just outside of the area of effect of Spotlights and Omnilights #73176
Comments
This is due to Forward Clustering. |
I think the documentation can be improved about light shaders. The issue here is that the shader is trying to get lights to affect objects well outside their respective ranges. You can see in the image in the OP that there is no overlap between the lights and the objects. The To be clear, the offending line is |
I would like to leave this open until a note is added to the documentation. We currently don't have enough information about light shaders so it is too easy to make this sort of mistake |
Ok. I was doing some more testing to correct this issue in the shader that I'm working on and found that it still occurs even if I'm not using attenuation. Am I doing something wrong? Is this expected behavior? This is my new light() function:
|
@hidemat The issue will occur if you do not multiply by If ATTENUATION is 0, Godot can choose to include or not include your light arbitrarily, and that arbitrary engine decision is what causes those clustering artifacts. That's why you need to respect ATTENUATION. |
Interesting. Ok I rewrote it to account for ATTENUATION when it is approaching 0, and that fixes the issue: |
Please let me know if I shouldn't be posting here, but I want to explain the reason why I'm trying to do this. The main purpose of me messing around with the attenuation value is because I want invert the shadow values to create a mask that will allow me to add color to the shadows. While attempting to invert the diffuse values, I discovered the culprit of my original shader (the one I posted initially in this issue.):
I also tried doing a one-minus with the same result: Is there a correct way to invert the diffuse values? Or is just not possible? [EDIT] I think I could achieve the desired result if I could add color to the completely black (unlit) parts of the shadow. Is there a way to do that? |
@hidemat That's just not going to work the way you describe it. As long as you are using Forward+ (Clustered), you'll need to ensure that the light function has no effect once ATTENUATION reaches 0. If not, you'll need to come up with a different approach, something like...
|
You can emulate colored shadows in 4.0 by using two lights at the same position: one with shadows and with the inverted color of the shadow color you desire, and one without shadows and with the shadow color you desire. For instance, to get a white light with green shadows, place a magenta light with shadows and a green light without shadows at the exact same position. |
Is there something the godot team is already working on that should fix this issue or is it low priority ? Thanks. |
Colored per-light shadows were removed on purpose in #45023 for optimization reasons. They're unlikely to be readded, unless a way is found to do so without impacting performance when you don't use the feature. Note that per-light shadow opacity is still supported, which is useful for LOD fading of distant light shadows. Note that Godot 3.x only supported per-light tweaks of shadow color, not per-pixel colors in the shadow map itself (which is what you'd need for stained glass to cast shadows of the correct color, for instance). Per-pixel shadow colors are more flexible, but are also even more demanding than per-light shadow colors. See also godotengine/godot-proposals#3276. |
Are you referring to light projector textures (aka. light cookies)? This is already supported in Godot 4 using the Projector property in OmniLight3D and SpotLight3D. You must enable shadows on the light for it to work though. |
No i updated my post with a picture so you can better understand what is was getting to. |
Godot version
Godot 4 rc1
System information
Windows 10, Vulkan, NVIDIA GTX 1660
Issue description
It's likely that I configured something incorrectly, but I'm using a custom lighting shader and objects that are outside of the area of effect of spotlights and omnilights get lighting artifacts:

This is the shader code:
Steps to reproduce
Minimal reproduction project
CustomShaderLightingBug.zip
The text was updated successfully, but these errors were encountered: