Greetings, OpenGL Masters,
I've been using a unique shader for several years without problem and suddenly, between minors renderer modification and NVidia drivers upgrades, something went terribly wrong.
My shader is fairly complex but it can render any geometry with any material properties and light count. (I’m aware that this is not optimal but it’s very easy to maintain).
For instance, I do skinning like so:
uniform int u_DeformerCount;
in vec4 a_Weights;
in ivec4 a_Deformers;
uniform mat4 u_XFormMatrix[40]; /// Deformation matrices.
if (u_DeformerCount > 0) /// Matrix deformations.
{
mat4 l_deformer;
for (int i = 0; i < 4; ++i) /// Maximum of 4 influences per vertex.
{
l_deformer += a_Weights * u_XFormMatrix[a_Deformers];
SNIP....
}
The problem:
While everything works without a glitch when u_DeformerCount > 0, there seems to be data corruption with geometries that doesn’t have the skinning condition enabled. I’m basically getting black frames frequently, like a kid playing with the light interrupter.
Now, I can make the problem disappeared by using u_XFormMatrix[0] instead of u_XFormMatrix[a_Deformers]... I tried everything I could think of so far to fix this and I’m at the point where I could use Jedi Master’s wisdom.
- How could a part of the shader that is not used explicitly affect its output?
- Any known pitfall using uniform arrays?
PS: The major downside of a unique shader is that every uniforms needs to be set/reset every draw and I’m guessing it could be the source of my problem.