简体   繁体   English

SceneKit 球体法线似乎随着相机移动而改变?

[英]SceneKit sphere normals appear to change as the camera moves?

The normals of an SCNSphere in the following example appear to change as the camera rotates, which doesn't seem right and suggests I'm misunderstanding something fundamental.以下示例中的SCNSphere的法线似乎会随着相机的旋转而变化,这似乎并不正确,表明我误解了一些基本的东西。

In a scene with cylinders placed to highlight the x, y, and z axis (colored red, green, and blue respectively) and sphere with unit radius and the following custom fragment shader modifier:在放置圆柱体以突出显示 x、y 和 z 轴(分别为红色、绿色和蓝色)和具有单位半径的球体和以下自定义片段着色器修改器的场景中:

_output.color.rgb = _surface.normal;

a camera at position (0, 0, 10) (ie along the z-axis) renders the following: position (0, 0, 10) (即沿 z 轴)的相机呈现以下内容:

在此处输入图像描述

This looks right, since normals projecting outward at the x, y, and z axes are red, green, and blue respectively, with the expected gradations throughout.这看起来是对的,因为在 x、y 和 z 轴上向外突出的法线分别是红色、绿色和蓝色,并且始终具有预期的渐变。 But, if we were to then rotate the camera to position (10, 0, 0) (ie along the x axis), this is the rendered scene:但是,如果我们将相机旋转到 position (10, 0, 0) (即沿 x 轴),这是渲染场景:

在此处输入图像描述

which suggests that the normals have changed, as the gradation is no longer corresponds the expected directions in the coordinate space (in fact, this color pattern holds for any rotation of the camera).这表明法线已经改变,因为渐变不再对应于坐标空间中的预期方向(事实上,这种颜色模式适用于相机的任何旋转)。

From the documentation :文档中:

Geometric fields (such as position and normal) are expressed in view space.几何场(如 position 和法线)在视图空间中表示。 You can use SceneKit's uniforms (such as u_inverseViewTransform) to operate in a different coordinate space, but you must convert back to view space before writing results.可以使用SceneKit的uniforms(比如u_inverseViewTransform)在不同的坐标空间进行操作,但是在写结果之前必须先转换回视图空间。

So the normal is expressed in the coordinate system of the camera, it's not in object or world space.所以法线用相机的坐标系表示,而不是在 object 或世界空间中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM