Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

Fragment Height in GLSL

This topic is 4619 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
Advertisement
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

Share this post


Link to post
Share on other sites
Any value calculated in the vertex shader that is passed on to the frag shader is interpolated for each fragment

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!