为什么我们应该在OpenGL流水线的片段阶段进入眼睛空间坐标? [英] why should we go in eye-space coordinates during fragment stage in the OpenGL pipeline?

查看:416
本文介绍了为什么我们应该在OpenGL流水线的片段阶段进入眼睛空间坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个小型3D引擎,我想知道为什么我应该在片段着色器中进入眼睛空间坐标。要做到这一点,我必须把我的相机矩阵放在一个统一的坐标中来转换光线位置,并使用camera_normal矩阵将光线方向放在眼睛坐标中。
为什么每个人都使用这些坐标?我真的没有看到任何优势,所以如果你能帮我理解这个选择,我会很感激。
Thanks:)

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, so if you could help me understand this choice, I'd be grateful. Thanks :)

推荐答案

使用眼睛空间有几个原因:

There are several reasons eye-space is used:


  1. 这很方便。它是一个存在的明确定义的空间,也是你在转换位置的过程中计算的一个空间。

  2. 它具有与世界空间相同的尺寸,但没有问题世界空间确实。眼睛的空间总是(相对)接近零(因为眼睛在0),所以这是一个明确的变换矩阵的合理空间。比例很重要,因为您可以提供在世界空间中计算的距离(如光衰减项)。距离在眼睛空间中不会改变。

  3. 无论如何,您都需要将其转换为线性空间。在非投影空间这样的非线性空间中进行照明,特别是在缩放时,会非常棘手。所以你必须在某种线性空间中提供法线和位置,所以它可能就是眼睛空间。

  4. 它需要最少的变换。眼部空间就是投影变换之前的空间。如果您必须逆向转换为线性空间(例如,延迟渲染),则眼图空间是需要最少操作的眼睛空间。

  1. It's convenient. It's a well-defined space that exists, and one that you compute on the way to transforming positions anyway.
  2. It has the same scale as world space, but doesn't have the problems world space does. Eye space is always (relatively) close to zero (since the eye is at 0), so it's a reasonable space for having an explicit transform matrix for. The scale is important, because you can provide distances (like the light attenuation terms) that are computed in world space. Distances don't change in eye space.
  3. You need to transform it into a linear space anyway. Doing lighting, particularly with attentuation, in a non-linear space like post-projection spaces is... tricky. So you would have to provide normals and positions in some kind of linear space, so it may as well be eye space.
  4. It requires the fewest transforms. Eye space is the space right before the projection transform. If you have to reverse-transform to a linear space (deferred rendering, for example), eye space is the one that requires the fewest operations.

这篇关于为什么我们应该在OpenGL流水线的片段阶段进入眼睛空间坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆