Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Interactive foliage or touch bending [wip]

Discussion in 'Works In Progress - Archive' started by larsbertram1, Jul 19, 2013.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi there,

    i just wanted to share the latest preview on the upcoming advanced foliage shader update bringing interactive foliage or touch bending next to procedural wind animation and advanced lighting:

    webplayer

    i hope you enjoy,

    lars

    $touchbending.jpg
     
  2. PROTOFACTOR_Inc

    PROTOFACTOR_Inc

    Joined:
    Nov 15, 2009
    Posts:
    4,029
    tested the web player. Looks great. How expensive CPU wise is that? Does it still use the vertex alpha for bending etc ? Great wok :)
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi rosor,

    thanks!
    touch bending should not be a killer for the cpu as it only has to handle collisions and pass some variables to the shader.
    the vertex animation (wind and touch bending) is completely done within the shader.
    in fact i can not measure any real difference between touch bending enabled and disabled.

    and yes: the shader still uses vertex colors (rgb) to control bending.

    lars
     
  4. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Definitely adds a neat bit of realism. Can't help but imaging something coming towards you in the brush, and all you see is that brush or tall grass shifting. Nice!
     
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    thanks jc,
    it definitely does ,-)

    lars
     
  6. MattCross

    MattCross

    Joined:
    Jul 20, 2013
    Posts:
    3
    Played the web player and i am impressed. I was expecting it to not run that well on my laptop but it only upped my CPU usage but 2-5%. good work what do you plan to do with this asset.
     
  7. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,785
    Pretty cool, some question
    did it work with grass too?
    how did it behave if the foliage is large foliage with large leaves (banana tree or something like that)
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi matt,

    thanks. and indeed i am still surprised how fast it runs as well… .
    the touch bending feature will be part of the next update of the advanced foliage shader suite and come to the asset store quite soon i hope.

    lars
     
  9. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi rea,
    touch bending needs single game objects, so it does not work with any plants placed using the terrain engine.
    i started this project by working on a more or less just shader based version (which also worked in conjunction with the terrain engine) but it turned out that it did not produce such convincing results (and was quite heavy as all vertices had to be calculated – no matter if touched or not).

    so touch bending does NOT work with grass placed using the built in terrain engine (and i would always recommend to use a much easier solution to apply it to such simple geometry like grass).
    but of course you can place some bigger and more complex grass models manually and apply touch bending to them.

    hmm, the blackberry plant in the web player already is pretty large compared to the player’s size.
    and if you take a whole branch of it as big "leave" it already shows how huge leaves might react.
    anyway: you can define the stiffness, secondary fluttering and duration of the touch bending for each single game object aka plant independently: not only per prefab – although it would probably make sense… next to that vertex color red and vertex color blue of your mesh controls the amount of touch bending on the different parts of the plant. so you can make some vertices stick to the ground while others will bend like crazy when touched.
    but you have to keep in mind that always all vertices will be bended, not only those which are really touched as collision is only detected per game object.

    lars
     
  10. Aspiring_Failure

    Aspiring_Failure

    Joined:
    Jan 21, 2013
    Posts:
    42
    This really impressed me. What kind of tweaks are you going to put into the user's hands? For example, will we be able to adjust /how/ the foliage bends? To what degree it bends? How long the animation lasts? Do you plan on adding some sort of layer/tag based collision detection feature so that the foliage can bend differently depending on what makes contact with it?
     
  11. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    Great stuff as usual Lars. UT should hire you to revamp the whole terrain engine :)
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi failure,

    thanks!

    the user can tweak the touch bending animation per model using vertex colors and per game object setting up the script.

    vertex colors
    - blue defines the overall bandabilty and is also used for the wind animation.
    - red shifts the animation phase as far as the wind animation is concerned and determines the maximum amplitude of the touch bending.

    $touchbending_vertexcolors_jpg.jpg

    setting up the script
    the touch bending script offers the following parameters that can be tweaked individually for each game object in your scene:
    - bandabilty: low values will give you only little bending whereas high values will raise the amplitude.
    - disturbance: amount of extra disturbance (like secondary wind bending) added to the plant while it is touched.
    - duration: duration of the touch bending.

    right now touch bending only takes the player’s direction and speed into account which will make the whole plant bend according to the parameters mentioned above. i might think about implementing some tweaks from my first version (which also considered the magnitude between player and vertex position) but that will not be part of version 1.
    in case you need different touch bending animations like smooth swing back vs. high frequency shiver you can easily implement your own easing equation. so each plant can have its individual animation.

    lars
     
    Last edited: Jul 21, 2013
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    thanks nipoco.
    but i have to admit that touch bending will not work within the terrain engine but only on manually placed game objects…

    lars
     
  14. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    I see. It's still a fine and useful thing to have.
     
  15. Andrew_atl

    Andrew_atl

    Joined:
    Sep 21, 2010
    Posts:
    103
    Nice, I was just hoping for something like this the other day!
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    Last edited: Jul 31, 2013
  17. carl010010

    carl010010

    Joined:
    Jul 14, 2010
    Posts:
    139
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848