Normal Direction Shader

法向着色器

Basic 基础Shader 着色器

Normal Direction Shader

法向着色器

This shader colors an object based on the direction of its surface Normals. Surfaces whose Normals point towards the rendering ray take Color 1, the other surfaces take Color 2.

这个着色器根据物体表面法线的方向给物体着色。法线指向渲染光线的表面采用 Color 1,其他表面采用 Color 2。

Example:

例子:

In the example above, the surface Normals for the middle ring were reversed so that they point to the rear. The Normal Direction shader was loaded into the alpha channel, with Color 2 defined as black. The middle ring will therefore be masked out of the outer and inner rings.

在上面的例子中,中间环的表面法线是反过来的,所以它们指向后面。法线方向着色器被加载到 alpha 通道中,颜色2被定义为黑色。因此,中环将被遮蔽在外环和内环之外。

Note that it’s the other way round for the reflection, where only the middle ring is seen! This is because for reflections, rendering rays are sent out from the mirror into the scene. The middle ring’s surface Normals point towards these reflection rays, hence the middle ring is reflected, whereas the Normals for the inner and outer rings face away from the reflection rays and their surfaces are not reflected. A similar effect is created by the hard shadow (which is created using raytracing, whose sample rays run from the floor to the light source producing an inverted result) in the example on the left. Hard shadows as well as area shadows show a "false" result in this example. Only soft shadows (Shadow Maps) show a "correct" result. False and correct were placed in quotes because the shaders are technically correct but the effects shown here are most often not wanted.

请注意,这是反射的另一种方式,在那里只能看到中间的圆环!这是因为对于反射,渲染光线从镜子发送到场景中。中间环的表面法线指向这些反射光线,因此中间环是反射的,而内环和外环的法线则面向反射光线,它们的表面不反射。类似的效果是通过左边例子中的硬阴影创建的(使用光线追踪创建的,其样本光线从地板运行到光源,产生一个倒置的结果)。硬阴影以及区域阴影在这个例子中显示了一个“错误”的结果。只有软阴影(阴影地图)显示一个“正确的”结果。错误和正确被放置在引号,因为着色器在技术上是正确的,但这里显示的效果往往是不想要的。