Search Unity

Procedurally generated grass details not appearing in standalone build of 2019.1

Discussion in 'World Building' started by easmussen, Jun 13, 2019.

  1. easmussen

    easmussen

    Joined:
    Aug 1, 2013
    Posts:
    4
    Hello, I'm on Unity 2019.1.5f1, in a project that I recently upgraded from Unity 2017. Ever since I upgraded, my grass isn't appearing in standalone builds anymore.

    After a number of tests, it seems that any grass created at runtime using "SetDetailLayer" will not appear anymore in standalone builds. (It does appear in the editor just fine). I'm able to reproduce this in a fresh, simple project.

    I'm not using any custom rendering pipelines or anything. Grass will appear in the standalone if it's part of the terrain data prefab.

    My main project shows this error message (although the small test case I created does not, but has the same issue, so it may be a red herring): "Detail rendering shaders not found for the active render pipeline, falling back to default shader"

    Is there something obvious I am missing to get this to work? I opened a bug (1162582) on this just in case.

    Here's my grass generation code - again this works fine in the Editor, but not in Standalone builds.

    Code (CSharp):
    1. void Start()
    2.     {
    3.         GameObject go = (GameObject)Instantiate(terrainPrefab);
    4.         Terrain terrain = go.GetComponent<Terrain>();
    5.  
    6.         DetailPrototype detailPrototype = GrassPrototypeForTexture(grassSprite, 2f, new Color(.22f, .61f, .16f, 1f), new Color(.18f, .70f, .12f, 1f));
    7.  
    8.         TerrainData terrainData = new UnityEngine.TerrainData();
    9.         terrain.terrainData = terrainData;
    10.  
    11.         terrainData.detailPrototypes = new DetailPrototype[1]{detailPrototype};
    12.         terrainData.wavingGrassSpeed = .92f;
    13.         terrainData.wavingGrassAmount = .35f;
    14.         terrainData.wavingGrassStrength = .67f;
    15.         terrainData.wavingGrassTint = new Color(.45f, .45f, .45f, 1f);
    16.  
    17.         terrain.GetComponent<TerrainCollider>().terrainData = terrainData;
    18.  
    19.         terrainData.SetDetailResolution(64, 8);
    20.         int size = 64;
    21.         int[,] details = new int[size, size];
    22.         for (int x = 0; x < size; ++x)
    23.         {
    24.             for (int y = 0; y < size; ++y)
    25.             {
    26.                 details[x,y] = 15;
    27.             }
    28.         }
    29.  
    30.         terrainData.SetDetailLayer(0, 0, 0, details);
    31.  
    32.  
    33.     }
    34.  
    35.     public static DetailPrototype GrassPrototypeForTexture(Texture2D tex, float scale, Color dryColor, Color healthyColor)
    36.     {
    37.         DetailPrototype detail = new DetailPrototype();
    38.         detail.usePrototypeMesh = false;
    39.         detail.prototypeTexture = tex;
    40.         detail.dryColor = dryColor;
    41.         detail.healthyColor = healthyColor;
    42.         detail.noiseSpread = 5f; // Determines how big the clumps of dry / healthy grass are
    43.         detail.minWidth = .5f * scale;
    44.         detail.maxWidth = .75f * scale;
    45.         detail.minHeight = .35f * scale;
    46.         detail.maxHeight = .75f * scale;
    47.         detail.renderMode = DetailRenderMode.GrassBillboard;
    48.         return detail;
    49.     }
     
    Last edited: Jun 13, 2019
  2. easmussen

    easmussen

    Joined:
    Aug 1, 2013
    Posts:
    4