Godot 3/4 Particle Shader to Make 'Wandering' Grass With (Or Other Foliage) — Transcript
Full transcript
- 0:00good day to you all it's me again
- 0:01bringing you another episode of making
- 0:03stuff in godot 4.
- 0:05today i wanted to present the progress
- 0:07on my foliage system by using a particle
- 0:10shader a bit of a disclaimer up front it
- 0:13is far from finished i'm sure it could
- 0:15be optimized some more but since we're
- 0:18working in alpha it's probably too soon
- 0:20to worry about optimization anyway
- 0:23i am planning to put it on dropbox if
- 0:25you want to give it a try but remember
- 0:27it may be very short-lived given how
- 0:30things change from one of iteration to
- 0:33another it simply may not work
- 0:35anymore by the time you get to try it
- 0:37out okay so just saying and by the way
- 0:39in case you do try it out
- 0:42it would be a display of good manners if
- 0:44you liked the video and subscribe to the
- 0:46channel again just saying anyway to the
- 0:49point um here is something that remotely
- 0:52resembles a uh a patch of grass and if
- 0:55you grab it and move it around the scene
- 0:57it follows the shape of the terrain
- 1:00the terrain itself has no collision by
- 1:02the way it's all smoke and mirrors
- 1:04it's a flat mesh with a vertex shader on
- 1:06it and you can watch some of my previous
- 1:09videos to see how it was made now for
- 1:11demonstration purposes i am going to
- 1:13replace my grass mesh with a simple box
- 1:16mesh i'm going to set its height to
- 1:19something noticeable like 12
- 1:21and i'm going to reset all these
- 1:23parameters here on the shader so that we
- 1:25can start from a clean slate all right
- 1:29a few ground rules to begin with the
- 1:31shader is to be used on a gpu particles
- 1:353d node inside a process material the
- 1:38amount setting is kind of obvious is how
- 1:41many instances we're going to have i've
- 1:44got 10 000
- 1:45as you can see
- 1:47lifetime is how quick you want your
- 1:49particles to respawn if you set it to a
- 1:51minimum which is equivalent to 10
- 1:53milliseconds they will respawn in almost
- 1:55real time as you move the node around
- 1:57the scene i'm keeping it like this for
- 1:59demonstration but in an actual game it
- 2:01will depend on you know how vast your
- 2:04grass field is going to be and how fast
- 2:06your player is moving maybe you don't
- 2:08need to refresh the particles so quickly
- 2:11it's important to set the explosiveness
- 2:13to one and randomness to zero otherwise
- 2:16they will flicker when they refresh let
- 2:18me show you see what's going on
- 2:20so if you set explosiveness to maximum
- 2:22with zero randomness they will be drawn
- 2:25all at once and that will help you avoid
- 2:27this issue okay so
- 2:29let's look at some of the uh fundamental
- 2:32shader parameters first before we do
- 2:34anything let's make sure we have our
- 2:36height map image in this map height map
- 2:39parameter this of course should be the
- 2:41same image you're using to deform your
- 2:44terrain in the vertex shader assuming
- 2:46you want your grass to snap onto your
- 2:47terrain of course
- 2:49optionally you can put in the normal map
- 2:51of your terrain as well and you will see
- 2:52what for in just a moment next instance
- 2:55rose this is crucial because it controls
- 2:58the emission shape
- 2:59if you set the particle count to 10 000
- 3:02like i did
- 3:03it will just emit a single file row of
- 3:0610 000 particles starting from the
- 3:08emitter using this spacing parameter to
- 3:11space them out but that's not what we
- 3:12want we don't want single file we want a
- 3:15patch of grass with the emitter point in
- 3:17the center of it so we need to tell the
- 3:20shader how many times we want to divide
- 3:23this row of particles and this is
- 3:25exactly what this setting does instance
- 3:27rows
- 3:28and the rows will be offset by the same
- 3:30spacing parameter okay so if you set it
- 3:32to 100 you're going to get a hundred
- 3:35rows each with 100 particles totaling to
- 3:3810 000. so you'll get a nice square uh
- 3:41patch uh you can see what happens when i
- 3:43scroll the instance rows value uh our
- 3:46square patch is kind of morphing into a
- 3:48rectangle if i got it all the way down
- 3:50to one it would be a single row uh again
- 3:53but i want a square so i'm going to
- 3:54leave it at 100. one important thing to
- 3:56remember is that
- 3:58instance rows must be an integer
- 4:00otherwise if it's a float the particles
- 4:02will behave erratically when you move
- 4:04the node around finally terrain
- 4:06amplitude is the height value that you
- 4:09have in your terrain vertex shader in my
- 4:11case it's 100 so i've put 100 here to
- 4:14make sure that my foliage matches the
- 4:17shape of the terrain underneath
- 4:19okay so with the basic settings out of
- 4:21the way uh let's take a look at some of
- 4:23the more interesting parameters coverage
- 4:25altitude is the maximum altitude at
- 4:28which your foliage will grow it's now
- 4:31set to 20 but if i dial it in you will
- 4:34see that the particles that cover the
- 4:36higher parts the mountains uh begin to
- 4:38disappear and they're not really
- 4:39disappearing though they're just they're
- 4:41still being emitted only way off screen
- 4:44so we don't have to render them coverage
- 4:46range is the height range within which
- 4:48your grass will grow if i set it to
- 4:50something much smaller like 10 and then
- 4:53scroll the altitude up and down you'll
- 4:55see how the particles are moving up and
- 4:56down the mountain this could be useful
- 4:58when you want to have like different
- 5:00types of vegetation at different heights
- 5:02which happens in nature
- 5:04slope coverage decides on the extent to
- 5:07which the grass will grow on slopes so
- 5:09if i dial it in you'll see that the
- 5:10particles are starting to disappear from
- 5:13the areas where the slope is steeper
- 5:16clamping strength this one is
- 5:18interesting but before we make sense of
- 5:20it we need to create a clump map that is
- 5:23a map that will control where the grass
- 5:26grows within your patch the easiest way
- 5:29to go about this one is to create a
- 5:30noise texture so let's go ahead and do
- 5:32that i'll create a fast
- 5:35noise light and i'll give it a type of
- 5:37ping pong that's what i found works best
- 5:40for this purpose and i'm going to create
- 5:42a color ramp to give me some more
- 5:43control
- 5:44over the clumping so now if i play
- 5:47around with the sliders on the color
- 5:48ramp and noise frequency you'll see that
- 5:51i'm starting to get some pretty cool
- 5:52looking uh irregularities so clumping
- 5:56strength is basically the extent to
- 5:58which the clump map uh affects the
- 6:00particles it's like if you are
- 6:02increasing the contrast on the clamp map
- 6:04more or less
- 6:05now we can also orient the particles to
- 6:08the terrain normal with this checkbox
- 6:10here
- 6:11that's what we needed the normal map for
- 6:14if you remember hopefully you can see
- 6:15the effect it's not perfect because it's
- 6:17using an 8-bit normal map image to build
- 6:20the transform matrix from rgb values of
- 6:23the pixels if it was a 32-bit normal map
- 6:25it would probably be more accurate but
- 6:27still it's kind of okay you can also
- 6:30adjust the strength of the influence
- 6:32that the normal map has on the transform
- 6:34matrix
- 6:35better yet if you scroll down you'll see
- 6:38this terrain normal basis parameter with
- 6:40this you can manipulate the transform
- 6:43matrix of the normals and you can
- 6:45achieve some pretty freaky effects with
- 6:46this like if you wanted to create a
- 6:49windswept environment for example you
- 6:50could lay your grass down with the
- 6:53setting okay moving on instance position
- 6:55randomize this is going to allow us to
- 6:57make this rig look more organic as in
- 7:00more natural you can randomize the
- 7:02position of the particles we can also
- 7:05randomize their rotation like so we can
- 7:07randomize the scale of the particles by
- 7:10setting a minimum and maximum scale this
- 7:13alone will randomize their scale but we
- 7:15can further amplify the randomization
- 7:17effect with this setting instance scale
- 7:19randomize okay we can also set the scale
- 7:22of each of the three axis separately
- 7:24like if you wanted the instances to be
- 7:26taller or thicker or whatever and
- 7:28finally spacing which we discussed in
- 7:31the beginning controls the scattering of
- 7:33the individual instances and that my
- 7:35friends is it so using this shader with
- 7:38some really simple grass blades that i
- 7:40made in blender i was able to create
- 7:43these environments in qatar which
- 7:45performed quite well while arguably
- 7:47looking fairly decently in my personal
- 7:49opinion and that is before any
- 7:51optimization work has been done on godot
- 7:534 because remember this is still early
- 7:56alpha alpha 10 in this particular case
- 7:58anyway let me know what you think in the
- 8:00comments
- 8:01like the video if you enjoyed it find me
- 8:03on twitter for more frequent updates and
- 8:05i guess i'll see you in the next episode
- 8:08peace in the world
- 8:11[Music]
- 8:40[Music]
- 8:45so
- 8:51[Music]
- 9:20[Music]
- 10:27you
About this transcript
This page contains the full transcript of Godot 3/4 Particle Shader to Make 'Wandering' Grass With (Or Other Foliage) by devmar, generated from the public captions YouTube serves with the video. The transcript has 1,526 words across 223 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.