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.

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 on other sites
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 on other sites
Any value calculated in the vertex shader that is passed on to the frag shader is interpolated for each fragment

Share on other sites
Quote:
 Original post by DaveCalculate 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 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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632995
• Total Posts
3009771
• Who's Online (See full list)

There are no registered users currently online

×