in this video we'll make an interactive
vertex displacement effect using unities
shader graph tool we have a demo project
here of the shader graph shader and some
example game assets from the 3d game kit
if we enter play mode we can see a
sphere which we will apply a shader
based displacement effect when we hit
the spacebar of course in your game you
would assign this to some relevant game
play event in this video we'll look at
how to create this shader using the
shader graph package and integrate the
spacebar key press trigger the goal is
to help you understand how to design
effects and shader graph and interact
with them with your other c-sharp
scripts these assets are available for
free download at the link in the
description below the project contains
two shader the script that controls the
shader an example level a pre-configured
lightweight scriptable render pipeline
and an example scene for you to get
started with first let's look at how to
set up shader graph and create the
shader we first opened the package
manager and install both the lightweight
render pipeline package and the shader
graph package to setup the lightweight
render pipeline we need to create a new
pipeline asset in the project to create
the pipeline select create rendering
lightweight render pipeline asset we can
then activate this pipeline by going to
edit project settings graphics and
dragging the lightweight render pipeline
asset into the scriptable render
pipeline settings field if you're
following along with the downloaded
assets this step has already been
completed for you now that the
lightweight render pipeline is installed
we can look at creating a new shader
graph let's create a new graph in our
project by selecting create shader PBR
graph
the PBR graph allows us to create a new
material that interacts of lighting
including shadows and reflections and
has physically-based inputs once we have
created this shader we add it to a new
material and attached a material to a
sphere in our example scene to achieve
this effect we will displace the
vertices in our mesh along its normals
by changing the output position in the
PBR master output node we will displace
by using an add node on the base object
position of each vertex by adding the
normal vector to the base object
position we can see all the vertices
become extruded making the sphere appear
bigger to vary this displacement we will
multiply this normal vector displacement
semi randomly by using a simple noise
node when we click Save asset we can see
in the scene view that the sphere is now
displaced based on that simple noise
next we will fix the seams by using
object space for this simple noise
instead of using UV space and then
scroll the displacement map to create a
pulsation effect we simply add a
position node set to object to a time
node and send it to the UV input of the
simple noise node we can also use a
multiply node with the time node to vary
the speed of the scroll to control our
displacement we expose a new shader
property in our shader graph shader
properties allow us to provide inputs to
our shader via values entered in the
inspector or via our own c-sharp scripts
we will create a new vector one property
named amount and changed a reference to
underscore amount
the reference field is a string name by
which we will access and change the
displacement via script if we do not
change this it will use an
auto-generated value if the string does
not match exactly will not be able to
address our property via script we use
this amount shader property in a
multiply node with the simple noise node
before it gets multiplied with the
normal vector this allows us to scale
the noise before it's applied to the
vertex positions now we can see that the
amount variable controls how much we
displace each vertex in the mesh to
control this amount variable we have
created a c-sharp script called
displacement control and attached it to
the sphere this script controls the
underscore amount variable by
interacting with the property we created
in our material which is assigned to the
mesh renderer component we store a
reference to the mesh renderer component
in the variable mesh render and declare
new float variable displacement amount
we use a simple lerp and update function
to interpolate the displacement amount
variable to the value of 0 we then set
the shader variable underscore amount to
displacement amount this will update the
shader graphs underscore mount variable
smoothing it over time to zero we're
using unities default jump input access
which is assigned to the spacebar to set
the value of displacement amount to 1
when pressed now when we enter play mode
in the scene we can see that by pressing
the spacebar displacement amount gets
set to the value of 1 and then slowly
interpolates back to 0 to create the
adjustable glow effect you will output
to the emission in the PVR master node
let's use a Voronoi noise and multiply
it to a color node
this will create a little modulation in
the glow effect with some dark spots
then we use alert node with another
color node as the base color and use the
amount variable in the T input this will
allow us to blend between a base color
node and the Voronoi color node using
the amount variable
then we will scroll the Clos by using a
similar setup as before
we can also add a second layer of glow
for additional variation by using a
simple noise node scrolled by an
additional layer of time and multiplying
the two noise outputs together this
gives us a second layer of noise which
adds visual interest because this glow
effect is adjusted by the amount
variable in the lerp node we could see
in play mode that when we press the
spacebar the sphere will activate both
effects vertex displacement and glow and
then slowly go back to its normal state
to add a little extra touch we've also
linked up a simple particle system in
the displacement control script if you
like to experiment with these features
yourself we have provided the complete
project with all assets meshes shader an
example scene for you to download add a
link in the description below we look
forward to seeing what cool stuff you
create with it thanks for watching
you