Positional data in pixel shader

I’m new to using OpenGL ES 2.0 pixel shaders on iOS.

I’m rendering a full screen quad using 4 vertices and I want to obtain the interpolated positional vertex data in the pixel shader.

Can someone explain how this is done, I’ve been searching for answers all night without success :frowning:

Try using varying data type in shaders, so that you can pass interpolated values from vertex to fragment shader.
Let me know whether it works or not.

You can take uniform variable in fragment shader and assign that to gl_Fragcolor. Now in your draw function loop, change your local variable as per your color requirement and assign value of this local variable to uniform variable.

The interpolated positional vertex data is not available in the pixel shader for OpenGL ES 2.0, as you discovered.

One solution is to use the texture coordinates instead because they are available in the pixel/fragment shader in interpolated form. This is what is normally used to sample textures, such as gsvTexCoord in this example:

gl_FragColor = texture2D(gsuTexture, gsvTexCoord);

The only real difference is that gsvTexCoord has a limited range of only 0.0 to 1.0.

Regards, Clay

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