I am creating a shader that would deal with up to, say, 10 point lights for a scene ; but I have trouble with the "up to". Here is what I want to do :
vec3 temp = CalcPointLight(pointLights[1], norm, FragPos, viewDir, fragDiffuse, fragSpecular);
temp *= (1.0 - ShadowCalculationPointLight(FragPos, pointLights[1].position, pointLights[1].shadowCubeMap));
temp *= pointLights[1].use;
result += temp
So I have an array of structures pointLights
and I'll just do the same thing for all 10 of them, and in order to avoid branching by adding if
statements to check if the attribute use
is equal to 1 I multiply the result of the light / shadow calculation by the pointLights[1].value
.
But for some reasons it seems that if the different attributes of pointLights[1]
are not initialized, then the result
variable (which is later sent as the fragment color) is not drawn anymore, even when the temp
vector is supposed to be multiplied by 0.
To me there are two solutions to that problem : either I have to generate / write a shader for each number of point lights I have to deal with (so if I want to use up to 10 lights I'll have to write 11 different shaders) ; or I always initialize all of my 10 lights with values that will make my functions always return (0,0,0)
. For the latter solution I am not sure about how to initialize a samplerCube
such that it will contain exclusively 0s... Or is there another solution ?
EDIT : I am trying to implement the second solution but as I mentioned earlier but again, how should I initialize the samplerCube ? Should I have 6 textures of 1x1px loaded as a cubemap in the GPU memory and when I want to initialize the uniforms in my shaders, then send that "empty" cubemap sent, or is there a more fancy way of doing so (having a sampler giving only (0,0,0,1) ) ?