为什么我们应该在 OpenGL 管道的片段阶段使用眼空间坐标?
我目前正在编写一个小型 3D 引擎,我想知道为什么我应该在片段着色器中使用眼空间坐标。为此,我必须将相机矩阵放入统一的矩阵中,以转换眼坐标中的光位置,并使用camera_normal矩阵将光方向放入眼坐标中。
为什么每个人都使用这些坐标?我实在看不出有什么优势。
I'm currently programming a small 3D engine, and I was wondering why I should go in eye-space coordinates in the fragment shader. To do that, I have to put my camera matrix in a uniform to convert light positions in eye-coordinates, and a camera_normal matrix to put the light directions in eye-coordinates.
Why is everyone using these coordinates? I don't really see any advantage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用眼距的原因有几个:
There are several reasons eye-space is used:
您不必向着色器提供相机矩阵并在那里进行灯光位置和方向转换。实际上,这样做效率相当低,因为您对每个顶点一次又一次地对相同的数字执行相同的操作。
只需变换 CPU 端的灯光位置和方向,并将容易变换的灯光参数提供给着色器即可。然而,眼睛空间中的光照计算仍然更加简洁,特别是在涉及法线贴图的情况下。但无论如何,您都必须将所有内容转换为视空间,因为法线不会通过透视变换进行转换(尽管顶点位置可以直接转换为剪辑空间)。
You don't have to supply the camera matrix to the shader and do the light position and direction transformation there. Actually it is rather inefficient to do it that way, since you're doing the very same operations on the same numbers again and again for each vertex.
Just transform the light position and direction CPU side and supply the readily transformed light parameters to the shader. However lighting calculations are still more concise in eye space, especially if normal mapping is involved. But you've to transform everything into eyespace anyway, as normals are not transformed by the perspective transform (though the vertex positions could be transformed into clip space directly).