Beginner: Implementing both colours and textures in fragment shader (for picking)
Hi all, this is my first post.
I am learning about shaders in a very piecemeal fashion so don't be surprised if I seem to not understand really obvious things.
I have to implement picking in a program (for uni) with shaders with objects that are arrays of vertices and texture co-ordinates parsed from Collada files.
I started off trying to do ray picking but I just couldn't make it work. I then decided to try colour id picking because that's what I did in my previous graphics course which didn't introduce shaders.
I always wanted to draw some axes on the screen to help with debugging but never could, I didn't really understand what the shader we were given did at the time so I didn't worry about it. But now if I want to implement colour id picking I will have to be able to draw in colour and not in textures.
I've now learned a tiny bit about shaders and tried this in my fragment shader:
varying vec2 vTexCoord;
uniform sampler2D myTexture;
void main (void)
if(gl_Color.r <= 0.01 && gl_Color.g <= 0.01 && gl_Color.b <= 0.01)
gl_FragColor = texture2D(myTexture, vTexCoord);
gl_FragColor = gl_Color;
The shader used to just have gl_FragColor = texture2D(myTexture, vTexCoord); in the main ().
In my drawing part, if not in picking mode I enable textures and colour in black, and if in picking mode I disable textures and draw in the colour id of the object.
I may have mistakes in my drawing code, but I am sure that my shader code has mistakes because my matrix handles return -1. I can't seem to find any info on the net about testing what colour you have in the shader and doing different things based on the colour. So my shader code was just a blind guess as to what might work but I can't think of any other guesses to try.
Thanks heaps if anyone can help. And/or point me to some good shader tutorials.