Unity ShaderGraph tutorial - advanced shader (water surface, snow, digital wireframe)

1. Water surface (1)

Formula: scene depth node depth - W vector of screen space position = intersection edge of translucent object and opaque object

Principle: The depth of the scene depth node contains transparent pixels, and the screen space w vector does not contain transparent pixels.

Note: You need to turn on the Depth texture option in the UniversalRP-xxxQuality inspector panel to read the depth value.

(1) Fragment shader part:

(2) Vertex shader part

 Effect:

2. Water surface (2) 

Realization effects: water surface smoothness, underwater objects and shadow distortion effects

(1) Smoothness

Simply control the smoothness through a float parameter

 (2) Distortion effect

        Mix the color on the screen and the color of the water surface to cause a certain distortion in the screen coordinates of the rendered opaque object in the scene, and then combine it with the current color to simulate the refraction effect.

Note: To use the scence color node, you need to turn on the check mark of the opaque texture in the UniversalRP-xxxQuality inspector panel.

The scence color and the original basic color lerp already have transparency values ​​after mixing, so the original transparency does not need to be output separately.

3. snow

        The dot product of vector A and vector B, Dot (A, B) = |A|·|B|·CosQ, calculates the dot product of the snow direction A and the snow-carrying plane B, and determines whether snow can be accumulated based on the difference.

The normal vector node is the vector that converts the normal direction of the current vertex into the world space.

4. Digital wireframe

5.shader implements frame animation

 Row (row) acquisition: row = index (element index) / n

 Column (col) acquisition: col = index - (row -1) * m

Offset of U: uOffset = col * 1/m

Offset of V: ​​vOffset = 1-(row+1)/n

Replace the calculated dynamic frame rate index with the fixed value frameindex to realize dynamic playback of frame animation.

 

Guess you like

Origin blog.csdn.net/qq_29296473/article/details/132580555