Search Unity

Grass on mesh for a mobile device

Discussion in 'General Discussion' started by Aseemy, Oct 20, 2021.

  1. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    Need to create grass on mesh (not terrain) which would run on a mobile device.
    a great example is from a game called Golf Clash


    Need the grass to cover a whole lot of area, tried with prefabs but that makes the fps unplayable. the grass wont be visible all the time but only when camera is close enough, rest of the time the ground will have a texture only.

    I tried this tutorial from Roystan https://roystan.net/articles/grass-shader.html and the result looked great but it only worked for PC and not mobile devices, it uses tessellation which is not supported by most mobile devices.

    I am not good at shaders so cant convert this tutorial to work on a mobile device. from what i understand, this shader uses tessellation to get spawn points, maybe that could be obtained in a different way.

    So looking for anyone who has ideas on how to achieve the golf clash grass look and performance.
     
  2. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    bump
    if grass on mesh is not possible i am willing to try something with terrain. the reason I wanted mesh was that i have different meshes with different physics layer and material for different types of bounces. Will that be possible with terrain?
     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    A quick google search shows that geometry shaders and tesselators require OpenGL ES 3.2 for mobile devices.

    Does it have to be done through a shader? What's the use case? Should the grass grow on a moving object?

    To draw multiple meshes you could try using DrawMeshInstanced or just prepare entire geometry.
     
  4. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    yea, i saw that and most of the devices i have to support dont have OpenGL ES 3.2

    not necessarily, use case is to create a similar game as Golf Clash, video shared in first post.

    Will try this. thanks.
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,435
    i've seen these demos, this one has github project available


    some optimization techniques,then at 1.34 running in mobile
     
    tmonestudio likes this.
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    If it doesn't need to be done dynamically, you can generate grass manually on CPU without shader, and then add some wobble shader. All without a tesselator. Or you can have a grass clump mesh and try to draw it instanced like I said.
     
  7. If you rather pay a small amount instead of developing yourself, you can check the various vegetation assets on the Asset Store too.
    For example GPU Instancer does all of these for you and only needs OpenGL ES 3.1 on mobile. Obviously these things are more generic solution, so your miles may vary and do your research if they do what you need on the way you need it.

    But in general, vegetation on mobile is extremely expensive, especially if you need big, dense lumps of it.

    What you also can try, possibly (if you don't want to buy the solution but you want to do it yourself) is the shell-method, this is mainly used for rendering fur on meshes, but I guess it can be repurpose for grass if needed. Although I'm not a great technical artist, so I don't know too much about the nitty-gritty, I'm only scratching the surface.
     
  8. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    i have that asset and many others (vegetation engine, gaia, polaris, map magic, vegetation studio etc)
    Will try them. i wanted to try without any asset first but i have no issues in buying an asset other that what i already have.


    Doesnt need to be done dynamically. doest even need to wobble, can be static.


    Thank you for this. m sure this will be of great help.
     
    Last edited: Oct 27, 2021
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    Well, it can be done, but that's procedural geometry generation. Basically, find all face sthat are facing up, optionally not occluded, optionally use specific material, then within area generated by those faces, place grass meshes and combine them all together.

    Could be a fun exercise, if you're looking to code, otherwise you might be better off buying something or paying.
     
  10. GimmyDev

    GimmyDev

    Joined:
    Oct 9, 2021
    Posts:
    160
    The grass in that game is very intriguing, most part don't seem to have complex grass, but then this:
    upload_2021-10-28_9-30-35.png
    It looks like a visual trick that fade with the camera and only for this part

    upload_2021-10-28_9-33-26.png
    This is visually confusing, but seems most likely a flat texture (with a detail texture overlay that fade with distance) and just a mesh fan around the all for silhouetting

    The bug here
    upload_2021-10-28_9-37-8.png
    Suggest the grass is just a flat quad with detail texture that fade with distance, and was culled in this example, it's no volumetric because the ball don't intersect grass blade.

    My conclusion is that they take advantage of the setting to do simple trick for the grass, the first image is probably a mesh optimized for that view that fade in and out specifically for that view, they also cut to fixed image with high quality grass close up during transition, to prime you into seeing more than there is in the game. It's just clever art direction, it's all clever fakery.
     
  11. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    I thought so too, but installing and looking at the grass in game shows that its not.


    I also later focused on the ball in grass, and the ball is covered in volumetric grass. (Looked like)
     
  12. GimmyDev

    GimmyDev

    Joined:
    Oct 9, 2021
    Posts:
    160
    Oh it's a very very agressive LOD with a very short distance that fade into the background by taking adventage of the fact it's very very short in size, so it's a wow factor trick, because the mind interpolate and fill in details at distance after being primed. It's probably not something you can generalize to, say, a full AAA foliage. Also the terrain is rather flat making it simple.

    There is many way to implement it, the faster one would probably just a mesh with all the separate blade, and using the vertex shader, that read a heightmap, to snap them to a grid, using a hash function function and a random generator suing worldspace to keep it consistent, you could also scale each blade based on distance to camera in the vertex shader. That way you get easy and performant blade and not bother with batching issue and a whole lot of management of foliage, all you have to do is to parent to an object following the camera such the whole mesh is always in front of the camera. Also sending a single mesh is faster than instancing.
     
    neginfinity likes this.