Sign in to follow this  

Fragment Height in GLSL

This topic is 4310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to have a height for a fragment? What I would like to do is based on the vertex height have the ability to color my fragments based on what the height is in relation to the vertex. Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave
Calculate the height for the vertex in the VS and pass it through to the fragment shader, i think the height will be interpolated for the pixels.

Dave


Thanks for the reply. I understand that, but do I need to multiply it by anything?

or can I do just this


varying vec3 vertex;

void main()
{
vertex = vec3(gl_Vertex);
}




So with the interpolated value lets say vertex height starts 0 and ends at 1.0 then each fragment will be however many 1 / (how many texels per polygon e.g. 256) for each height value?

Share this post


Link to post
Share on other sites
If you just want the height, why don't you just pass the height? If the z coord of the vertex position denotes height, in the vertex shader:

varying float height;

void main()
{
height = gl_Vertex.z;
}


The interpolation is not always linear, mind. I think it is linear taking hte perspective projection into account, if you see what I mean. That is if the quad is parallel to your screen, you can take the interpolation to be linear. Do some tests to be sure though.

Share this post


Link to post
Share on other sites

This topic is 4310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this