Search Unity

[Solved]Instanced grass disappear on file save

Discussion in 'Shaders' started by Guedez, Sep 2, 2017.

  1. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    Webm related: https://webmshare.com/eQqqY

    I process a compute buffer of positions and other parameters, set to a material and draw with
    Code (csharp):
    1. Graphics.DrawMeshInstancedIndirect(baseMesh[lodLevel], 0, material, bounds, argsBuffer, 0, null, shadowCastingMode, receiveShadows);
    When I save a file in visual studio, even when it's on debug mode (which don't let me change an file but shader files), something reloads in Unity and my grass stop working.

    I assume my shaders are being reloaded, and then my compute buffers nuked, but I don't know, because even with all values at zero, some broken grass should be drawing, but it's literally empty.

    Since each block of 8x8x8 have it's own buffers, each of them have their own copy of the base material made with the instanced shader, in case this somehow could be the culprint

    Was a mistake to use compute buffers for this and I should have stuck to images?
     
  2. Guedez

    Guedez

    Joined:
    Jun 1, 2012
    Posts:
    827
    The issue was that the material properties were getting reset.
    Interestingly enough, attempting to queue the value of any property was giving me a
    Code (csharp):
    1. Assertion failed: Material doesn't have a float or range property
    for a single frame, so I just
    Code (csharp):
    1. ___needreload = !material.HasProperty("your_property_goes_here_preferably_as_int");
    At the end of the update, and reset all properties if ___needreload is true at the beginning of the update;