Six Grass Rendering Techniques in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ค. 2024
  • Ever wanted to add grass to your game? There are many ways of implementing grass in Unity, and while one technique could be great at one thing, it might suck at another. In this video, I'll go over six grass rendering methods and explore what makes each one great in certain situations.
    Made with Unity 2021.3.0f1 and URP 12.1.6.
    ------------
    👇 Download the project on GitHub: github.com/daniel-ilett/shade...
    📰 Read this tutorial in article format instead: danielilett.com/2022-12-05-tu...
    ------------
    📚 Get a copy of my shader book here: www.dpbolvw.net/click-10074214...
    ✨ Grab Snapshot Shaders Pro here: assetstore.unity.com/packages...
    ------------
    🎨 Grass Variations by RBG Illustrations: sketchfab.com/3d-models/grass...
    🎨 Ground 048 on ambientCG: ambientcg.com/view?id=Ground048
    🎨 Tree by randum: sketchfab.com/3d-models/tree-...
    ------------
    💬 Join the Discord: / discord
    💖 Support me on Patreon: www.patreon.com/danielilett?f...
    ☕ Or throw me a one-off coffee on Ko-fi: ko-fi.com/danielilett
    ------------
    00:00 Introduction
    01:22 Method 1: Mesh Grass
    04:33 Method 2: Geometry & Tessellation Grass
    07:32 Method 3: Procedural Rendering & Compute Shaders
    15:30 Method 4: Billboarding
    17:54 Method 5: Terrains
    19:39 Method 6: Impostors
    #gamedev #shaders #madewithunity
  • เกม

ความคิดเห็น • 63

  • @LowLevelLemmy
    @LowLevelLemmy ปีที่แล้ว +7

    The king returns. You and Ben Cloward are Shader geniuses

    • @danielilett
      @danielilett  ปีที่แล้ว +2

      Ben Cloward is amazing, right? Lots of in-depth videos!

  • @CodexHere
    @CodexHere ปีที่แล้ว +5

    EXCELLENT video! This is quality right here!
    It would have been cool to see the mixing of mesh, imposters, and billboard at different LODs implemented just to fully observe the effects - but what you DID show was also very helpful!
    Thanks for this, gonna look at your other videos now!

  • @shane3158
    @shane3158 ปีที่แล้ว +1

    Thanks Daniel, this is exactly what I needed, love the detail you go into, thank you for creating this content!

  • @colecancode
    @colecancode ปีที่แล้ว +1

    thank you for your amazing grass assets, it was just what I was looking for. It's also really fun to play around with the settings

  • @FrankGennari
    @FrankGennari ปีที่แล้ว +5

    This is a great overview of grass rendering methods. It's important to note that you can combine multiple solutions for near vs. far grass, but you have to get the colors/lighting to match and make the transition incremental. I like to use a pixel dissolve effect when transitioning from geometry to billboards, or when switching between imposter images at different angles.
    The approach I used that works well is to generate some number of square grass patches (I use 32) and randomly select from one of these for each terrain tile/chunk. Then these are drawn across the terrain using hardware instancing. I also generated several lower LODs by recursively finding the nearest pair of grass blades and merging them into a new blade with the sum of the surface area, the average of the color, and the average of the height. Each LOD is half the size, and they're all stored in the same buffer. Then for 4 different LODs you have up to 32*4 draw calls for each mesh of each LOD.
    In addition, I use hardware tessellation shaders to curve the grass blades when close to the player and apply a wind effect that scales with distance from the base to the tip so that the ends move more in the wind. This system can support a field of grass that stretches to the horizon at about 300 FPS on a GTX 1070.

    • @danielilett
      @danielilett  ปีที่แล้ว +1

      Your approach sounds super interesting! And of course, mixing approaches at different distances is crucial if you want great-looking grass with high performance. As it turns out I also have a GTX 1070 so 300FPS sounds pretty good to me!

  • @sangchad9161
    @sangchad9161 ปีที่แล้ว +2

    Great tutorial

  • @Chris-jo1zr
    @Chris-jo1zr ปีที่แล้ว +2

    You are a God send. I have your book and was about to look at the computer shader grass section for a mobile VR project, but now here's a lovely video on multiple ways!

    • @danielilett
      @danielilett  ปีที่แล้ว +1

      Glad I accidentally got the timing right for you :D I actually get a surprising number of comments asking about VR stuff, although I don't have a headset myself. Maybe it's worth me grabbing one, so I can at least see how well my shaders work in VR!

    • @Chris-jo1zr
      @Chris-jo1zr ปีที่แล้ว

      @@danielilett I think there's a lot of VR development in the UK and US running with Quest 2 and Pico Neo 3/4 but there's also not a lot of top tier people working on it, they understandably gravitate to the bigger games companies. So there's still a lot of professional work to be had in VR.
      What would you consider the best method for grass on a Quest 2 device?

    • @danielilett
      @danielilett  ปีที่แล้ว

      Out of these six, I would assume the procedural rendering approach would work fairly well on a Quest 2, but I really don't know that for sure.

    • @Chris-jo1zr
      @Chris-jo1zr ปีที่แล้ว

      @@danielilett Thanks Dan, I've come to that Conclusion myself also, I was attempting to implement the Compute Shader method (just to be all fancy) but realised it's likely really pointless for the project at hand.
      I did notice that the RenderParams Class used in the C# script appears to only be available in the 2021 Unity version, so my 2020 VR testing project was doomed to fail regardless.

  • @samivanni3866
    @samivanni3866 3 หลายเดือนก่อน +1

    This helped me a lot. Thank you for the video!

  • @Goeki_4
    @Goeki_4 ปีที่แล้ว

    OMG IM GLAD TO FOUND THIS CHANNEL

  • @AlexandreCoulonOldChannel
    @AlexandreCoulonOldChannel ปีที่แล้ว +1

    Very clear and informative, I took some notes ! thanks :)

  • @subhradipmajumder4204
    @subhradipmajumder4204 ปีที่แล้ว +1

    Thank You brother again for teaching me something new :) , Keep posting

  • @StefanRIZEA_
    @StefanRIZEA_ ปีที่แล้ว +1

    Great video. Keep it up!

  • @ayayrawnnn9725
    @ayayrawnnn9725 ปีที่แล้ว +5

    Such an amazing tutorial. The procedural geometry way I can only get to render in one eye though for VR, trying to search how to fix this, seems ill need to add lines to the shader

  • @SincerestSawa
    @SincerestSawa ปีที่แล้ว +1

    this was a great video, instructional enough for me to be able to choose what style would work for a world im making, spent days making multiple different meshes but painting the terrain with a grass texture worked great

    • @danielilett
      @danielilett  ปีที่แล้ว +2

      Glad it helped - best of luck with your game!

  • @samhblackmore
    @samhblackmore 5 หลายเดือนก่อน +1

    TIL you can enter functions into the transform position inspector!

  • @atomictraveller
    @atomictraveller หลายเดือนก่อน

    i love grass, man. i work in win32 so not the same, i was figuring on using shells next time i want grass, and an abstraction (several layers of squares like uninterpolated wind positions). i don't know if i missed it, a good tip i herd was to mix the terrain normal for specular at a distance to reduce aliasing. anyway, here's hoping some folks out there get the good word about the abstract.

  • @hulponot29
    @hulponot29 ปีที่แล้ว +2

    Cool video, I have known something new!
    What about others Terrain grass methods? (Instanced mesh,Grass mesh). I think they are somehow related to batching approach?
    Thanks for your work!

  • @Memeieli
    @Memeieli ปีที่แล้ว +1

    Great tutorial. is there a chance you could cover Mesh Shaders sometime? (Mesh shaders/meshlets?)

  • @Gandalf642
    @Gandalf642 ปีที่แล้ว

    Many thanks for this video. I tried to use the procedural instancing (with compute shader). That works perfectly on pc but the grass is not displayed in a PS5 build, an idea ?

  • @day_that_i_die9854
    @day_that_i_die9854 ปีที่แล้ว

    Amazing content! Unfortunately procedural+compute grass crashes Unity 2021 and 2022 without console errors

  • @slurpiks
    @slurpiks 10 หลายเดือนก่อน

    how did you put everything from the winrar file? like grass ground and others
    ?

  • @mallugamedev4951
    @mallugamedev4951 ปีที่แล้ว +1

    which one is the best for a mobile game with dense grass ( which aproch is the most optimized ) ?

    • @danielilett
      @danielilett  ปีที่แล้ว

      I wouldn't recommend geometry shaders for this, because they are not well-supported on mobile.
      If you don't mind the visuals being slightly rougher, terrains with grass are most likely the most efficient. If you want something that looks a bit better, the procedural rendering approach is still very optimised. That's probably my favourite technique.

  • @TheMrPawolo
    @TheMrPawolo ปีที่แล้ว +1

    WOW! Where I can read more about "math functions" that you typed in the transform component in 3:50? I never heard about it! :O

    • @danielilett
      @danielilett  ปีที่แล้ว +2

      Yeah I learned about them pretty recently too! Here's the documentation page that goes over them: docs.unity3d.com/Manual/EditingValueProperties.html

  • @colecancode
    @colecancode ปีที่แล้ว

    when changing the max tesselation distance, it works for the most part but still leaves singular grass blades outside of this max distance. How can i fix it so that no grass whatsoever appears outside of this max tesselation distance?

  • @bistek2769
    @bistek2769 11 หลายเดือนก่อน

    I tried to run the procedural rendering with compute shaders one but I can't make it work. Console is throwing "out of range" error constantly. Maybe someone knows what's happening?

  • @Massive-3D
    @Massive-3D ปีที่แล้ว +2

    Hey awesome video. The audio is quiet though, sound far away

    • @danielilett
      @danielilett  ปีที่แล้ว +1

      The acoustics in my room are pretty terrible which makes it difficult to get the audio balance right. I think I've worked out a solution for future videos, but it's a shame that I can't go back and fix the audio for past videos!

  • @GiMiat
    @GiMiat ปีที่แล้ว

    How about DrawMeshInstanced vs the DrawProcedural, they seem similar, is there any performance difference?

    • @danielilett
      @danielilett  ปีที่แล้ว

      While making this video I did see tons of similar looking methods like those which seemed to do very similar things and just differ by what paramaters they accept. Not sure about the performance difference, but I'm assuming it's small.

  • @soleia9461
    @soleia9461 ปีที่แล้ว +1

    Can you please do fur shader? thank you

  • @plainshades
    @plainshades ปีที่แล้ว

    Can I get your book even if I wish to specifically learn the Shader Graph only? I've always found shader code intimidating.

    • @danielilett
      @danielilett  ปีที่แล้ว

      Most of the effects in the book include Shader Graph versions. There are a few things that Shader Graph still can't do, but I made sure to cover it where possible!

  • @Berndr
    @Berndr หลายเดือนก่อน

    this was so informative thanks, just curious what grass do they use in top-down games, I noticed that recent top-down city builder games such as Manor Lords or Farthest Frontier are literally littered in the grass , how is that not slowing the performance? in the past top-down games never had any actual grass just texture ...

    • @danielilett
      @danielilett  หลายเดือนก่อน +1

      I don't know for sure which techniques they used, but I would strongly assume it involves a lot of GPU instancing. After all, I'm just some guy on the internet and I could easily get a couple million grass blades all on screen at once, so a dev team with a lot more resources (and a few optimisations to thin out the grass when further away) should be able to litter the ground with grass without destroying performance.

    • @Berndr
      @Berndr หลายเดือนก่อน

      @@danielilett Thank yuo for the reply, I was only wondering because in top-down games you see a very large area of the terrain and yet they had foliage all over it whilst in first-person view it is easy to cool down the grass far away ... apparently, Manor lord is made by one guy ...

  • @aliengarden
    @aliengarden ปีที่แล้ว

    What about Graphics.DrawMeshInstanced ?

  • @frankyonng1710
    @frankyonng1710 ปีที่แล้ว

    Dose Billboard increase the overdraw?

    • @danielilett
      @danielilett  ปีที่แล้ว

      If you're using an opaque material (even if it uses alpha clipping), then it shouldn't do. If you're using a transparent material, then it will - so it's definitely something to be careful of!

  • @vrictor
    @vrictor ปีที่แล้ว +1

    HELP pls, when using the geometry grass method and upgrading it to unity 2022.2.18 for some reason the grass displaces to a diferent location than the objects one. for example if the object with the material is at X=0 and Y=0 the grass is at X=0 Y=0 but if I move the object to X=2 Y=0 the grass moves to X=4 Y=0 and so on and on. this makes the grass unusable because when the objects get a little bit away from the center of the scene (lets say 12 meters) the grass moves super away (24 meters) because for some reason it multiplies the distance by two in all axis. if someone can tell my why it does this ill be veryu thankfull :D
    ps: sorry for writing a full byble paragraph xd

    • @alpergiray1783
      @alpergiray1783 5 หลายเดือนก่อน

      Hey! Did you manage to solve the problem?

    • @vrictor
      @vrictor 5 หลายเดือนก่อน

      @@alpergiray1783 i dont use Unity anymore bc of the polemic that happened and also nevera found the soultion. Apparently its a bug that the versión hada or smthn because no one was able to solve It 🫠

  • @omelette2718
    @omelette2718 4 หลายเดือนก่อน

    You should really lower the sound of music in your video. Great video though!

  • @mochou-p
    @mochou-p ปีที่แล้ว +1

    19:39 XD

  • @armyofchickens6062
    @armyofchickens6062 9 หลายเดือนก่อน

    how can you render grass in a 2D game using a single blade of grass and populating the world with it?

  • @matrixdev
    @matrixdev ปีที่แล้ว

    nice video but music is way to loud...

  • @stevphiericardo2790
    @stevphiericardo2790 ปีที่แล้ว +4

    You forgot the most important grass method, called Grass blending.. It's very common in UE and easy to do that there, whil;e in Unity, good god it's so little resources regarding this matter in Unity due to these reasons "
    1. Normal blendings are expensive
    2. It's very hard to implement in Unity

    • @danielilett
      @danielilett  ปีที่แล้ว +3

      I'm interested in this, where do you suggest to find out more details about it in UE? Would be interesting to have a go at implementing it in Unity!

    • @stevphiericardo2790
      @stevphiericardo2790 ปีที่แล้ว

      @@danielilett Almost every UE stylized tutorials out there you can find, usually they don't even mention it due to how it's a built-in feature there and it can be done on the shader level pretty easily. Most likely can find this in a stylized ue videos.
      in Unity, either baking the maskmap or using secondary ortho camera, yeah, it sucks.
      And for the love of god! PLEASE MAKE A TUTORIAL FOR THIS for Unity!...

  • @majortom2405
    @majortom2405 ปีที่แล้ว

    It apears the Link to your Book doesn't work anymore

  • @carriesummers4244
    @carriesummers4244 ปีที่แล้ว

    lets
    GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

  • @rasmuspedersen4891
    @rasmuspedersen4891 ปีที่แล้ว +2

    when you misinterpret "Go touch grass":

  • @derrelecte
    @derrelecte 4 หลายเดือนก่อน +2

    The music is very annoying and hard to understand you over it.

  • @matiastemesio893
    @matiastemesio893 ปีที่แล้ว +1

    unreal engine is a way better than unity in all this grass and foliage thing as far i can see

  • @Arelias95
    @Arelias95 ปีที่แล้ว

    Using geometry shaders is a pretty poor idea