glsl & perspective correction of varying values

Go To StackoverFlow.com

1

is every varying vertex value (or in newer versions of glsl values that go "out" of a vertex shader) interpolated by the rasterizer using perspective correction? is this hardware dependant?

when clipping occurs, how are the values at the clipping vertices calculated?

I try to undo perspective correction and notice strange behaviour for polygons that are clipped and I would like to understand better what is going on behind the scenes.

2012-04-04 20:40
by user1282931


3

Pre-GL 3.0, the only way to affect perspective-correct interpolation is with a hint. Generally, glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) will activate perspective-correct interpolation on all varyings, while glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST) will generally turn it off. Note that these are driver hints and nothing more; drivers don't have to react this way.

In GLSL 1.30+ (OpenGL 3.0+), you have the ability to force each output/input to interpolate in a specific way. The interpolation qualifier smooth means perspective-correct; this is the default if you don't specify a qualifier. noperspective means... the obvious.

Clipping is always done in such a way that it will work exactly as if it weren't clipped (or near enough within hardware precision). So if a value is interpolated perspective-correctly, then the value generated for the clipped vertex must also use perspective-correct interpolation.

2012-04-04 21:00
by Nicol Bolas
oh this sounds as it would make stuff a lot easier! will try it right now! thanks! one more thing: gl_FragCoord.z is interpolated with no perspective correction applied, correct - user1282931 2012-04-04 21:29
Ads