问题描述
我正在学习OpenGL图形,并且进入阴影。我正在阅读的教程告诉我将我的法线和光矢量转换到相机空间。为什么是这样?为什么不能保持协调在模型空间?
I am learning OpenGL graphics, and am getting into shadows. The tutorials that I am reading are telling me to transform my normals and light vector to camera space. Why is this? Why can't you just keep the coords in model space?
后续问题是如何处理模型转换。我找不到一个确定的答案。我目前有这个代码:
A follow up question to this is how to handle model transformations. I am unable to find a definitive answer. I currently have this code:
vec3 normCamSpace = normalize(mat3(V) * normal);"
vec3 dirToLight = (V*vec4(lightPos, 0.0)).xyz;"
float cosTheta = clamp(dot(normCamSpace, dirToLight),0,1);"
V是视图矩阵或相机矩阵。当模型在位置,旋转和缩放中变化时,我不确定如何移动或编辑光。
V is the view matrix, or the camera matrix. I am unsure how to move or edit the light when the model changes in position, rotation, and scale.
推荐答案
主要原因是,通常你的灯光位置不会在模型空间中,而是在世界空间中,但是对于照明效率来说,所有的计算都必须在一个公共空间中进行。链模型局部坐标由模型视图矩阵直接变换到视图空间中。
The main reason is, that usually your light positions will not be given in model space, but world space. However for illumination to work efficiently all calculations must happen in a common space. In your usual transformation chain, model local coordinates are transformed by the modelview matrix directly into view space
p_view = MV · p_local
因为你通常只有一个modelview矩阵,将这个steap分成类似
Since you normally have only one modelview matrix it would be cumbersome to separate this steap into something like
p_world = M · p_local
p_view = V · p_world
$ b
因为投影变换传统上是作为一个单独的步骤,视图空间是自然的公共低地,其上基于照明计算。它只是涉及到转换你的光位置从世界到视图空间,并且由于光位置不是很复杂,这是在CPU和预先转换的光位置作为着色器。
Since the projection transformation traditionally happens as a separate step, view space is the natural "common lower ground" on which illumination calculation to base on. It just involves transforming transforming your light positions from world to view space, and since light positions are not very complex, this is done on the CPU and the pretransformed light positions given as shader.
注意没有什么阻止你在世界空间中执行照明计算,或者模拟本地空间。它只是正确地转换灯的位置。
Note that nothing is stopping you from performing illumination calculations in world space, or model local space. It just takes transforming the light positions correctly.
这篇关于为什么使用相机空间而不是模型空间的法线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!