Search Unity

[Released] Advanced Terrain Grass

Discussion in 'Assets and Asset Store' started by larsbertram1, Sep 11, 2017.

  1. T_Strijker

    T_Strijker

    Joined:
    Jun 24, 2013
    Posts:
    18
    Hi larsbertram1

    Were have problems in our current game with Unity terrain system taking to much loading time in frames for the grass details. Look at you ATG plugin it could be the solution for fixing our problem. But after reading the first post on this thread I have some questions over the following points:

    - Billboarded grass is not supported. Thus this means that there is no support for rotating meshes to the camera or/and no support for panel like grass meshes?

    - ATG currently does not support to reset the world’s origin and move terrains around to handle floating point issues.
    Thus this mean dat once the ATG grass is loaded at a terrains location that it won't move when the terrain is moved?

    Looking forward to your answers.
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    yes, billboarded grass is not supported.
    the shaders simply do not handle this.
    resetting the world's origin actually is supported now. and so is moving the terrain.
     
  3. T_Strijker

    T_Strijker

    Joined:
    Jun 24, 2013
    Posts:
    18
    Thank you for your answers. It looks like will need to replace all the billboard grass if wan't to use the ATG. As for to be able to move the terrain with the ATG grass is good news :)
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    billboarded grass looks so ugly :)
     
  5. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    Hello! Has anyone successfully layered two cameras (main camera + UI camera) while running ATG?

    If I turn off my UI camera, all the grass renders nicely with no issues. With the UI camera on, I experience either no grass or all the grass vanishing depending on where I stand. Toggling the grass manger "Ignore Visibility" with the UI camera active made no difference. Oddly, while the UI camera is active, only when my Cull Distance is set between'70-90' will I see grass. Anything higher or lower will also cause all the grass to vanish.
     
  6. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    can you give the exact setup of your cameras?
     
  7. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    @larsbertram1
    I sent you a message with an attached demo scene. Hopefully it will show the issue I'm experiencing.
     
  8. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    i had a look into the demo scene and it turned out taht actually your terrain is too small.
    sounds crazy but something breaks if it is too small.
    if i raise the size from 100x100 meters to 200x200 meters everything works as expected.

    i hope this helps.
     
  9. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    Thanks for finding this issue so quickly. Hmmm, this an issue for my project, as I'm making an endless tile runner and the smaller terrain size has a specific purpose. Are there no values in the code I can change to make it work on smaller terrain?
     
  10. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    you can edit the grassmanager script and comment the following return:
    // CullingGroup most likely did not return a valid result... (which happens in the first frame)
    if(numResults == TotalCellCount) {
    return;
    }

    doing so let me use your terrain even with a size of 100x100 meters.
     
    Last edited: Jan 25, 2019
  11. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    Thanks! This works, my grass no longer vanishes on small terrain. Though doesn't commenting out the CullingGroup disable Float Origin correction? The new issue I'm seeing is grass vanishes when I reposition my terrain with Floating Origin Enabled.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    how could i reproduce this?
     
  13. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    I think I easily found the repro. Duplicate a terrain and have both in view. Try moving one of the terrains. You can see the grass moves with the original terrain. I've included a gif.
    floatpoint.gif
     
  14. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    i see. so you do not shift the origin, but shift individual terrains.
    this is not supported as the shift is send as a global vector to the grass shaders :(
    so if you move just one terrain this will influence the grass on all other terrains as well. if the grass actually moves if you move a terrain depends on the oexecution order of the scripts: last grass manager will win.
     
  15. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    That's too bad :( Because I move a couple of small terrains around, I'm experiencing those lag spikes when unitys default grass gets regenerated. I might need to make planes of mesh grass and hand place them I suppose..
     
  16. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    don't give up too early :)

    if i get it right you shift all active terrains synchronously like shown in 1 and 2.
    this should be covered by the grass manager already.
    the problem occours in 3 where you move terrain c individually, right?

    terrainmove.png

    if you move terrain c and push it away from the camera which is located at the gray line at the bottom, then its grass should be invisible to the camera simply because of the grass drawing distance – which is fine as it leaves us some time.

    so in case we move terrain c individually we first have to stop the related grass manager from drawing the grass.
    simply do this by adding another public bool and check this at the top of the DrawGrass() function.
    it might already handle this automatically as it checks:
    if( (TerrainPosition - CamTransform.position).sqrMagnitude > SqrTerrainCullingDist ) {
    return;
    }
    you just have to use another TerrainPosition here which gets updated each frame (TerrainPosition is used by the worker thread to set the grass matrices in world space and must match the position at which the terrain was initialized).

    next we will have to reposition the culling spheres and wipe out all the cell data.
    repositioning the culling spheres should be easy.
    the function RefreshGrassRenderingSettings() contains some code which shows how wiping out the data could be done:

    // Remove already queued cells
    CellsOrCellContentsToInit.Clear();

    and:
    // Clear all currently set CellContents
    // We simply rely on the Update function here, which will generate new CellContents based on the new settings.
    for (int i = 0; i < Cells.Length; i ++) { ... }

    should handle this.

    then theoretically the regular behavior of the grass manager should handle the rest:
    so grass cells get generated when coming into sight.
     
  17. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    50
    Thanks for the suggestion and the time you put into this! You'd be correct, this concept of 3 terrains moving in front of the next is what I'm doing. Although to be honest, I'm pretty confused by your suggestion simply because I'm not much of a programmer, haha. My entire project has been created in Playmaker. That and my knowledge of code is extremely limited. If you think this issue might become a bit of a deep rabbithole of things to modify/fix to get the concept working, it's okay if we abandon it.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    well, it would need some coding... maybe a good point to look into c# :)
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    dear customers,

    this is not really related to ATG – but as it also may increase the immersion of your scene/game i would like to introduce you to Lux Lit Particles which give you rather cheap and real time lit particles receiving real time shadow and proper ambient lighting to make particles fit with the rest of your scene.



    As i always wanted particles to be more grounded i added support for directional light shadow. You will see the difference it makes int the screen shots below.



     
    diamondian likes this.
  20. niflying

    niflying

    Joined:
    Jul 11, 2012
    Posts:
    48
    Hi, Any plans to support HDRP?
     
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    once it is finished, yes.
     
  22. diamondian

    diamondian

    Joined:
    Nov 12, 2018
    Posts:
    3


    I am currently using the 1.09 version , since I put some my modifications in the lib to suit my needs, so , I do not know whether such a potential issue has been fixed or not.

    In case your terrain defines a grass type, but never draw one piece of it on your terrain, meanwhile if you enabled the "compute" then a zero size of compute buffer error will breaks the system, because the "density array" will contains a zero length of sub array , that will cause the problem.

    So you either clear the prototype if its not being used on your terrain, or disable the compute feature, which will slow down your grass system. I been suffering this error for days until I found the reason yestoday. If the issue has been fixed, then nevermind, otherwise, I would be neat if a warning dialog or somthing else that notes the issue or put some additional code into the init process to avoid such situation happens.

    My game is about to release, so I will leave the upgrade to the future and hang with the current version for awhile, but will keep my eyes on this lib and looking forward to the future cool features...

    By theway , the lit particles is awesome! simple enough and easy to use, really boosts my S*** to the next level! will later recommend it in the review.
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    thanks a lot for pointing this out.
    i will have a look into this altho i think that the latest version of the script should already take care of zero length buffers.
     
  24. diamondian

    diamondian

    Joined:
    Nov 12, 2018
    Posts:
    3
    Thanks for you attention, by the way, you might as well take a look the worker thread disposal , since I have encountered a "thread closing error" after I switched to il2cpp to build my game., I managed to suppress that exception by try catch. but it raised an other one...


    IndexOutOfRangeException: Index was outside the bounds of the array.
    at AdvancedTerrainGrass.GrassManager.InitCellContent (System.Int32 cellIndex) [0x00000] in <00000000000000000000000000000000>:0
    at AdvancedTerrainGrass.GrassManager.InitCellContentOnThread () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.Application+LowMemoryCallback.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in <00000000000000000000000000000000>:0
    at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.Application+LowMemoryCallback.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    UnityEngine.Logger:LogException(Exception, Object)
    UnityEngine.Debug:LogException(Exception)
    System.EventHandler`1:Invoke(Object, TEventArgs)
    (Filename: currently not available on il2cpp Line: -1)


    if somthing related has been fixed, never mind then.
    Seems I should give the latest version a go...
     
  25. gavriloP

    gavriloP

    Joined:
    Mar 25, 2018
    Posts:
    4
    Hi, new ATG owner here.
    I'm having the problem with deferred rendering in Unity 2018.3. I've set the ATG deferred shaders correctly in project settings but I still get white grass when using deferred rendering on cameras in demo scene. However if I use forward or legacy deferred (light prepass) mode everything works ok.
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    hi there!
    legacy deferred in this case equals forward :)
    strange however that regular deferred outputs "white grass". how does it look like?
    and do you happen to have any cti driven tree in your project?
     
  27. gavriloP

    gavriloP

    Joined:
    Mar 25, 2018
    Posts:
    4
    I forgot that I did have those BOTD conifers in the same project :) when I created just new project with ATG, it works fine. My problematic project actually has different path to deferred shaders: it says "Hidden/CTI/Internal-Deferred..." in the graphics settings. I wonder what will happen when I use CTI because I have that too...
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    :)
    cti is a subset of atg. but the bodt conifers come with a deferred shader that is derived from the atg (but without atg related code). so unity is clever :( and overwrites the atg shader and replaces it with the cti one although the filenames do not fit.
    simply reimport atg – just the deferred shaders should be fine.
     
  29. gavriloP

    gavriloP

    Joined:
    Mar 25, 2018
    Posts:
    4
    I did more testing with just ATG demo and CTI. When I first import ATG to new project it works fine in deferred. But after I import CTI, it changes the shaders in graphics settings and I can't change them back. This breaks the deferred rendering with grass (totally overblown white and red). But if I first start with ATG like before and then import CTI without ATG shaders that are included with it, everything works fine. I mean just unclicking the shaders from import tree window. ATG Asset reimporting from project view didn't help.

    EDIT: this sounds little bit scary because if I import some stuff to project that has these shaders in and by mistake I don't notice them, will they break the entire project?
     
    gecko likes this.
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    it is a bit scary. i duplicated the shader files years ago. on a different computer. moved them over the network. moved and renamed them in folders. and unity still thinks they are the same.

    i will create new shaders and just copy paste the code for the conifers.
     
  31. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    251
    By the wording of this post I think I might be facing a similar/the same issue at the moment?

    I am getting this error when I try to go to play mode. Grass renders just fine at a certain distance around the starting camera position, but there are many patches of missing grass on the terrain.

    It works fine on other scenes. The errors below point to something with the height and widght of the terrain heights and bilinear filtering. But sadly I am no programmer and do not understand much of this.

    Given that it is only on this map I was also wondering if its related to the post quoted above. I have many more grass types on the terrain, but have no used most of them yet, because the scene is still WIP.


    IndexOutOfRangeException: Index was outside the bounds of the array.
    AdvancedTerrainGrass.GrassManager.InitCellContent (System.Int32 cellIndex) (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:1661)
    AdvancedTerrainGrass.GrassManager.BurstInit () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:1093)
    AdvancedTerrainGrass.GrassManager.Init () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:1042)


    Looks like this:



    Thanks!
     
    Last edited: Apr 1, 2019
  32. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    251
    So as a test I placed down all grass types on the edge of the map and the issue persists.

    It happens with both Compute on and off btw.
     
  33. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    251
    Our programmer took a look at the problem and wrote a quick hack to fix the issue.
    Obviously its just a quick hack to make it possible for me to continue work on the scene, but here it is, just in case you want to see what he did.

    Thanks!

    Code (CSharp):
    1. //  --------------------------------------------------------------------
    2. //  Bilinear sampling from the height array
    3.  
    4.         public float GetfilteredHeight(float normalizedHeightPos_x, float normalizedHeightPos_y) {
    5.         //  NOTE: Using Floor and Ceil each take 0.8ms - so we go with (int) instead
    6.             int normalizedHeightPosLower_x = (int)(normalizedHeightPos_x);
    7.             int normalizedHeightPosLower_y = (int)(normalizedHeightPos_y);
    8.             int normalizedHeightPosUpper_x = (int)(normalizedHeightPos_x + 1.0f);
    9.             int normalizedHeightPosUpper_y = (int)(normalizedHeightPos_y + 1.0f);
    10.  
    11.         //  Get weights
    12.             float Lowerx = (normalizedHeightPos_x - normalizedHeightPosLower_x);
    13.             float Upperx = (normalizedHeightPosUpper_x - normalizedHeightPos_x);
    14.             float Lowery = (normalizedHeightPos_y - normalizedHeightPosLower_y);
    15.             float Uppery = (normalizedHeightPosUpper_y - normalizedHeightPos_y);
    16.  
    17.         //  Adjust x positions to match our array
    18.             normalizedHeightPosLower_x *= TerrainHeightmapHeight; // "* height" as we sample height in the inner loop
    19.             normalizedHeightPosUpper_x *= TerrainHeightmapHeight;
    20.  
    21.             var clamp = normalizedHeightPosUpper_x + normalizedHeightPosLower_y;
    22.             if (clamp >= TerrainHeights.Length)
    23.                 clamp = TerrainHeights.Length - 1;
    24.  
    25.             // NOTE: We simply use "swapped weights" in order to not have to calculate (1 - factor)
    26.             float HeightSampleLowerRow =  TerrainHeights [ normalizedHeightPosLower_x + normalizedHeightPosLower_y ] * Upperx;
    27.                   HeightSampleLowerRow += TerrainHeights [clamp] * Lowerx;
    28.  
    29.             var clamp2 = normalizedHeightPosUpper_x + normalizedHeightPosUpper_y;
    30.             if (clamp2 >= TerrainHeights.Length)
    31.                 clamp2 = TerrainHeights.Length - 1;
    32.  
    33.             float HeightSampleUpperRow =  TerrainHeights [ normalizedHeightPosLower_x + normalizedHeightPosUpper_y ] * Upperx;
    34.                   HeightSampleUpperRow += TerrainHeights [clamp2] * Lowerx;
    35.             return HeightSampleLowerRow * Uppery + HeightSampleUpperRow * Lowery;
    36.         }
    37.  
    38.  
    39.  
    40.  
    41.                 //  Adjust x positions to match our array
    42.                                     normalizedHeightPosLower_x *= TerrainHeightmapHeight;
    43.                                     normalizedHeightPosUpper_x *= TerrainHeightmapHeight;
    44.  
    45.                                     // NOTE: We simply use "swapped weights" in order to not have to calculate (1 - factor)
    46.                                 //  float HeightSampleLowerRow =  TerrainHeights [ normalizedHeightPosLower_x + normalizedHeightPosLower_y ] * Upperx;
    47.                                 //        HeightSampleLowerRow += TerrainHeights [ normalizedHeightPosUpper_x + normalizedHeightPosLower_y ] * Lowerx;
    48.                                 //  float HeightSampleUpperRow =  TerrainHeights [ normalizedHeightPosLower_x + normalizedHeightPosUpper_y ] * Upperx;
    49.                                 //        HeightSampleUpperRow += TerrainHeights [ normalizedHeightPosUpper_x + normalizedHeightPosUpper_y ] * Lowerx;
    50.                                 //  Final bilinear filtered height value
    51.                                 //  tempPosition.y = HeightSampleLowerRow * Uppery + HeightSampleUpperRow * Lowery;
    52.                              
    53.                                 //  To better match the geoemtry (triangles...) we only use 3 sample points and no bilinear sampling.
    54.                                  
    55.                                     float HeightLowerLeft  = TerrainHeights [ normalizedHeightPosLower_x + normalizedHeightPosLower_y ];
    56.  
    57.                                     var clamp = normalizedHeightPosUpper_x + normalizedHeightPosUpper_y;
    58.                                     if (clamp >= TerrainHeights.Length)
    59.                                         clamp = TerrainHeights.Length - 1;
    60.  
    61.                                     float HeightUpperRight = TerrainHeights [clamp];
    62.                                     if( Lower_x > Lower_y) {
    63.                                         // we use the lower right sample
    64.                                         //      11
    65.                                         //      |
    66.                                         // 00---10
    67.                                         float HeightLowerRight  = TerrainHeights [ normalizedHeightPosUpper_x + normalizedHeightPosLower_y ];
    68.                                         tempPosition.y = HeightLowerLeft + (HeightLowerRight - HeightLowerLeft) * Lower_x + (HeightUpperRight - HeightLowerRight) * Lower_y;
    69.                                     }
    70.                                     else {
     
    Last edited: Apr 2, 2019
  34. ChristoKunchev

    ChristoKunchev

    Joined:
    Jun 22, 2019
    Posts:
    8
    Hi @larsbertram1,

    have a Question. Now first, I am a total Noob in Unity. I downloaded and Installed the Grass and have the following Problems. The Full demo doesn`t seem to be working, the Grass is all orange, only the 3D Plants look fine.
    And when I try to create some grass myself and add the Grass manager and Shader, the Grass dissapears in play mode. I am working in Unity 2018.3. Is the Unity version the problem or am I just a total Noob and simply can`t crack it.
    Thanks and have a nice Week :)
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    thanks. and sorry that i haven't answered: unity did not notify me...
     
  36. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    does your camera use deferred?
    and have you assigned the at deferred lighting and reflection shaders? i guess not :)
    atg (usually) only renders in playmode.
    what does "create some grass myself" mean? just painting some more grass onto the terrain?
    painting grass onto a new terrain?
    do you get any errors?
    have you checked debug?
     
  37. ChristoKunchev

    ChristoKunchev

    Joined:
    Jun 22, 2019
    Posts:
    8
    Hi dude,

    thanks for the fast reply, much appreciation here :). My mistake with the demos was that I had already opened them and then after that tried to assign the shaders. While reading your post I realised, I should try this the other way around.
    Now after first assigning the shaders everything seems to work and it looks pretty good.

    I will build a scene again, paint some grass on a new terrain and check if everything is working. I will report the results.
    So thanks again. :)
     
  38. ChristoKunchev

    ChristoKunchev

    Joined:
    Jun 22, 2019
    Posts:
    8
    Hi again,

    so I checked everything. The problem that I have seems to happen when I create either smaller terrains with higher density. For example:

    I create a 5 x 5 meters terrain. Set up the detail resolution per patch to 8, and detail resolution to 1024. Then I paint a little bit of grass and add the grass manager script. The grass doesn`t show at all.
    Console says:
    Max Instances per Layer per Cell: 256
    UnityEngine.Debug:Log(Object)
    Max Bucket Density: 1
    UnityEngine.Debug:Log(Object)

    Sooo any ideas? What am I missing?
    Whenever I create a bigger terrain with less density it works. Only small ones seem to be problematic.

    By the way I wanted to ask you a separate question too. How do you set up your terrain density on large terrains. I tried to copy the settings from your Quickdemo to a terrain of mine with the same width and legth, but Unity still doesn`t let me paint the grass as dense as in your Demos. Do you setup something else outside of the terrain settings?

    Thanks for the help and sorry if I am asking noob questions again. :)
     
  39. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    atg is not made for very small terrains. it simply does not make any sense and would slow down everything :)
    see above.
    the actual reason why you do not see any grass: if the culling result for the grass cells signals that all cells shall be visible atg will treat this as "culling spheres are not set up properly yet" and stop rendering (culling spheres are one frame behind).
    so the grass draw distance must always be smaller than your terrain and the cell size must be small enough so that some cells might be culled.
    if you need very small terrains?! then you would have to edit the script and add a counter: if the culling result signals more than one time that all cells are visible then draw.
     
  40. ChristoKunchev

    ChristoKunchev

    Joined:
    Jun 22, 2019
    Posts:
    8
    Ok, I think I get it now. Thanks a lot the help.

    I also did find a very easy way to get around the problem. I just left the terrain big and added grass only on a very small piece of it. Don`t know why I didn`t think of it earlier. :)
     
  41. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    you are welcome!
     
  42. Murkawski

    Murkawski

    Joined:
    Nov 30, 2014
    Posts:
    48
    I have issues when using multiple terrains. I put the grass manager on all terrains and the grass sometimes doesn't render. Could you provide me with some best practices when using multiple terrains?

    Also, I am moving the terrain from the center, I do not move the center of the world at the moment. Does the asset have any problems with that?
     
    Last edited: Jul 5, 2019
  43. Willbkool_FPCS

    Willbkool_FPCS

    Joined:
    Jun 13, 2018
    Posts:
    143
    I'm having a bit of trouble when using ATG and the Oak trees(and Conifers). The shader that ATG uses doesn't work right with the trees, but if I load the tree shader afterwards then the grass doesn't render properly. Is there a proper order to install these packages to get them to work correctly together?
     
  44. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    how do these issues look like? any errors in the console? or just grass not rendering?
    having multiple instances of the grass manager active at the same time might give you a quite heavy impact as far as memory consumption is concerned. so you should always make sure that there are not more than 4 grass managers active. 4 managers should be enough to draw all grass currently visible.
     
  45. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    import atg after the tree shaders. atg should contain a super set of the translucent lighting functions compared to cti. sorry for that inconvenience.
     
    Willbkool_FPCS likes this.
  46. Murkawski

    Murkawski

    Joined:
    Nov 30, 2014
    Posts:
    48
    The error I get is when I put the grass manager on the terrains:
    NullReferenceException: Object reference not set to an instance of an object
    AdvancedTerrainGrass.GrassManager.Init () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:868)

    When I press play I get this:
    IndexOutOfRangeException: Index was outside the bounds of the array.
    AdvancedTerrainGrass.GrassManager.Init () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:868)

    Max Bucket Density: 0
    UnityEngine.Debug:Log(Object)
    AdvancedTerrainGrass.GrassManager:Init() (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:938)

    Max Instances per Layer per Cell: 0
    UnityEngine.Debug:Log(Object)
    AdvancedTerrainGrass.GrassManager:Init() (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:944)


    The grass just doesn't render. We have a bunch of connected terrains 128x128 in size in the current level, about 25 of them. Each one of them has a grass manager as we use grass on all of the terrains. Sometimes it happens that when I walk onto a certain terrain the rendered grass just disappears. If I don't use the update grass button sometimes the grass doesn't render at all.
     
    Last edited: Jul 8, 2019
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    this happens in the editor?
    try to add these lines before line 867:


    Code (CSharp):
    1. //  Due to ExecuteInEditMode LayerToMergeWith might not be setup by the editor. So we will simply create and fill it.
    2.             if(LayerToMergeWith == null) {
    3.                 LayerToMergeWith = new int[OrigNumberOfLayers];
    4.                 for (int i = 0; i < OrigNumberOfLayers; i++) {
    5.                     LayerToMergeWith[i] = 0;
    6.                 }
    7.             }
    here comes line 867: for (int i = 0; i < OrigNumberOfLayers; i++) {
     
  48. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,431
    that is quite a lot... "128x128" is meters? if so why do you use that many and small terrains?
    various active grass managers do not share resources currently. so each manager will allocate memory for all the needed buffers and arrays as if it was the only one. so 4 active managers should be the max.
     
  49. Murkawski

    Murkawski

    Joined:
    Nov 30, 2014
    Posts:
    48
    Now I'm getting this
    IndexOutOfRangeException: Index was outside the bounds of the array.
    AdvancedTerrainGrass.GrassManager.Init () (at Assets/_AdvancedTerrainGrass/_Scripts/GrassManager.cs:880)

    The script is in the attachment so you can see what's on which line of code
     

    Attached Files:

    • Code.png
      Code.png
      File size:
      301.5 KB
      Views:
      174
  50. Murkawski

    Murkawski

    Joined:
    Nov 30, 2014
    Posts:
    48
    We're using smaller chunks to make use of culling. As I understand unity can cull whole terrain chunks if the chunks are smaller
     
unityunity