Summary
I added a mat2 uniform to my vertex shader. I assigned it an identity matrix so I was surprised when my mesh stopped displaying. I replaced the uniform by the literal identity mat2(vec2(1, 0), vec2(0, 1)) and the mesh displayed correctly.
So I checked with Nvidia Nsight and I found the issue.
My uniform declaration:
uniform params {
mat4 viewProj;
mat2 model;
};
My uniform data looks like this (params[0] on the GPU):
Address Data
0x00000000 0.00250 0.00000 0.00000 0.00000
0x00000010 0.00000 0.00333 0.00000 0.00000
0x00000020 0.00000 0.00000 -0.00100 0.00000
0x00000030 0.00000 0.00000 0.00150 1.00000
0x00000040 1.00000 0.00000 0.00000 1.00000
0x00000050 0.00000 0.00000 0.00000 0.00000
The generated vertex shader tries to initialize the mat2 like this:
mat2(params[4].xy, params[5].xy)
According to the data it should be:
mat2(params[4].xy, params[4].zw)
Test case
https://github.com/Ohmnivore/battle/tree/5c88e270fef19618425dbfa82b6217bc87c7dafc
Overview (the project only has two source files):
- Shader code in
code/shaders.glsl
- Uniforms applied in
code/BattleApp.cc (BattleApp::OnRunning):
// Update parameters
this->mainVSParams.viewProj = viewProj;
this->mainVSParams.model = glm::mat2();
this->mainDrawState.FSTexture[MainShader::tex] = this->texBG3;
// Render
Gfx::ApplyDrawState(this->mainDrawState);
Gfx::ApplyUniformBlock(this->mainVSParams);
Gfx::Draw(0);
Generated files
Summary
I added a
mat2uniform to my vertex shader. I assigned it an identity matrix so I was surprised when my mesh stopped displaying. I replaced the uniform by the literal identitymat2(vec2(1, 0), vec2(0, 1))and the mesh displayed correctly.So I checked with Nvidia Nsight and I found the issue.
My uniform declaration:
My uniform data looks like this (
params[0]on the GPU):The generated vertex shader tries to initialize the
mat2like this:mat2(params[4].xy, params[5].xy)According to the data it should be:
mat2(params[4].xy, params[4].zw)Test case
https://github.com/Ohmnivore/battle/tree/5c88e270fef19618425dbfa82b6217bc87c7dafc
Overview (the project only has two source files):
code/shaders.glslcode/BattleApp.cc(BattleApp::OnRunning):Generated files