Fragment shader array uniforms not getting erased after draw call

Im working on a full lighting system for Defold game engine it uses puer opengl to draw stuff. So the actuall thing is this: The way the implementation goes is much like an observer pattern. Theres an array/vector with all the lightsources currently loaded into memory. A certain object can listen to certains light sources, by that i mean they will get their memory location and know which value is the light source(s) position, color and alike. Thing is, every object that can recieve light has its own array/vector of lights. Im implementing a way of adding/removing light sources from this array. In the way things are, when i run the game, i have one object that will listen to 4 light sources, that being a sun (directional light) and three other point light sources. When the scenes initialized the array is kinda of like this:

[0] = sun
[1] = lamp
[2] = lamp2
[3] = lamp3

This is how information is sent to the gpu, but note that directional light and point lights are separated. For point lights they all go into an array, so this is how they look in the gpu (renderdoc used):
image
then i remove lamp from the list

[0] = sun
[1] = lamp2
[2] = lamp3

but instead of the position [2] of the gpu being erased and all be 0, instead they still have the value of lamp3 :
image

i have tested the lua code the engine runs on, and it only sends data to the gpu 2 times after i removed the lamp object, in short, theres no information about lamp being passed to the gpu after it is removed from the list

after removing lamp on more time, i add it again this time it is on top of everything on the light sources array (its the last position):

Image

It’s not really an answer to your question, as I understand you are trying to change the uniform between draw calls. However, I am interested in how do you do that remove?

In case when I want to pass to shader empty values I set it to zero vector:

And as far as I understand in current openGL version only the constant value requred to for loop, so we have to sent full uniform array each time. Even if it has empty values.

where LIGHT_COUNT is define const

3 Likes

the removing only happens in lua code, i remove one of the lights from a big light source array. Then its data wont be sent to the gpu. Theres nothing being removed on the gpu, its just that i dont send it anymore, i supposed that should make the next draw call make that value 0

Not here to answer the question either but I wanting to verify something based on my observation.
So when you send the following list to the gpu

You mentioned that this is what it looks like in gpu

Now if you remove lamp3 from the list and send the list to the gpu again, I am suspecting the light_post values will still be the same like the above?

yes. Note that the sun light source is stored in a single uniform, it doesnt go within that array. I managed to solve it by clearing the uniform array myself every frame. If i do encounter performance issues, i know what to do, but for now it works.