So I have a picking shader that changes the colors of instanced items when I select them…
here is the vertex shader
#version 410
layout (location = 0) in vec3 position;
layout (location = 4) in vec4 trans1;
layout (location = 5) in vec4 trans2;
layout (location = 6) in vec4 trans3;
layout (location = 7) in vec4 trans4;
mat4 transform;
uniform mat4 projCamMat;
flat out int referenceIndex;
void main()
{
transform[0] = vec4(trans1.x, trans2.x, trans3.x, trans4.x);
transform[1] = vec4(trans1.y, trans2.y, trans3.y, trans4.y);
transform[2] = vec4(trans1.z, trans2.z, trans3.z, trans4.z);
transform[3] = vec4(trans1.w, trans2.w, trans3.w, trans4.w);
gl_Position = projCamMat * transform * vec4(position, 1.0);
referenceIndex = gl_InstanceID;
}
and here is the fragment shader
#version 410
#extension GL_EXT_gpu_shader4 : enable
flat in int referenceIndex;
out uvec3 FragColor;
uniform uint objectIndex;
void main()
{
FragColor = uvec3(objectIndex, referenceIndex, gl_PrimitiveID + 1);
}
- basically all of my objects render their indexes in the form of a color to a frame buffer and I read pixels from that.
Everything works fine on Nvidia cg compilers - when I click objects they highlight like they should… However on two ATI cards with completely updated drivers the picking shader
doesn’t work correctly - it compiles and links - yes I checked for error messages - but the picking just doesn’t work. I did some investigating and found that basically no values are
ever given to referenceIndex and objectIndex - they always contain uninitialized values…
I’m not sure but I think the problem comes from gl_InstanceID not working correctly - so my question is does anyone see anything else that might cause this problem and - if the problem is gl_InstanceID does anyone know a fix for this? By the way the compiler on the ATI cards are both GLSL 4.2