Pixel Position world space

Hi guys,

I am wondering if somebody can help.
I’ve got a list of quads, few of them got a flag and in the pixel shader I need to be able
to colour the quad with a flag half red and half black (just two random colors).
Probably when I render I need to understand when I am in the middle of my quad
but I don’t know how to do it.


I think it’s the local space not the world, but the concept should be clear even with this error.

Simple solution, texture coordinates.

Using a texture was my first thought unfortunately I can’t :slight_smile: I’ve got only the vbo with vertex, normal and color.

You don’t need a texture if you only have two clearly defined colors. And you can define the coords yourself quite easily: You’ve got quads - made up of four vertices. That’s all you need to know. Define the coordinates, put them in the VBO and use the texture coordinates to decide how to color the quad.

Ok two colors was only to simplify, at the end is going to be more complex I tried to do something like that :

float value = gl_TexCoord[0].s;


gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);


gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);

But it does not work, I am missing something.

I think I start to understand now, I will try soon.


it works! thanks

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.