Search Unity

A grass shader that can be removed on collision

Discussion in 'Shaders' started by kavs, Nov 15, 2017.

  1. kavs

    kavs

    Joined:
    Jun 29, 2012
    Posts:
    25
    I'm making a project where you can clear a field by harvesting it with a collider. My solution right now is thousands of single grass blade meshes with colliders, but that is murdering my CPU as I'm sure the collision detection is expensive on all those objects. I can definitely optimize this much further, but I'm curious if there are known rendering techniques or existing shaders that might fulfil my goals.

    The system I'd need to support with this solution:
    1. Set up a field of grass blades.
    2. As a tagged collider comes into contact with a blade, remove the grass blade.
    ----Bonus: The grass cuts down to a stub and rotates in the direction of the collider's forward vector on removal (to show how it was removed)
    3. From that collision, increment a score variable.

    A modified hair shader might work for this. Some kind of polygonal generation and slicing solution might work. I'm looking into some packages in the App Store that might be able to be modified to solve this, but I'm admittedly a bit of a Unity novice and thought there might be a shader solution here.

    Any help on topics I can research is greatly appreciated! Thanks. :)
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    some ideas
    - the blade could just paint into mask texture, that then removes grass on that area in the grass shader
    - for bending grass, can do in the shader also (taking distance to player/harverster)
    - falling grass, just spawn as particles (can enable collision if needed, so they land on the ground)

    or this ready asset,
    https://www.assetstore.unity3d.com/en/#!/content/436
     
  3. SunnyChow

    SunnyChow

    Joined:
    Jun 6, 2013
    Posts:
    360
    i think you should make it one collider for a group of grass. it's really a bad idea to make each grass blade as one gameobject unless the game is about ants
     
  4. HAMILCAR_TECHNOLOGIES

    HAMILCAR_TECHNOLOGIES

    Joined:
    Dec 14, 2018
    Posts:
    12
    @mgear hey , the link not working , can you cite the name of the asset