Search Unity

[Shader - Open Source] Polygon Wind - for Low Poly Tree Assets

Discussion in 'Shaders' started by Renan-Bomtempo, Oct 8, 2017.

  1. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    Last year I was looking for a wind shader to use on a low poly model, however I couldn't find one that had the visual I was looking for. So I started to develop the Polygon Wind Shader.

    It is supposed to simulate a more suttle organic wind movement on trees (not great for heavy wind effects).
    Lately I haven't had much time to work on it, so I decided to publish the source code here and make it available so that anyone can use it.

    Result achieved in the last dev sprint.



    This is an example of what it can look like, when used to populate a scene with the terrain editor.



    How to use it:

    Just apply the shader to a material and apply the material to your asset. The ideal tree asset is one with a single mesh.

    The shader has various parameters for you to tweak:
    • Wind Wave Size;
    • Wind Direction;
    • Tree Sway Displacement;
    • Tree Sway Stutter;
    • Tree Sway Speed;
    • Foliage Wiggle Amount;
    • Foliage Wiggle Speed;
    • Branches Up/Down;
    • Red Vertex Influence;
    • Blue Vertex Influence.
    It uses a series of inputs to calculate the final vertex position, one of them being the vertices colors of the mesh:
    • Red - Use on the branches to make possible the up/down movement;
    • Blue - Use it on the leaves to get that organic wiggle movement.
    Example of a painted mesh:

    2018-03-12.png

    Here is the source code: GitHub

    Ps.: Feel free to alter it in any way you like. Just remember to give me credit for the original development :)
     
    Last edited: Mar 18, 2018
  2. SomerenV

    SomerenV

    Joined:
    Dec 20, 2011
    Posts:
    83
    Damn dude! Looks really good so far :) Can't wait to get my hands on it and start playing around with it. Keep it up!
     
    Renan-Bomtempo likes this.
  3. ManxJason86

    ManxJason86

    Joined:
    Mar 11, 2017
    Posts:
    2
    Would love to get my hands on this package!
     
    Renan-Bomtempo likes this.
  4. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    BrandyStarbrite and Flurgle like this.
  5. HUBA-GAMES-Sixx93

    HUBA-GAMES-Sixx93

    Joined:
    Jul 23, 2015
    Posts:
    1
    any update on this project? I am really interested in this...
     
  6. gurkansinel

    gurkansinel

    Joined:
    Dec 27, 2013
    Posts:
    1
    how can we buy/get it?
     
  7. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    Hi!
    So, I finally finished all my school work and now I can focus more on the development of the project.
    Seeing that people are interested in it really inspiree me to keep working on it!
     
    joshcamas likes this.
  8. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    It isn't ready yet, but when it is, I'm still not sure how I'll release it.
     
  9. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    Question: How do you manage to have custom tree shaders? My game always complains that it needs specific shaders (Nature/Tree Soft Occlusion Leaves)
     
  10. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    The thing is, these trees are not created with the Tree Editor, they are independent external assets. Then I apply the material thats using my shader to them, as with any other standard game asset.
    Hope this answered your question.
     
  11. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    Ah sorry, I meant how are you using these trees with the terrain tree system. (Using the terrain-tree painter). When I use the tool with my external assets, it gives a warning about how it requires the "Nature/Tree Soft Occlusion Leaves" shader.

    If I don't use this, the billboards get messed up.
     
  12. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    That's true, I still have this problem.
    But I don't see it being too much of a problem, given the fact that Low Poly games tend to present less problems performance wise.
     
    joshcamas likes this.
  13. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,277
    Aw man I was hoping there was a way around this. If I use another shader, it get's angry and the leaves turn invisible in the distance. I guess for now I'll have to resort to not using terrain-trees at all, and just using normal meshes. Thanks!
     
    Renan-Bomtempo and evilangel89 like this.
  14. evilangel89

    evilangel89

    Joined:
    Feb 8, 2017
    Posts:
    269
    This is looking pretty cool. Planning on releasing an early access build or something of the sort ? Would buy it :)
     
    Renan-Bomtempo likes this.
  15. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    Update on the Development

    I really appreciate the interest that you guys had with my project!
    I'm back to working on it, so this week I'll release the alpha version!

    Regarding the price:
    I thought a lot about it and I decided not to charge anything for it. Since this is my first project and I'm really a beginner on Shader Programming I don't think my shader will be worth buying at this stage.
    So I'll release it FOR FREE and will keep working on it so I can improve my skills and abilities, and also so that I can provide you guys with a better and improved product.

    Thanks for all your support and interest!
     
    joshcamas likes this.
  16. fayers

    fayers

    Joined:
    May 10, 2017
    Posts:
    8
    Any update on this project? I'd like to test it
     
  17. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    I just updated the main post here in the thread, check it out!

    Any questions regarding the shader's usability, feel free to contact me.
     
  18. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569
    Renan-Bomtempo likes this.
  19. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    I'm actually configuring my GitHub right now hahahah
     
  20. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    have a freaking upvote! This is amazing :D
     
    Renan-Bomtempo likes this.
  21. fayers

    fayers

    Joined:
    May 10, 2017
    Posts:
    8
    Is it possible to add the double side shading option for the leaves?
    Thank you.
     
  22. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    In all honesty, that is some really, really nice work.
     
    Renan-Bomtempo likes this.
  23. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    I tried disabling culling on both faces, but for some reason ends up breaking the shader.
    I need to do some more research to come up with a solution.
     
  24. fayers

    fayers

    Joined:
    May 10, 2017
    Posts:
    8
    Found anything to solve the problem of double shading for the leaves? I look forward to this trick because, for everything else, it goes to perfection and the final effect is really nice to see.
    Thank you.

    P.S. Maybe you could post here on the forum in the scripting section or editor and general support to point out the problem and maybe someone can find the solution.
     
  25. caubebutchi

    caubebutchi

    Joined:
    Dec 12, 2010
    Posts:
    73
    Nice shader, However, you should be add to double shading for the leaves. Please develop it for leaves . I will glad for you alot.
     
  26. seuceu

    seuceu

    Joined:
    Jun 4, 2018
    Posts:
    1
    Thank you very much for such a wonderful shader.
    I succeeded in drawing on both sides.
    Cut out is also possible.
    I can make attractive trees.
     
    Renan-Bomtempo likes this.
  27. Quakeulf

    Quakeulf

    Joined:
    Mar 26, 2013
    Posts:
    40
    You wouldn't need to vertex paint if you made the waving effect exponential upwards on the Y-axis where 0 is the base root and 1 is the top crown, however that could look weird on most trees except maybe palm trees. ;w;
     
    Renan-Bomtempo likes this.
  28. Renan-Bomtempo

    Renan-Bomtempo

    Joined:
    May 1, 2017
    Posts:
    13
    hahahaha yeah, you may be right. I'll certainlly test this later.
    Well, I'm now an undergraduate student in Computational Mathematics, and I'm learning a lot. I really hope to come back to this project with some new ideas and more knowledge. I can't wait to make some more technical art projects!
     
  29. Quakeulf

    Quakeulf

    Joined:
    Mar 26, 2013
    Posts:
    40
    An even better way to do it would be to sort by colour range, as you could "mask" the effect to only apply to certain colour ranges based on UV (leaves will be of a different shade than the trunk etc.). Instead of just using Y, you could use a sphere from 0,0,0 which would be the tree trunk root as it comes up from the ground, and the further away you get the stronger the effect. also this could check for normals so that if the plane is more horizontal it will move less (or just in any way not having a large surface area facing the wind).
     
    Renan-Bomtempo likes this.
  30. Quakeulf

    Quakeulf

    Joined:
    Mar 26, 2013
    Posts:
    40
    I did a little bit of experimentation with this now, and here is the result:

    This was a combination of vertex colouring, world positioning, and the shader you made. The code I have so far which is based on your vert (without a random factor) is here:
    Code (CSharp):
    1.          
    2.             float3 worldPos = mul(unity_ObjectToWorld, i.vertex).xyz;
    3.  
    4.             float windageX = (worldPos.y/_wind_size); //(i.vertex.x/_wind_size);
    5.             float windageZ = (worldPos.y/_wind_size); //(i.vertex.z/_wind_size);
    6.             float vertexing = (i.vertex.y * 0.1); //(i.vertex.y / 10);
    7.  
    8.             //Tree Movement and Wiggle
    9.             i.vertex.x += (cos(_Time.z * _tree_sway_speed + windageX + (sin(_Time.z * _tree_sway_stutter * _tree_sway_speed + windageX) * _tree_sway_stutter_influence) ) + 1) * 0.5 * _tree_sway_disp * _wind_dir.x * vertexing +
    10.             cos(_Time.y * worldPos.y * _leaves_wiggle_speed + windageX) * _leaves_wiggle_disp * _wind_dir.x * i.color * _b_influence;
    11.  
    12.             i.vertex.z += (cos(_Time.z * _tree_sway_speed + windageZ + (sin(_Time.z * _tree_sway_stutter * _tree_sway_speed + windageZ) * _tree_sway_stutter_influence) ) + 1) * 0.5 * _tree_sway_disp * _wind_dir.z * vertexing +
    13.             cos(_Time.y * worldPos.y * _leaves_wiggle_speed + windageX) * _leaves_wiggle_disp * _wind_dir.z * i.color * _b_influence;
    14.  
    15.             i.vertex.y += cos(_Time.z * _tree_sway_speed + (worldPos.y/_wind_size)) * _tree_sway_disp * _wind_dir.y * vertexing;
    16.  
    17.             //Branches Movement
    18.             i.vertex.y += sin(_Time.w * _tree_sway_speed + _wind_dir.x + (worldPos.y/_wind_size)) * _branches_disp * i.color * _r_influence;
    19.  
     
    Renan-Bomtempo likes this.
  31. Quakeulf

    Quakeulf

    Joined:
    Mar 26, 2013
    Posts:
    40
    Just an update: This does not work in deferred lighting in Unity 2018.3.
     
    Renan-Bomtempo likes this.
  32. Ruslank100

    Ruslank100

    Joined:
    Apr 11, 2018
    Posts:
    46
    Hello! I am using Unity's post processing stack, but the ambient occlusion effect looks very glitchy with this shader. Any idea how do I solve this?
     

    Attached Files:

    • ao.png
      ao.png
      File size:
      870.4 KB
      Views:
      854
  33. GreenCubeGames

    GreenCubeGames

    Joined:
    Jan 9, 2015
    Posts:
    19
    no alpha version?
     
  34. MonkeyPuzzle

    MonkeyPuzzle

    Joined:
    Jan 17, 2016
    Posts:
    119
  35. moscatogiovanni01

    moscatogiovanni01

    Joined:
    Sep 26, 2023
    Posts:
    1
    pink texture idk why?? :(
     
  36. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,076
    Okay. Remove the texture and shader, and then re-apply it/them.

    Or, remove the texture and shader, save the project, close the project, open back the project, and then re-apply the shader and texture, or use a different shader. That should solve that annoying pink problem.
     
    Last edited: Jan 18, 2024