This may look familiar. Half a year ago, I showed you
the prototype of a velocity buffer an idea of faking physical interaction
with foliage on a shader level. And believe me or not, to this day, people
reach out to me, asking if I could share it. The problem is that in this old video, I used
some smoke and mirrors to make it work: Only the x-axis was supported. The camera couldn't move. Only one thing could interact with foliage. But, when working on my line simulation,
I finally fixed all of this. So today, I'd like to share it with you. It's available as a package on my Github. You can take a look at the shaders,
the source code. Or just use it in your game. Let's take a look at how to use this thing. We're gonna start with this scene,
nothing special here. I'm gonna create a new material... ...with my grass shader... ...and assign it to the grass and flowers. I can tweak the wind a bit
to see how it looks like. Now to make it intractable, we'll need to
set up our velocity buffer. The best way to do that is by using a Velocity
Render Feature. But the 2D renderer does not support that
yet. So instead, I'm gonna use
a Velocity Camera component. It's more limited but should
work with any SRP. You can find more info on what these options
do in the documentation. For now, I'm just gonna focus
on the Layer Mask. Here you can choose the layers that
will interact with foliage. With that set, we can create a velocity emitter. It's basically a sprite renderer assigned
to our chosen layer. It uses a component that passes our velocity
to this material. During rendering, emitters do not show up
on the screen but instead, they write directly
to the velocity buffer. I'm gonna place this one inside of Jeff. As the mode, I'm gonna choose rigidbody2D
and use Jeff as the source. The max speed is gonna be 12, which is the
fastest that Jeff can go. Now, if I hit play, nothing happens. I need to go to my grass material and adjust
the Velocity Strength which controls how much the grass
is affected by the velocity buffer. And now it works. These emitters are just an example of how
you can interact with the buffer. You can create custom shaders that will do
something different. For instance, you could render a circle like
this and rapidly expand it to produce a shockwave. Similarly, you don't need
to use my foliage shaders. You can access the velocity buffer
from within any shader. Also, this project uses upscaling. If I disable it, you will notice that the
sprites bend smoothly. So you can use this for things other than
pixel art. Obviously, it's no match for Ori and the Blind
Forest, but still. If you, however, want to maintain the pixel-perfect
distortion without upscaling there's a dedicated set of shaders
that will do just that. And that's more or less how these things work. You can find much more detail in the documentation. This sample project is also available on Github. So you can take a look at how all of this
is set up. That being said, I'd like to announce that
I've finally become a sellout. You can now support this channel on Patreon
if you want. I've got this stupid idea. Cuz this channel costs me around 50 bucks
a month. 30 euros for Creative Cloud and 13 for Epidemic
Sounds, to be more precise. And I know that I'm asking for a lot but it would be surreal if we could actually
make this channel self-sustainable. In terms of perks, currently, there's only
one, which is early access to my videos. Let me know if there are any other perks that
you would like to see. And yeah Thanks so much for everything. Till next time!