Search Unity

TurboForest: Unity fast billboard forest rendering

Discussion in 'Assets and Asset Store' started by Alekxss, Jan 23, 2014.

  1. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    @hopeful I have added a top down camera to check performance in this area when the switch comes, the z-fighting seems to exist in the previous implementation fwiw, fixable via radius as you say. :)

    @Aily "Here's terrain with ~20 000 trees + 20 000 TF trees. It's 2x2km, and TF chunk size set to 1km, i.e 8 TF chunks(draw calls) - 4 for diffuse and 4 for shadows."

    It just said 544. That is why I asked. must be the terrain then. cheers

    upload_2015-4-12_17-1-26.png
     
  2. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Some test with realy big terrain (20x20km with 500 000 trees) ( if i counted all correct :) )
    Default terrain trees:
    models far cull 200m
    billboards cull 2000m
    tf_terr_speed_test1.jpg

    Added TurboForest as far LOD (2x2km chunks)
    tf_terr_speed_test2.jpg

    You can see here unexpected bonus! TF shadow casters can be used now as shadows from terrain billboards.
    And now realy all trees drop shadows.
     
  3. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Don't know what Unity count, maybe it's terrain trees+terrain chunks.
     
    twobob likes this.
  4. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    The Frame Debugger makes it very easy to find out.
    Anyways, I think it is that.

    Thanks
     
  5. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Mesh trees added

    tf_mesh.jpg

    DEMO
     
    twobob likes this.
  6. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    love that. Excellence. The "double billboard" look is super cute!
     
  7. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Have big world ready for some mesh trees.

    upload_2015-4-19_21-53-57.png

    Did you release the mesh creation version please mate?

    Please may I have it?

    Many thanks
     
  8. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Still no. New TF tools are ready, but it now realiy complex to ajust, specialy when adding trees, because of many different techniques. Working this days to make it more user friendly. Can send you draft version, but better to little wait when it will be ready.
     
  9. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    okay. thanks for the update Aily
     
  10. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Here is an idea to make a dense forest, drawing only the top, and just the tree trunks from the side. With dense forests you can't see the tree trunks so the whole thing can be drawn using a large static low poly mesh.This should give another huge speed improvement.

    Examples of what a dense forest looks like from above:

    forest above.jpg

    forest above 2.jpg

    This should be achievable with a simple mesh, clever normal mapping, and perhaps even some displacement mapping.

    Would you be interested in adding this type of forest?
     
    hopeful likes this.
  11. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    I hink this technique is heavy different than TF, and TF now became more complex than expected at first.
    This type of multipass rendering need some research and will be another tool.
    So nope, i can't improve this in TF, sorry.
     
  12. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Why would this require multi pass rendering? Just a diffuse and normal map should do.
     
  13. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Ah, i get that you means :)
    New TF tools have shaders to simulate what you want.

    1. Add TurboForest object and generate trunks with "Mesh" or "Cylindrical" type.
    2. Add another one TF object and generate leaves with "Billboard" type.

    But it still not updated in assetstore (making adding own trees features to be more handy)

    P.S.
    About multipass i've just thought that you want to render trees as one plane with multipas with something like 3D texture :)
     
    twobob likes this.
  14. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    No need for 3d textures. The current leaf textures look quite ok at large distance so the same technique can be used for a dense forest.

    Will have a look at the new version once it comes out.
     
  15. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I have modded your shader to render lights as far as the eye can see, at incredible speed.

    lights.jpg

    It works best with a 3rd party bloom shader such as Sonic Ether's Bloom Shader, or Jove 2.

    Do you mind if I post this shader here? It contains only one line of code from your shader, the one which rotates the billboard:
    Code (CSharp):
    1. output.pos = mul(UNITY_MATRIX_P...
    Others might find this useful. I haven't seen anything like this before.
     
    Last edited: Apr 26, 2015
    Andrew_atl, ikemen_blueD and hopeful like this.
  16. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,686
    This looks cool. Maybe it could represent a flyover urban area at night?

    It would be good to use this with a mask, so the lights show up only in a specific area or areas. This would help separate rivers, parks, mountains, and other areas where city lights would not exist.
     
  17. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Not mind ;)
     
  18. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Ok, great. Here it is.

    Code (CSharp):
    1.  
    2. Shader "Custom/TurboLights"{
    3.  
    4.     Properties{
    5.  
    6.         //Place the variables on the Inspector.
    7.         _MainTex ("Particle Texture", 2D) = "white" {}
    8.         _Color ("Color", Color) = (0.5,0.5,0.5,0.5)
    9.         _Yoffset ("Y Offset", FLOAT) = 0.0
    10.         _Scale ("Scale", FLOAT) = 1.0
    11.         _Brightness ("Brightness", Range(0, 1)) = 0.3
    12.     }  
    13.  
    14.     SubShader{
    15.  
    16.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    17.         Blend SrcAlpha One
    18.         AlphaTest Greater .01
    19.         ColorMask RGB
    20.         Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
    21.      
    22.         Pass{
    23.  
    24.             CGPROGRAM
    25.             #include "UnityCG.cginc"
    26.             #pragma vertex vert
    27.             #pragma fragment frag
    28.             #pragma multi_compile_particles
    29.      
    30.             uniform sampler2D _MainTex;      
    31.             uniform float _Yoffset;
    32.             fixed4 _Color;
    33.             float _Brightness;
    34.             float _Scale;
    35.  
    36.             struct vertexInput {
    37.  
    38.                 float4 center : POSITION;
    39.                 float4 uv0 : TEXCOORD0; //Texture coordinates.
    40.                 float4 uv1 : TEXCOORD1; //Vertex coordinates are stored in the second UV channel.
    41.                 fixed4 color : COLOR;
    42.             };
    43.  
    44.             struct vertexOutput{
    45.  
    46.                 float4 pos : SV_POSITION;
    47.                 float4 uv0 : TEXCOORD0;
    48.                 fixed4 color : COLOR;
    49.             };          
    50.  
    51.             vertexOutput vert(vertexInput input){
    52.  
    53.                 vertexOutput output;
    54.  
    55.                 /*
    56.                 //Set the scale.
    57.                 float offsetY = (input.uv1.y + _Yoffset) * _Scale;
    58.                 float offsetX = -input.uv1.x * _Scale;
    59.  
    60.                 //Rotate billboard only around Y.
    61.                 output.pos = mul(UNITY_MATRIX_MV, float4(input.center.x, input.center.y + offsetY, input.center.z, 1));
    62.                 output.pos = mul(UNITY_MATRIX_P, output.pos + float4(offsetX, 0, 0, 0) );
    63.                 */
    64.  
    65.                
    66.                 //Rotate the billboard towards the camera.
    67.                 float4 offset = float4(input.uv1.x, -input.uv1.y + _Yoffset, 0.0, 0.0) * _Scale;
    68.                 output.pos = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_MV, input.center) + offset);
    69.                
    70.  
    71.                 /*
    72.                 //Always face the same way.
    73.                 //Set "Cull Off" to make billboard double sided.
    74.                 float4 offset = float4(input.uv1.x, input.uv1.y + _Yoffset, 0.0, 0.0) * _Scale;
    75.                 output.pos = mul(UNITY_MATRIX_MVP, input.center + offset);
    76.                 */
    77.  
    78.                 //UV mapping.
    79.                 output.uv0 = input.uv0;
    80.  
    81.                 //Set the color.
    82.                 output.color = input.color;
    83.  
    84.                 return output;
    85.             }
    86.  
    87.             float4 frag(vertexOutput input) : COLOR{
    88.  
    89.                 //Compute the final color.
    90.                 return 2.0f * input.color * _Color * tex2D(_MainTex, input.uv0) * (exp(_Brightness * 5.0f));
    91.             }
    92.  
    93.            ENDCG
    94.         }
    95.     }
    96.  
    97.     FallBack "Diffuse"
    98. }
    99.  
    100.  
    It needs a simple flare texture such as this (no need for alpha, that is handled automatically):

    flare.png

    The mesh has to be generated by the TurboForest.cs script (because of uv mapping and vertex placement) so you can use the existing forest workflow to place the lights.
     
    Last edited: Apr 27, 2015
    hopeful likes this.
  19. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Ok, last bugs fixing and uploading to store.
    Guys, if you have Android devices, can you just run this APK and look how it works?
    http://goo.gl/949HMs (20mb)
    Scene have ~20 000 trees, without shadows but attenuted by normalmap+light.
     
    twobob likes this.
  20. Deleted User

    Deleted User

    Guest

    4 frames per second..on galaxy tab2..not turbo...yet...1280X800 resolution..FYI
     
    Last edited by a moderator: Apr 26, 2015
  21. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Don't know how Unity count framerate, but in Editor TF trees renders 2x faster than same default billboard trees. (using Unity's counter)
    Making comparison APK, something wrong here...
     
  22. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Ok, let's make it clear.
    As
    realy, seems like not turbo if compare with same trees look as terrain trees.

    I've made some test here ad see that Unity frame built in counter not realy show FPS in fact.
    Unity count just time spent to render by camera, exclude time that need to render by GPU.

    Builtin forest loose time on batch trees, but renders very fast.
    TF not spend time to batch (because almost batched to chunks), but spend time with GPU render.

    Builtin trees:
    terrain_trees.jpg

    TF trees
    tf_trees.jpg

    Wee just cant jump above head, and seems like default trees and TF trees renders ~same speed.

    But TF still have it own features, which not exist in builtin trees.

    Thanks ForceVFX, good to know it runs on not same as mine device.
     
  23. Deleted User

    Deleted User

    Guest

    Well, I have been watching this...I was just hoping for another pipeline, I do not have 3D max...I use maya..and I place my trees through Terrain Composer, based on pixel color, from a satellite image or color map..

    I have spent months..on one tree...really..sounds dumb, but replicate it, 2,000 times with 16 tiles, approx 200.000 Pine tree mesh, get it to run a 100 draws or less(a full 360 camera rotation) running on android at 60 FPS @ My phones resolution. Problem..Vertice count is crazy..I have three other tree types..that fill out the scene..I have placed all the buildings...found out , there was no way..ever, I was going to get that to run on mobile devices



    This would be the best and fasted I can get so far..

    Give me a way to use this with maya..I will become a customer..I have 2 other big projects that need Lots Of Turbo Fast Trees..(Speed tree has better quality, but can not come close to this speed...

    p-
     
    Last edited by a moderator: Apr 26, 2015
  24. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    You can model "forest places" above your map with Maya (tool not make sense, any modelling tool wich can create triangles)

    Next export it to Unity, set to TF yor "forest place" mesh and just press Generate.
    Trees will be distribute in that mesh area but above your terrain.

    Its very fast way.

    And new version now have tools to add trees in Unity editor (paint trees)

    Here is APK with almost all features demos inculed

    Base techniques:
    1. Atlas trees (for strategy\flightsim\RTS)
    2. Cylindrical trees (for racing games, RPG maybe)
    3. Mesh X trees (same for racing\RPG)
    And experimental:
    4. Dynamic (works almost same as terrain trees)
    5. Terrain near cull (for using TF as far LOD for builtin terrain)

    First 4 scenes in demos have ~40 000 trees.
    Terrain ~10000 as i remember...
     
  25. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
  26. Deleted User

    Deleted User

    Guest

    So...I no longer need vray to render my own trees?

    I understand creating the mesh /look up..take my existing mesh terrain, use my wacom brush to select the faces for trees, then use that selection for a new mesh, that way, I can paint directly on my satellite Images..so the height, will use raycast?, so I do not need my elevation for my tree placement? It can just be flat?

    I can use my own,low poly mesh trees? And once placed, can you delete that mesh?

    Thanks..
    p
     
  27. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Yes, it's automatic now. Not so ideal as VRay, you can see quality in demos. It's just placed regular mesh trees in scene and rendered using special script and shader.

    Yep, old version and new one works like this.

    Yes, but I prefer just disable it renderer - to regenerate forest if i want make changes.
     
  28. Deleted User

    Deleted User

    Guest

    FYI : APK Demo - Atlas 6 FPS (I believe there is something Other than Turbo trees causing this...)

     
    Last edited by a moderator: Apr 26, 2015
  29. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170

    I not get it, as for me - looks cute :) I'm not designer, realy.
    (shadows disabled for Android)
     
  30. Deleted User

    Deleted User

    Guest

    Actually..not my point.(it is cute though, in a minimalist way) ...6 Frames per second..is my point...As a test..a took my base scene, with all my trees, switched to Galaxy Tab 2 (1280X800) at "Fantastic" Quality...I really hate to tell you this...but I can not get my scene to run that slow, really..something is wrong with your build, your textures, something...to waste even more time, its Sunday ;-) .I created a new build....remember this is w/ my animated UI, Full flight physics, my scene is 10X as big, as your demo..with rear camera, going at full speed!!)..see spoiler..
    I thought this was too slow.:)....(The Editor FPS match my Devices Profiled FPS ( + or - 2 FPS)

    My main point..that APK is not...Conducive to future mobile sales? That even 30 FPS is unacceptable.(just for trees)

    Just trying to give a real world comparison..I really want this to work..fast...and for you to prove it..that's all.

    I am not showing off or being personally critical..Just Professional feedback to further your product development..

    (honestly)

    p-
     
    Last edited by a moderator: Apr 26, 2015
  31. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Ok, it's very good feedback. I have a questions for you ;)
    1. This screenshot is from Editor running on PC?
    2. How much visible trees in view?
     
  32. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    ready to use the new version mate.
    as and when :)
     
    Alekxss likes this.
  33. Deleted User

    Deleted User

    Guest

    Yes.in the editor, windows xp :-(....but connected to my device...that is why I mention the device profile rate....the editor fps and what I get from the build on my device...in my unity pro 4.6.1 those numbers almost match, test after test, my editor fps rate, while connected, is exactly what I am getting in my build. (thats the caveat..unity 5, in my opinion.! Is to slow to work with.yet...something is going on..both on my laptop, pc..and all my android devices..3 words keep popping up in my mind..de-moted instruction sets..?).I can profile my latest build, from my tab2, but that only has 4 quadrants of 1,500 trees each...

    Visable trees, well on the latest screen shot, which Is all pine trees, 4x4 mesh terrain = 16 quadrants x 1,1,500 = approx 24,000 trees, according to occlusion view I can see, maby 8,000?

    Something is fighting in that apk...I can see exactly what you Intended, colors, textures, but some proccess is slowing the performance to crawl...i will try my phone next..things that may be slowing you down,
    turnoff all colliders, turn off sprite packer, disable vsynch, set lighting to skybox...um..I will keep thinking of things, that might help



    P
     
    Last edited by a moderator: Apr 26, 2015
  34. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Profiler?
     
  35. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    What is the cylindrical rotation code you are using (like "output.pos= mul(...")? I want to add that to the lights shader.
     
  36. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Code (CSharp):
    1.  
    2. o.pos = mul(UNITY_MATRIX_MV, float4(i.center.x, i.center.y + i.corner.y, i.center.z, 1));
    3. o.pos = mul(UNITY_MATRIX_P, o.pos + float4(-i.corner.x, 0, 0, 0) );
    4.  
     
  37. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Thats the answer, Editor FPS counter doesn't see GFX.WaitForPresent from profiler (maybe something else, don't know realy) but script counting FPS manualy always showing ~ 2-3 times less FPS, then Editor.

    In TF test there 4 chunks and most time you see all of them, i.e. 40 000 trees * 2 triangles = 80 000 triangles. Its very a lot for mobile. And for you Tab2 a fortiori. (on my JXD S7800b it runs 15-25 FPS)

    So i thinking with suitable chunk size for your scene - you will have same render speed + handy tools to distribute forest.

    P.S. Your affected me yesterday with "not turbo" feedback. I've made test (disable almost all in shader) and not got any speedup.... Huge triangles count fault, shader doesn't matter.

    And I realy cant imagine how you getting 30 FPS with 500 000 triangles on mobile o_O
     
    Last edited: Apr 27, 2015
  38. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Very-sery soon. This speed test takes a lot of time yesterday and i did not have time to upload it...
     
    twobob likes this.
  39. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Profiler most part (~60% of speed) eating by PresentAndVSync. So i think, this means that TF all render job send to video hardware of device.
    (in any 3D graphics optimization this case is better than instancing for me, every time)
     
  40. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Thanks. Works beautifully :)

    I added it to the shader in my previous post, along with a scale function.
     
    Last edited: Apr 27, 2015
    twobob likes this.
  41. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    I noticed that the trees are split into groups not based on the amount of trees, but the position of the collider. If a small collider area is used, this results in a couple of groups being generated, each only containing a few trees.

    I am sure there is another way of doing this :)
     
  42. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Yep, random point in mesh wich uses TF is not ideal (i grabbed it somwhere from internet).
    But i almost solve it and now trees generating:
    1. by density (not by count)
    2. evenly random placed

    P.S. Another one sorry guys for so long, i guarantie you to upload new TF stuff this holidays.
     
  43. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
  44. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    New version uploaded, waiting approval.
     
    hopeful and twobob like this.
  45. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Editor features
     
    twobob likes this.
  46. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Adjusting forest now will be like this: (no need to searching properties in materials)
     
  47. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,783
    Can this be used with speed trees ?
     
  48. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Conifers in package is free Speed Tree. But warning you, it's not 2 clicks to use them.
    To use Speed Tree need:
    1. Duplicate your tree materials.
    2. Assign to this materials special shader (for render atlases)
    3. Put your tree in tf_atlasrender scene, adjust it to fit camera viewport.
    4. Adjust this materials
    5. Press Render.

    After this TF generate atlas, side view, normals textures and all required scriptable objects for it.
    And this new tree apears in forest data like as built-in trees.

    It's realy, 10-15 minutes to setup Speed Tree for TF :)
     
    Last edited: May 4, 2015
    hopeful likes this.
  49. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,783
    Thanks Aily :)
     
  50. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Importing it now. must have cleared.
    yay asset store team
     
    hopeful likes this.