简体   繁体   中英

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.

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:

_output.color.rgb = _surface.normal;

a camera at position (0, 0, 10) (ie along the z-axis) renders the following:

在此处输入图像描述

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. But, if we were to then rotate the camera to position (10, 0, 0) (ie along the x axis), this is the rendered scene:

在此处输入图像描述

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. 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.

So the normal is expressed in the coordinate system of the camera, it's not in object or world space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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