glsl & perspective correction of varying values

核能气质少年 提交于 2019-12-02 07:58:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!