You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Figured I'd make this a discussion, because ideally I'd like to get at least some feedback before actually making a proposal. Essentially, I'm currently working on a shader for 2d geometry, but I've hit a snafu-- when I use multiple lights, and attempt to add an ambient term to the lighting, this ambient term is added multiple times (once for each light). I can't just use a CanvasModulate, because I'm trying to include ambient occlusion; however, it's impossible to have consistent ambient lighting across separate scenes, with different numbers of light sources. This is because in the source for canvas shaders, there's no actual way to only apply a certain effect to the lighting once-- it has to be applied for every single light.
I can think of several ways to fix this; the simplest would be adding light_base (the somewhat oddly named light id) as an argument to light_compute, then adding it as an available constant. I would implement this myself, but to be frank I'm not entirely confident in my ability to do it correctly; if anyone could point me in the right direction for how to add custom accessible variables to gdshaders, I'm all ears. Another way could perhaps be to include the light accumulator as a parameter, allowing for light() function calls to access the result of prior calls; I'm not quite sure how well this would work, but it would help a lot (and would line up more with the docs, right now it seems like LIGHT should be an accumulator, given that it's currently labeled as inout). A probably more complicated solution could be to allow light() to have/update varyings, which are only accessible within light(); this could allow crosstalk between light() calls, which would also solve the issue.
But yeah, that's just my (somewhat uninformed) thoughts :p
(Ideally all the stuff that I'm doing shouldn't be required at all, godot has all the systems in place to very easily make a comprehensive default 2d shader system based on the preexisting SDF and raymarching, but that's an entirely separate proposal)
As an example, here's what it should look like (with the extra lights removed to only have the one ambient term)
2024-03-21.12-09-45.mp4
And here's what it looks like with the lights added (note that they have zero influence behind the barrier, I've verified that it is the ambient term being added multiple times)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Figured I'd make this a discussion, because ideally I'd like to get at least some feedback before actually making a proposal. Essentially, I'm currently working on a shader for 2d geometry, but I've hit a snafu-- when I use multiple lights, and attempt to add an ambient term to the lighting, this ambient term is added multiple times (once for each light). I can't just use a
CanvasModulate
, because I'm trying to include ambient occlusion; however, it's impossible to have consistent ambient lighting across separate scenes, with different numbers of light sources. This is because in the source for canvas shaders, there's no actual way to only apply a certain effect to the lighting once-- it has to be applied for every single light.I can think of several ways to fix this; the simplest would be adding
light_base
(the somewhat oddly named light id) as an argument tolight_compute
, then adding it as an available constant. I would implement this myself, but to be frank I'm not entirely confident in my ability to do it correctly; if anyone could point me in the right direction for how to add custom accessible variables to gdshaders, I'm all ears. Another way could perhaps be to include the light accumulator as a parameter, allowing for light() function calls to access the result of prior calls; I'm not quite sure how well this would work, but it would help a lot (and would line up more with the docs, right now it seems likeLIGHT
should be an accumulator, given that it's currently labeled as inout). A probably more complicated solution could be to allowlight()
to have/update varyings, which are only accessible withinlight()
; this could allow crosstalk betweenlight()
calls, which would also solve the issue.But yeah, that's just my (somewhat uninformed) thoughts :p
(Ideally all the stuff that I'm doing shouldn't be required at all, godot has all the systems in place to very easily make a comprehensive default 2d shader system based on the preexisting SDF and raymarching, but that's an entirely separate proposal)
As an example, here's what it should look like (with the extra lights removed to only have the one ambient term)
2024-03-21.12-09-45.mp4
And here's what it looks like with the lights added (note that they have zero influence behind the barrier, I've verified that it is the ambient term being added multiple times)
2024-03-21.12-10-29.mp4
Beta Was this translation helpful? Give feedback.
All reactions