How to get depth information in UE4/Unreal material

1. Obtain a fixed depth

1. Effect

2. Nodes in UE4

3. Node principle analysis

  • ScenceDepth can sample the depth of all model surfaces, as shown in red points B and E ;
  • PixelDepth can only sample the depth of the surface of the model being drawn, as shown in the blue point B in the figure ;
  • The absolute world position can only sample the pixel points on the surface of the model being drawn, as shown in point F;
  • (Absolute world position - camera position: vector FA) * (ScenceDepth/PixelDepth: depth ratio) = vector DA;
  • Vertex C is (0, 0, 80), which sets the height of the water surface/plane;
  • camera position - point C = vector AC;
  • Vector DA + vector AC = vector CD;
  • The Mask mask takes the Z value of the vector CD, which is the yellow h value in the figure , and the depth h obtained in this way will be constant at another angle;
  • The purpose of the follow-up calculation is to make h take a value between 0-1;

2. How to obtain the depth that changes with the viewing angle

1. The effect is as shown in the figure

2. Nodes in UE4

 3. Analysis of node principle

  • DepthFade node: Simulate the fusion of transparent objects and non-transparent objects when they are in contact;
  • FadeDistance: Control the speed of fading, the smaller the distance, the faster the fading;

Guess you like

Origin blog.csdn.net/u011637323/article/details/124989952