• Advertisement

• ### Popular Now

• 10
• 13
• 19
• 27
• 9
• Advertisement
• Advertisement
• Advertisement

# Fragment Height in GLSL

This topic is 4401 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

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

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

##### 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 this 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

##### Share on other sites

• Advertisement