Simulating Wind in URP (Shader Graph Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to look at how we can use shader graph to simulate wind interacting with vegetation in our scene in our boat attack game demo for the universal render pipeline we built a shader for our trees and bushes in shader graph that distorts the mesh back and forth over time causing it to appear to be blowing in the wind let's take a look at some of the basics of how we can build a shader like this using shader graph and have our tree look as though it's fluttering in the wind let's create a new shader by choosing shader pbr graph and name it vegetation let's also create a material and assign it to our tree let's start by creating our albedo and normal textures we've packed the smoothness texture and normal texture together so we'll need to use a remap node to remap from the standard zero to one values to the negative one to one value range of a normal map texture the smoothness is stored in our alpha channel so let's connect that to the smoothness value of our master node then let's connect the albedo to the master node and as our alpha value is also stored in the alpha channel of this texture let's also connect it to the alpha channel 2. so we've got our tree but it's a little bit static let's take a look at how we can use vertex information and the vertex position property of our master node to manipulate the vertices on our mesh we're going to build a series of nodes that will allow us to distort our object's position and bend it let's create a new position node and make sure it's set to object space let's then create a split node because we want to bend our meshes from the top we'll use the green channel let's connect the green channel to a new multiply node and then in our blackboard let's create a vector1 property to use as our bend strength this can end up being pretty powerful so let's divide this property by 100 before connecting it to our multiply node that way we can deal with nicer values in the inspector rather than just offsetting the values of our vertices we want to create a function to perform our bending so that the vertices offset relative to the center of the mesh and bend further the higher they are from the center so we need to remap our values let's create an add node and add one to our value then let's multiply it by itself twice then we'll connect the two multiply nodes to a subtract node this function will limit the displacement of our mesh into a spherical direction which is great for creating a bending motion for more information on how this works and other ways you can offset and bend geometry like this follow the link below next let's create a new vector2 property in our blackboard called direction which we'll use to influence which way our bend is performed let's add a multiply node and connect our vector2 and our subtracted value we'll split this result and combine it into a new vector3 we don't want our object to move along the y axis so we'll need to remap the green channel of our split node onto the blue channel of our combine node that way only the x and z positions are influenced we want to add the world position to our bend value so let's create a new position node set to world space and then connect this to an add node together with our bend value and transform this back into object space with another node then let's connect this to the vertex position of our master node now in unity we can use the bend value and wind direction setting to distort and deform our tree notice how the higher up points of the tree bend and distort further than the bottom parts thanks to the bend function we created we could animate the distortion property on our material here if we wanted to manually control how it moves however we can also use some offsets in our shader to dynamically move and distort our tree in our shader let's create a new time node and multiply the cosine time by our bend factor property now our tree and bush moves and distorts back and forth this is pretty good i'd love to have a bit more control though and only distort the leaves rather than the whole tree fortunately this mesh contains painted vertex colors which we can use as filters if we look at our vertex colors we can see that the tree trunk is mostly painted blue so if we apply the distortion to only the green and red channels we should be able to stop the trunk from moving in our shader let's split our vertex colors and combine just the red and green channels then let's create a lerp node we can use this node to blend between our object position and our result based on the vertex colors now if we look back at our tree only the leaves are moving this is looking pretty good but it's still a little bit too uniform it would be really nice if we could move and distort the leaves a bit more individually we can achieve this by passing a noise texture over the final vertex position in our shader let's create another lerp node and hook our previous slip node into it then as our time input let's create a noise texture using a gradient noise node now if we look at our tree our bend function distorts and moves each of the leaves in slightly different directions if we animate this noise texture we can simulate the look of the wind moving and passing through the leaves let's add a tiling and offset node to the graph and connect it to the uv of our gradient noise node then let's multiply the offset value by a time node in our blackboard let's also create a vector1 property called speed and connect this to the multiply node so we can control the speed of our noise let's also create another vector1 and connect it to the scale property of our noise so we can define the density now if we look at our tree the leaves are moving a lot more independently depending on how you want your wind to look you could also remove the cosine time value from the bend property in order to receive more of a constant motion we can play around with the scale noise bend and direction to get the look we desire for our scene as you can see vertex distortion vertex painting and noise textures are great ways to create bespoke animation in your materials without the need to rely on any other external components for a more advanced version of the shader and to see how some of the other shaders for the scene were built using shader graph follow the link below to download the bodatec demo for yourself thanks for watching
Info
Channel: Unity
Views: 72,432
Rating: undefined out of 5
Keywords: Unity3d, Unity, Unity Technologies, Games, Game Development, Game Dev, Game Engine, Unity game development, unity gamedev, unity game dev, unity urp, unity universal render pipeline, universal render pipeline unity, universal render pipeline, unity urp tutorial, unity grass, unity vegetation, unity urp vegetation, creating vegetation in unity, unity vegetations, unity vegetation tutorial, unity universal rp tutorial
Id: ZsoqrHHtg4I
Channel Id: undefined
Length: 6min 59sec (419 seconds)
Published: Fri Jul 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.