Search Unity

[FREE]MicroSplat, a modular terrain shading system for Unity Terrains

Discussion in 'Assets and Asset Store' started by jbooth, Aug 9, 2017.

Thread Status:
Not open for further replies.
  1. Ivoryjw

    Ivoryjw

    Joined:
    May 20, 2018
    Posts:
    31
    Hello again Mr.Booth.

    I was wondering if I could enable or disable certain microsplat features at runtime.

    For example if someone just wanted more performance, a script would turn off certain features (or modules) in exchange for performance. Or if someone wanted to have the best look possible, then all the features will be turned on.

    Is that possible with microsplat?
     
  2. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    92
    Purchased the texture clusters addon and it said that I had to update Micro Splat. Which I did. And now I get this error:
    I'm using Unity 2017.4.3

    Shader error in 'Hidden/MicroSplat/Terrain TC2_x0_y0_Base-363043497': Surface shader Input structure needs INTERNAL_DATA for this WorldNormalVector or WorldReflectionVector usage at line 1505 (on d3d11)

    Compiling Vertex program with DIRECTIONAL
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_RGBM_ENCODING
     
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You pre-compile several variations of shaders with the features you want and set the one you want to use at runtime.
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Strange - do you get this when enabling a certain feature? You might try reinstalling..
     
  5. kepesh

    kepesh

    Joined:
    Dec 29, 2017
    Posts:
    92
    I copied the shader text from the example file in to my terrain shader file, which got rid of the error. But all the tint colors turned to shades of purple / pink. So I went back to a backup and copied the hex codes for all the colors. So now everything is fine again.

    Another question:
    Would it be possible to steal the terrain shader/material for other objects based on the vertex colors of those objects? Like the mesh blend but it's only based on vertex colors?

    Thanks!
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    MicroSplat uses a texture to store it's splat map data, not vertex colors..
     
  7. Ivoryjw

    Ivoryjw

    Joined:
    May 20, 2018
    Posts:
    31
    Got it. Thanks.
     
  8. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    hi, I think there's an error in the latest package, file: MicroSplatShaderGUI.cs, line 57.
    I think it should be:
    string s = keywords.keywords;

    Regards
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yes, a patch was submitted this morning but hasn’t made it through the store yet. I also posted fixed script files in the discord room. But yeah, that will fix it.
     
  10. TEllard

    TEllard

    Joined:
    Nov 3, 2017
    Posts:
    1
    Hi there. I'm getting this in the latest package, with Unity 2018.3.7f1 Windows 10.

    Assets/MicroSplat/Core/Scripts/Editor/MicroSplatShaderGUI.cs(57,30): error CS0029: Cannot implicitly convert type `System.Collections.Generic.List<string>' to `string'

    Thanks for any advice!
     
  11. Ivoryjw

    Ivoryjw

    Joined:
    May 20, 2018
    Posts:
    31
    Hello again, I'm also getting an error after updating:
    Assets\MicroSplat\Core\Scripts\VegetationStudio\Editor\MicroSplatVegetationStudio.cs(129,28): error CS0115: 'MicroSplatVegetationStudio.DrawPerTextureGUI(int, Material, MicroSplatPropData)': no suitable method found to override

    Edit: I did section of some of the code such as the drawpertexturegui method (which is empty) and this in microsplatshadergui:

    if (renderLoopNames == null || renderLoopNames.Length != availableRenderLoops.Count)
    {
    var rln = new List<GUIContent>();
    for (int i = 0; i < availableRenderLoops.Count; ++i)
    {
    rln.Add(new GUIContent(availableRenderLoops.GetDisplayName()));
    }
    renderLoopNames = rln.ToArray();
    }

    if (renderLoopNames.Length == 1)
    {
    return false;
    }

    int curRenderLoopIndex = 0;
    for (int i = 0; i < keywords.keywords.Count; ++i)
    {
    //string s = keywords;
    for (int j = 0; j < availableRenderLoops.Count; ++j)
    {
    if (s == availableRenderLoops[j].GetRenderLoopKeyword())
    {
    curRenderLoopIndex = j;
    compiler.renderLoop = availableRenderLoops[j];
    break;
    }
    }
    }

    int oldIdx = curRenderLoopIndex;
    curRenderLoopIndex = EditorGUILayout.Popup(CRenderLoop, curRenderLoopIndex, renderLoopNames);
    if (oldIdx != curRenderLoopIndex && curRenderLoopIndex >= 0 && curRenderLoopIndex < availableRenderLoops.Count)
    {
    if (compiler.renderLoop != null)
    {
    keywords.DisableKeyword(compiler.renderLoop.GetRenderLoopKeyword());
    }
    compiler.renderLoop = availableRenderLoops[curRenderLoopIndex];
    keywords.EnableKeyword(compiler.renderLoop.GetRenderLoopKeyword());
    return true;
    }

    This fixed the errors and don't really notice a difference in terms of quality.
    Hope this helps.
     
  12. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    501

    Thanks for this. It works different, perhaps better - but somehow I still can not get the desired results. Not quite sure what the issue could be.
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    The patch to fix this was released on the store this morning..
     
    TEllard and camta005 like this.
  14. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    We want to play some particle effects under the player's feet when the Snow Amount is above a certain amount -- but only under the player's feet (not global value from the material, since snow accumulation is affected by elevation). Is there an good performant way to do that?
     
  15. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You'd have to recreate the shader on the CPU - because snow is affected by the height of the textures, normals, etc. So it really depends on how accurate you need it.

    The other alternative would be to bake out a mask for the snow and sample that - if your snow is static. It would be fairly easy for me to write a debug mode to output this data to a texture- you could even render it to a buffer in real time if you had the perf to do it.
     
  16. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    Hi Jason, in terrain blending asset, I have a model with submeshes that I am not able to blend it properly. I know that the manual says it will only work on the first one, but as you can see, it is selecting the second material instead (wood):

    model.png

    Is this how Unity work or an issue in the shader?
    Thanks
     
  17. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It's just how unity draws things, nothing I can do to control it. If you break this into two meshes, and put the component on both, then it will work..
     
  18. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    no worries, thanks, do you happen to know any hacks to change the order of materials in the mesh renderer field?
     
  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You'd have to write a script to change the order of the submeshes in the mesh data, essentially. Unity doesn't expect it to matter, and just outputs them in whatever order it encounters them I'd bet..
     
  20. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Darn it. And our snow isn't static. We can mostly use the global Snow Amount, but we use elevation to have it accumulate more slowly at lower elevations....do you think it'd be possible to recreate that logic/timing in our code so we can estimate where snow would be appearing at any given moment/?
     
  21. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Sure, depending on how accurate you need it, you can simplify the code. For instance, you can likely get a decent approximation if you just take the world position and vertex normal of the terrain into account- but for perfect you would actually have to sample the height maps of the textures and blend them all to get the surface height and normal, which would be a lot of work. If you look at the code in the microsplat_func_snow.txt to see how it's done.
     
    gecko likes this.
  22. Hallur90

    Hallur90

    Joined:
    Dec 4, 2017
    Posts:
    55
    I'm getting these errors after importing terrain blending.

    error.png

    I see the update button on some of the other modules I have installed, but knowing from experience updating may mess everything up.

    Could it be that this is version incompatibility?

    If not.. any remedies?
     
    Last edited: Mar 7, 2019
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You can't mix versions with MicroSplat modules- if you update to a version, you need to update all of them to that version- otherwise the APIs may have changed between the modules, etc..
     
  24. Hallur90

    Hallur90

    Joined:
    Dec 4, 2017
    Posts:
    55

    Thanks, yeah guess that was bit of a brainfart on my part.
    I updated and imported all the modules and it works fine.

    Out of curiosity can I see the current version of each module somewhere in my project?
     
  25. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    No, but it will show a warning if any module is out of sync in the material (and it still compiles, which isn’t always the case) - and the main version is displayed on the top.
     
  26. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    hi, the advanced details module seems to be broken with the latest microsplat version. is this the right forum to report it?
    Thanks
     
  27. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    That's @wmpunk 's module, so he will have to update it. I actually already updated the code, but I don't have a way to push it to the store since it's his asset.
     
  28. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    I see. is it something complex or you can point me how to fix it? I know it has to do with the MicroSplatKeywords stuff, right?
     
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yes, a few of the module APIs changed, and the keywords are looked up from the scriptable object instead of the material. Should be straightforward to fix; I’d share the code, but I don’t own it.
     
  30. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
  31. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    I can confirm the asset is working fine after the update. Thanks
     
  32. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    320
    Does Microsplat work with the terrain draw instanced feature in 2018.3? When I try it the terrain disappears and I'm just wondering if there is a way to get it working, or if it's not possible.
     
  33. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Yes, you need to run the latest and regenerate the shader (by changing an option) once in 2018.3. Note that unity does not compile tessellation for instancing right now, so that feature must be off.
     
  34. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    Hi Jason, Activating Tesselation when AdvancedDetails are active will produce a NULL reference error in the line indicated below (AdvancedDetails.cs):

    Code (CSharp):
    1. public override void OnPostGeneration(StringBuilder sb, string[] features, string name, string baseName = null, bool blendable = false)
    2.       {
    3.          if (isEnabled)
    4.          {
    5.             var txt = sb.ToString();
    6.  
    7.             var sampleInsertIndex = txt.IndexOf("// ADVANCEDTERRAIN_ENTRYPOINT");
    8.             txt = txt.Insert(sampleInsertIndex, sampleInsert.text + "\n\n");
    9.  
    10.             var tessInsertIndex = txt.IndexOf("// ADVANCEDTERRAIN_TESS_ENTRYPOINT");
    11.             if (tessInsertIndex > 0)
    12.             {
    13.                txt = txt.Insert(tessInsertIndex, tessInsert.text + "\n\n"); <=== ERROR
    14.             }
    15.  
    16.             sb.Remove(0, sb.Length);
    17.             sb.Append(txt);
    18.          }
    19.       }
    Apparently tessInsert is a Microsplat asset that is not being properly assigned before this function is called.

    I'm not sure if this is related to AdvancedDetails or Tesselation module?
    Thanks
     
  35. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    @wmpunk
     
  36. niallmc

    niallmc

    Joined:
    Sep 3, 2015
    Posts:
    44
    Hey, I'm searching for how to edit a per texture property at runtime. I can't find anything on the matter online.
    Essentially I want to edit the 'Tint' property of the 3rd Texture within my microsplat material

    So normally I would use: material.SetColor("MyColor",Color.blue);

    Do you know how I could do this for a pertexture property? e.g: material.SetColor("PerTextureProperty3",Color.blue);


    Many thanks for your help.
     
  37. m506

    m506

    Joined:
    Dec 21, 2015
    Posts:
    93
    Hi, thanks for redirecting the error accordingly. I've managed to get the tesselation working fine by commenting that block, but I don't know the impact it would have.
    The library looks amazing as I expected but of course it comes with a cost. If I want to expose an option to the player to disable tesselation from the terrain, what would be the best way of achieving that during runtime? disabling the feature from the microsplat material or messing around with the tesselation parameters (ie min/max distance)?
    Thanks
     
  38. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Create two versions of the shader and swap them. You can change the option at runtime, because no shader compiler is available in the Unity runtime.
     
  39. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Two possible ways:

    Slow
    - Call SetValue on the PropData object with the index and value you want
    - Call MicroSplatTerrain.SyncAll();

    Fast
    - Get the prop data texture from the material and use SetPixel to set the correct value.

    All pertexture properties in MicroSplat are stored in a lookup table, as this is much more efficient than having thousands of material properties. If you look at the MicroSplatPropData.cs file, there's an index describing what pixel holds which values.
     
  40. niallmc

    niallmc

    Joined:
    Sep 3, 2015
    Posts:
    44
    Thank you for your time, I hate to be a bother but It would be amazing if you could explain the fast method in more detail as I don't think I can figure it out.

    So would I go:

    microSplatMaterial.propData.SetPixel(3,1,Color.Red)

    The microsplatMaterial does not appear to have a PropData Method

    Sorry for being a bother and thanks for such an amazing asset!
     
  41. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    320
    Thanks, yeah I had tessellation on so that was the issue.
     
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You'd grab the texture from the material, and set the pixel on it. Something like:

    Code (CSharp):
    1. Texture2D propData = templateMaterial.GetTexture("_PerTexProps") as Texture2D;
    2.  
    3. int textureIndex = 3; // on 4th texture in the array
    4. int propertyIndex = 1; // tint and interpolation contrast
    5.  
    6. propData.SetPixel(textureIndex, propertyIndex, tintColorAndInterpContrast);
    7.  
     
  43. HiWill

    HiWill

    Joined:
    Jun 2, 2013
    Posts:
    18
    can we set Stochastic sampling per texture?
     
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Not right now- is your reason esthetic or performance? Because of the way shaders work, it would actually be just as expensive to do this per texture as it is to do it all the time. The same is true with triplanar, so when you turn that off per-texture, it still runs the whole triplanar effect and just selects the top projection.
     
  45. niallmc

    niallmc

    Joined:
    Sep 3, 2015
    Posts:
    44
    So hopefully this is my last question.

    When I use:
    propData = microSplatMat.GetTexture("_PerTexProps") as Texture2D;

    propData results in 'null'
    It doesn't seem to recognise a "_PerTexProps" texture on the microsplat material, any ideas on that one?


    Again thanks for your time!
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You could alternatively grab it from the propdata object on the MicroSplatTerrain component instead.
     
  47. niallmc

    niallmc

    Joined:
    Sep 3, 2015
    Posts:
    44
    I have ended up with the following code:

    Color grassAliveColor = new Color.green;

    propData = microSplatTerrain.propData.GetTexture();
    int textureIndex = 1; // on 1st texture in the array
    int propertyIndex = 1; // tint and interpolation contrast
    propData.SetPixel(textureIndex, propertyIndex, grassAliveColor);

    it doesn't throw any error's but it does nothing at all, the microsplat material is not updated. Am I missing something?

    ]
    ]
     
  48. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Well, texture index 1 would be the second texture in the array, not the 1st.. Also, tint has to be enabled on your material.
     
  49. niallmc

    niallmc

    Joined:
    Sep 3, 2015
    Posts:
    44
    yes sorry that's the texture I want to access, the second one, no texture at all is being changed in any way with this. I know this is taking a lot of your time, but thanks for taking a look anyway

    Tint is also enabled
     
    Last edited: Mar 12, 2019
  50. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It's odd that you couldn't grab the texture from the material itself; you could try calling MicroSplatTerrain.SyncAll() afterwards, but you shouldn't have to.
     
Thread Status:
Not open for further replies.