Use ShaderGraph to achieve water surface effect

First, briefly introduce what is Shader Graph

Shader Graph: Unity provides the effect that can be achieved by writing shader and connecting.

Table of contents

The initial phase

 Final effect display

Prepare

official stage

final stage


The initial phase

 Final effect display

Prepare

Without further ado, let’s get straight to the point

I am using unity 2021.3 urp

1. To create a new 3d project, you can directly select urp or select build-in and then change it to urp (I believe everyone should know it)

2. It is to prepare and arrange a scene (this is not the point, so I won’t introduce too much)

3. Create a material and add your own shaderGraph and assign the material to the prepared plane model

official stage

The water surface effect is a bit complicated, so here is a step-by-step introduction 

Open the shaderGraph we just created and start wiring

 First, change the surface type to transparent type.   If you don't change it, you can't show the depth and don't produce shadows. At the same time in urp Assest. Change as shown below

 

 The effect of interacting with opaque objects.

Scene depth - w vector of screen space position = edge where opaque objects and translucent objects intersect

Principle: The depth of the scene depth node contains transparent elements, and the w vector of the screen space position node does not contain transparent pixels to obtain the edge depth. 0 represents black and 1 represents white.

Next is the coloring is very simple 

Perform a lerp operation on the effect and color achieved above. 

 

The effect is as follows

 

Make the water move and add ripples

 renderings

 underwater twist

 Obtaining the color at the screen position is to perform lerp on the depth achieved above to achieve the final effect.

 

 

 final stage

 The general order of realization of this effect is to first make the effect of intersecting transparent objects and opaque objects according to the depth of the screen, and then attach colors to each area, and then make the wave effect according to the normal map, and then make waves. The flow effect, and finally the refraction of the bottom of the water.

A lot of nodes are used in it. If you are interested, you can check the effect and specific usage of each node on the official shaderGraph. Here are a few main nodes

scene Color Gets the color of the buffer (the color seen from the camera)

scene Depth: Get the screen depth

scene Position (raw): The cropped w vector also represents the screen depth.

 

 

Guess you like

Origin blog.csdn.net/m0_52021450/article/details/129108360