问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/10018905/glsl-perspective-correction-of-varying-values