Shader Graph6-Dot Product node (on)

1. Dot product of normal and viewing angle (dot product)

Open Unity, create a new Shader, and double-click to open it. First, let's take a look at how we can implement Dot Product using the most basic nodes without using Dot Product. Let's observe the following two pictures, the first picture is that Add is connected to Base Color, and the second picture is not connected. It is obvious that the first image is brighter and the second image is darker.

Let's modify the preview shape display and change it to a cube

After Add is connected, observe again, and you will find that when there is a face facing us, the surface is bright, and the other faces are dark.

Let's take a look at what our shader has done?

Let's first explain the View Direction node and the Normal Vector node. The orange arrow indicates View Direction, the camera logo identifies our observation position, and the green arrow indicates Normal Vector, which is the normal direction of the surface below. When we look down from the top, the direction of View Direction is consistent with the direction of Normal Vector, and the direction of View Direction in the figure below forms a certain angle with the direction of Normal Vector.

The dot product of these two vectors View Direction and Normal Vector is

Then the angle between the two vectors in Figure 1 is 0, cos0°=1, and the angle between the two vectors in Figure 2 is, for example, 60 degrees, then cos60=1/2, so the result in Figure 1 is better than that in Figure 2 The result is larger, so this explains why the result of the connection of the shader at the beginning of the article is brighter, and the result of not connecting is darker. When we choose the cube to preview, the reason why the face facing us is always brighter.

Second, use the Dot Product node to simplify the Shader, the result is the same.

Let's take a look at the situation in UE, the effect is the same as in Unity.

 

The difference from Unity here is that you need to calculate the View Direction first. The green wireframe in the figure below is the calculation of View Direction. How to calculate View Direction?

 

Look at the picture below, black represents Camera Posion, green represents Absolute World Position, according to vector subtraction black-green=orange, that is, the vector of View Direction is obtained. It was later discovered that the green wireframe can be replaced with a Camera Vector node.

Guess you like

Origin blog.csdn.net/zhuziying99/article/details/129974565