# Thread: Pixel Position world space

1. ## 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.

cheers.

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

3. Simple solution, texture coordinates.

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

5. 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.

6. Originally Posted by thokra
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;

if(value<0.5)
{

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

else
{
gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);
}

But it does not work, I am missing something.

7. Originally Posted by thokra
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.
I think I start to understand now, I will try soon.

thanks.

8. it works! thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•