Search Unity

vertex program respecting multiple influences (vegetation / wind / forces)

Discussion in 'Shaders' started by AlwaysSunny, Oct 8, 2017.

  1. AlwaysSunny

    AlwaysSunny

    Joined:
    Sep 15, 2011
    Posts:
    260
    Ten or twenty shelved projects ago, I kitbashed a vegetation shader which took origin, radius, and strength parameters. In addition to the standard veggie "wind" effect, properly colored verts were also pushed or pulled around this origin.

    I'd like to build a vertex program which can respect multiple forces simultaneously, but quite frankly I'm clueless about where to begin. GPU lore is still very much arcane to me.

    What came to mind was a (CPU) vector field. But to sample values from that field and give them to my shader, wouldn't each veggie need its own instance of the veggie material? That seems like a non-starter right there.

    Hopefully I'm just not thinking it through properly... Can I somehow shift the burden to the GPU? In a way that would offer the same freedoms I'd expect from a CPU-based vector field?

    It's worth noting that this would be a key feature of this project's presentation, and thus worth spending a handful of milliseconds to achieve. Also, these veggies will be independent of Unity's terrain / vegetation system.

    My humble thanks for any advice,
     
    Last edited: Oct 9, 2017
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Pack the extra data into uv's along with whatever else you need. Set the values on one big vegetation mesh as needed. Chunk to whatever mesh size makes sense for performance.
     
    AlwaysSunny likes this.
  3. AlwaysSunny

    AlwaysSunny

    Joined:
    Sep 15, 2011
    Posts:
    260
    That's a great thought to pack displacement into uv2. Shame it's CPU heavy, but the chunking idea will make that viable.

    I hadn't considered combining meshes representing different veggies. Now that you mention it, Unity's veggies do that under the hood w/ atlases. It'll be a big pain to set up, but that's a smart plan.

    The project proposal involves per-frame changes to all veggie instances, (timelapsed growth & decay, status effects, etc) and yet I'm sure it'll still be worthwhile to combine meshes each frame. Chunking might present even more opportunities to reduce loops.

    I sincerely appreciate the advice!
    CPU to the rescue!

    Further input welcome,