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

ats Mobile Foliage [released]

Discussion in 'Assets and Asset Store' started by larsbertram1, May 20, 2012.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    having a look at the script i can only imagine, that setting the "camera.main.layerCullDistances" might be the reason for your tree to get invisible. check its layer and may be change TreeDistance = 500;and MediumDetailsDistance = 5;

    lars
     
  2. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,266
    I love these shaders. I'll be using them with sprites to create the illusion of movement. Any idea how to add simple vertex lighting?

    I see where the vertex alpha ambient occlusion is calculated in the fragment program; I was hoping it would be as easy as multiplying that with _LightColor0 somehow, but I'm not even a novice with CG and can't penetrate it.

    EDIT: Solved by trial and error.
     
    Last edited: Aug 8, 2013
  3. alessandro_88

    alessandro_88

    Joined:
    Aug 19, 2013
    Posts:
    8

    first of all, thank you very much!! :)
    i tried to get it work, that the grasses move at different speeds. i added therefore the vegetation-movement script. but if i press play, and then change the values of (for example) the wind.x there is just one grass (i think it is the last in the hierarchy-list) that will react to the changements. also will every grasses move then at the same speed, as this specific grass. how can i achieve, that i can fill in a unique value for every grass to make it move at it's own speed? thank you!
     
  4. larsbertram1

    larsbertram1

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

    i haven’t looked into these shaders for quite a while.
    and i t might be time to get back to them. unless then i guess you will have to live with what you can do now.

    lars
     
  5. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    Surprised I only just discovered this, this is great! I've been looking for some form of 'windy grass' shader and this is exactly what I need. And what's more it's free! Thanks so much Lars :)

    I'm guessing, instead of having the entire tree bend in the wind, that it's not currently possible to have only the leaves on trees flutter?
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    yes, bending is controlled by vertex colors. so just apply them the the pat of your model which you want to bend.

    lars
     
  7. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    Heh. Noticed this in the documentation after my post :oops:



    Aside from that, I have a little bit of weirdness happening with the grass. Mostly it works fine but a few of them seem to jerk about a bit. It changes depending on where the camera is looking… Anyone else experienced this? Any ideas how to fix it?

    You can watch a video here: https://www.dropbox.com/s/6zuoogd637jvlfg/Grass%20weirdness.m4v
     
  8. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    I'm looking for the fastest possible shader for trees and tree billboards. I have a scene with thousands of trees, which is posing a big challenge for iPad. I understand that these shaders are good for mobile, and include tree bending with the wind -- which is nice, but I would happily lose that for better iOS performance. You mentioned earlier that if I don't want bending, then just use a built-in mobile shader. That would be just as fast as this? Or is there a way to tweak these shader to be as fast as possible?
     
  9. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    This problem seems to have resolved itself in a recent Unity update.

    I've begun using the fern and noticed a weird jerking problem whenever the camera moves around it. It works great when the camera is still though. What's wrong with the shader here? Can see the issue here: https://www.dropbox.com/s/i7r4yj18bk201u2/fern_weird.m4v
     
  10. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    So it seems the fern jerking occurs when using the alpha blended fern where more than one is on-screen at once. It appears to be an issue related to dynamic batching. After some help with Lars it seems the best course of action is to try combining all your foliage into one mesh, but this can remove the vertex color information so this will need to be preserved or replaced after combining.

    Another option would be if someone could edit the shader to vertex animate in global space rather than local space. I am not to that level yet but just putting that info out there for future reference in case someone else was able to do that! :)
     
  11. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    I understand (from previous queries) that this shader requires that the trees be lightmapped in order to prevent color shifting as the camera moves around the trees. Normally that's fine, but now I want to use this shader in a scene with a dynamic sun (moving across the sky), so I can't lightmap the scene. Is there a way to modify the shader so the tree looks good without lightmaps?
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    you would have to add a lighting function which is pretty expensive on mobile…

    lars
     
  13. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    Okay. Thanks much for the quick reply.

    Somewhat OT, but: Do you (or anyone) know if it's possible to bake a lightmap on a single tree prefab, and have it used by all instances of that prefab?
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    i guess: not within unity. but you could easily bake such a lightmap in your 3d app and add it as texture.
    lars
     
  15. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    Okay, so I combined the meshes into one, which fixed the issue. The Mesh Combine Children script I used that retained vertex colors was this: http://forum.unity3d.com/threads/4538-Mesh-Combine-Children-and-Vertex-Colors

    And I used a CombineChildren script to reference this. If anyone ever needs my slightly customized version which saves the combined result as an asset:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Collections;
    5. using System.IO;
    6. /*
    7. Attach this script as a parent to some game objects. The script will then combine the meshes at startup.
    8. This is useful as a performance optimization since it is faster to render one big mesh than many small meshes. See the docs on graphics performance optimization for more info.
    9.  
    10. Different materials will cause multiple meshes to be created, thus it is useful to share as many textures/material as you can.
    11. */
    12.  
    13. [AddComponentMenu("Mesh/Combine Children")]
    14. public class CombineChildren : MonoBehaviour {
    15.    
    16.     /// Usually rendering with triangle strips is faster.
    17.     /// However when combining objects with very low triangle counts, it can be faster to use triangles.
    18.     /// Best is to try out which value is faster in practice.
    19.     public bool generateTriangleStrips = true;
    20.     public bool castShadows = true;
    21.     public bool receiveShadows = true;
    22.     public bool saveGeneratedMesh = false;
    23.    
    24.     /// This option has a far longer preprocessing time at startup but leads to better runtime performance.
    25.     void Start () {
    26.         Component[] filters = GetComponentsInChildren(typeof(MeshFilter));
    27.         Matrix4x4 myTransform = transform.worldToLocalMatrix;
    28.         Hashtable materialToMesh = new Hashtable();
    29.        
    30.         for (int i=0;i<filters.Length;i++) {
    31.             MeshFilter filter = (MeshFilter)filters[i];
    32.             Renderer curRenderer  = filters[i].renderer;
    33.             MeshCombineUtility.MeshInstance instance = new MeshCombineUtility.MeshInstance ();
    34.             instance.mesh = filter.sharedMesh;
    35.             if (curRenderer != null  curRenderer.enabled  instance.mesh != null) {
    36.                 instance.transform = myTransform * filter.transform.localToWorldMatrix;
    37.                
    38.                 Material[] materials = curRenderer.sharedMaterials;
    39.                 for (int m=0;m<materials.Length;m++) {
    40.                     instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);
    41.                    
    42.                     ArrayList objects = (ArrayList)materialToMesh[materials[m]];
    43.                     if (objects != null) {
    44.                         objects.Add(instance);
    45.                     }
    46.                     else
    47.                     {
    48.                         objects = new ArrayList ();
    49.                         objects.Add(instance);
    50.                         materialToMesh.Add(materials[m], objects);
    51.                     }
    52.                 }
    53.                
    54.                 curRenderer.enabled = false;
    55.             }
    56.         }
    57.        
    58.         foreach (DictionaryEntry de  in materialToMesh) {
    59.             ArrayList elements = (ArrayList)de.Value;
    60.             MeshCombineUtility.MeshInstance[] instances = (MeshCombineUtility.MeshInstance[])elements.ToArray(typeof(MeshCombineUtility.MeshInstance));
    61.            
    62.             // We have a maximum of one material, so just attach the mesh to our own game object
    63.             if (materialToMesh.Count == 1)
    64.             {
    65.                 // Make sure we have a mesh filter  renderer
    66.                 if (GetComponent(typeof(MeshFilter)) == null)
    67.                     gameObject.AddComponent(typeof(MeshFilter));
    68.                 if (!GetComponent("MeshRenderer"))
    69.                     gameObject.AddComponent("MeshRenderer");
    70.                
    71.                 MeshFilter filter = (MeshFilter)GetComponent(typeof(MeshFilter));
    72.                 filter.mesh = MeshCombineUtility.Combine(instances, generateTriangleStrips);
    73.                 renderer.material = (Material)de.Key;
    74.                 renderer.enabled = true;
    75.                 renderer.castShadows = castShadows;
    76.                 renderer.receiveShadows = receiveShadows;
    77.                 if ( saveGeneratedMesh )
    78.                 {
    79.                     if ( !Directory.Exists("Assets/Objects/Combined") )
    80.                         AssetDatabase.CreateFolder( "Assets/Objects", "Combined" );
    81.                     if ( !Directory.Exists("Assets/Objects/Combined/"+Application.loadedLevelName) )
    82.                         AssetDatabase.CreateFolder( "Assets/Objects/Combined", Application.loadedLevelName );
    83.                     AssetDatabase.CreateAsset(filter.mesh, "Assets/Objects/Combined/" + Application.loadedLevelName + "/" + gameObject.name + "_combined.asset");
    84.                     Debug.Log ("Created new asset. Check Assets/Objects folder");
    85.                 }
    86.             }
    87.             // We have multiple materials to take care of, build one mesh / gameobject for each material
    88.             // and parent it to this object
    89.             else
    90.             {
    91.                 GameObject go = new GameObject("Combined mesh");
    92.                 go.transform.parent = transform;
    93.                 go.transform.localScale = Vector3.one;
    94.                 go.transform.localRotation = Quaternion.identity;
    95.                 go.transform.localPosition = Vector3.zero;
    96.                 go.AddComponent(typeof(MeshFilter));
    97.                 go.AddComponent("MeshRenderer");
    98.                 go.renderer.material = (Material)de.Key;
    99.                 MeshFilter filter = (MeshFilter)go.GetComponent(typeof(MeshFilter));
    100.                 filter.mesh = MeshCombineUtility.Combine(instances, generateTriangleStrips);
    101.             }
    102.         }  
    103.     }  
    104. }
    105.  
     
  16. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    I've used this shader quite successfully in the past, but now I'm having troubles with depth sorting -- the tree branch depths are completely mixed up. I am testing in a project in which it worked great before, with the same tree models. I'm using 4.3.3 -- and I'm wondering if something changed in the lightmapping with 4.3 that might have broken this shader? Has anyone else had success or problems using it in 4.3? (Yes, I am switching to the default transparent cutout diffuse shader for lightmapping, then switching back to the ats shader -- and that's when the depth sorting issues appear.)
     
  17. Essential

    Essential

    Joined:
    Sep 8, 2011
    Posts:
    265
    I had a lot of depth-sorting issues. You can take a look at my posts on this page and the last one. The solution was to combine the meshes.
     
  18. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    I can't combine all the trees into one mesh. (I have 10,000 trees in the scene, and am using a different LOD/batching solution.) And this is a new problem -- the same tree that works/looks great in older versions of Unity has depth-sorting issues in 4.3....
     
  19. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,238
    Well, it's not a Unity version issue. I'm having the same problem now in Unity 3.5.7. Am I missing a step? Here's what I'm doing:
    1) Bring tree into scene, mark it as static.
    2) Assign Unity's Transparent/Cutout/Diffuse shader to the leaves material.
    3) Run lightmapping.
    4) Assign atsVegetation-Unlit-Lightmap-Wind Alpha Blended OR Tested shader
    5) Ambient occlusion is screwy (branch tips are darker than inner tree, some spots are oddly bright). Depth sorting is correct with alpha tested (but that's worse on iOS). but screwy with alpha blended.

    Am i doing something wrong?
     
  20. WendelinReich

    WendelinReich

    Joined:
    Dec 22, 2011
    Posts:
    228
    Not sure if anyone else has noticed, but the shaders currently don't work with Unity 5. I'm guessing it may be because the lightmap system has changed - but I'm not sure because I'm not a shader programmer.

    Does anyone have a clue? Is this a simple matter of changing a function call or is this more complex?

    (I may add that the shaders worked well for me in Unity 4.5.5, whatever issues other people may be having...)
     
  21. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Hi guys,

    I am having trouble with using this shader. For some reason the trees are either completely white or black when I use a different scene. There is no problem with the demo scene though.
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    you have to lightmap the scene...
     
  23. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Hi
    Are you suggesting I should use different shaders to lightmap then scene, and then use this shader?
     
  24. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    yes, as beast does not recognize alpha transparency on the mobile foliage shaders.
     
  25. Eric-Chadwick

    Eric-Chadwick

    Joined:
    Mar 26, 2012
    Posts:
    20
    Hi Lars,

    Thank you so much for providing these shaders!

    I was using them for sails on a ship, but it seems the shaders are broken in Unity 5.0.1f1.

    Most of them render black, except atsGrass-Unlit-Wind, but that has sorting errors so I can't really use it... some of the sails draw in front of the other sails, and my blob shadows also poke through. It doesn't have the vertex alpha ambient occlusion either, which is really helpful to have for better shading.



    Any chance of updating these to work in Unity 5? Or perhaps there's a simple fix I can apply myself?

    I might be able to use Advanced Foliage Shaders, but I'm not sure if those work with arbitrary non-terrain models like this ship... would they?

    Thanks again.
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    i am not sure if the advanced foliage shaders would do the job.
    but the mobile foliage shaders will not be updated within the next month, sorry:
    there is simply too much to do right now.
    cheers, lars
     
  27. apan-bin

    apan-bin

    Joined:
    May 15, 2015
    Posts:
    29
    QQ0001.jpg Hi Lars,
    This is a veryuseful shader,but I met a static batch processing problem.I used two kind of grass, it stands to reason that should be processing for 2 DrawCalls, but stats show but super chat out, I not only is caused by what?In T4M, I met the same situation.The solutioncan not findit annoys me.....(Mesh has a static hook):(
     
    Last edited: May 15, 2015
  28. Girish-sruthkia

    Girish-sruthkia

    Joined:
    Mar 24, 2015
    Posts:
    5
    hi Lars,
    Using your shaders for quite some time, which are awesome and should mention that your shaders are the only one which can be used efficiently on mobile.
    Good documentation.
    The thing i want to know is, can we use the same vertex colors as diffuse color for the tree/fern which are opaque.
    if so can u please post the shader.

    Thanks for your shaders, it helped me alot, after days of research i got them on the assetstore and one of the best available for mobile.
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    hi there,
    i dont understand your question, sorry.

    lars
     
  30. Girish-sruthkia

    Girish-sruthkia

    Joined:
    Mar 24, 2015
    Posts:
    5
    Hi Lars,
    Sorry for that confusing question.
    My question was, now we are using vertex colors for tree leaves movement, i there any way that we can use the same vertex colors for diffuse channel also without using 2d texture, Which will be more performance saver on mobiles??
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,848
    i haven’t had a look into the shaders for about 3 years – but if the vertex colors are passed to the fragment shader using these to add color should not be a problem.
     
  32. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,020
    Using the vertex colors you use for the leaf movement for the color as well, will result in your leaves having very weird colors.

    (also, I believe the vertex colors are passed to the fragment)
     
  33. Girish-sruthkia

    Girish-sruthkia

    Joined:
    Mar 24, 2015
    Posts:
    5
    I wonder how they got this grass(animated), is it textured or just vertex colors.
    BTW it is from Lara Croft GO.
    Can somebody tell me how they would have acheived. Laracroft Go.jpg
     
  34. mikaelgustafsson

    mikaelgustafsson

    Joined:
    Mar 6, 2014
    Posts:
    13
    I've got two questions:

    1. How can I adjust the code so that I don´t have to have a lightmap? I want to use a unlit shader.

    2. How do I make the trees be affected by the built in fog?

    Thanks
     
  35. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I have a error on Unity 5.1.4 DX9 for each shaders.
    Shader error in 'atsVegetation Unlit-Lightmap-Wind Alpha Blended': variable 'o' used without having been completely initialized at line 108 (on d3d9)
     
  36. Yippie

    Yippie

    Joined:
    May 4, 2009
    Posts:
    227
    Although they look 2D but actually this game is a 3D game will toon shading, so the grasses are 3D models, they're textured to look like 2D toon grass, how they're animated, maybe by vertex shader or they're rigged and animated like a normal skinned character with bones.
     
  37. policetestprep3

    policetestprep3

    Joined:
    Jul 19, 2016
    Posts:
    1
    Police Test Prep helped me enormously when I was get ready to compose my tests with ATS. Around 6 months after the fact I was procured. I discovered Police Test Prep's learning modules to be forward and impeccably disclosed to make things so much less demanding and WAY FASTER!

    For More Information Visit Here:- https://www.policetestprep.ca/
     
  38. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    133
    anyone fixed shadow issue ?? i want to use realtime shadow
     
  39. EvilGremlin

    EvilGremlin

    Joined:
    Aug 12, 2016
    Posts:
    231
    So this shader is depreciated now. Any alternatives?