Shader Graph8-Vector

1. Three vectors

Vector is called vector or vector. Vector is more mathematical, and vector is more graphic. We use the following three Vectors the most, the red is called the Camera Vector, the blue is called the Surface Normal surface normal, and the yellow is called the Light Vector.

Each face has a normal, the normal vector is like this

 2. Open UE

Surface normal VertexNormalWS

Create a new Material, called DemoVector, and double-click to open it. Add a normal vector and modify the Preview to display the object as a cube. The node of the normal vector is called VertexNormalWS, directly connected to the Base Color to observe.

The colors corresponding to positive x, y, z normal vectors are red, green, blue, and the colors corresponding to negative x, y, z normal vectors are black.

We add a 3-channel Vector vector (0,0,1) to do the dot product with VertexNormalWS, and connect it to the Base Color.

Because (0,0,1) is vertically upward, after the normal of all faces of the cube is dotted with it, only the result of the top face is 1, so only the top face is white, and the other faces are black, and It is 0. You can try to modify the value of the 3-channel vector to see the effect.

We can also use the Mask node to make the above simpler, modify the value of Mask, and fill in 1 in the B input box.

MaskChoose here

Camera Vector camera normal

Let's take a look below, Camera Vector camera vector, Preview still chooses a cube. When we rotate the camera, the color on the cube face will change, and this color representation is the normal direction of the camera. It should be noted here that the official statement about the direction of the camera normal is the direction from the pixel to the camera.

We select the Top view, the color of the cube faces is blue, and the Bottom view is selected, and the color of the cube faces is black. Note the orientation of the lower left axis.

You can switch the view and try it yourself to understand.

https://mp.csdn.net/mp_blog/creation/editor/129989462 Here is the Fesnel effect achieved by combining DotProduct and Camera Vector.

Light Vector Light Vector

When we connect the Light Vector to the Base Color, there will be a download error, because the reflection of the material has been implemented by the engine.

Select Lit in the preview window, and the material will have a reflective effect.

3. Open Unity, create a new Shader Graph, and double-click to open it.

Normal Vector

Camera Vector

Guess you like

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