Search Unity

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

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

  1. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    204
    Recently add height-based wetness for shoreline. It looks great, but there are a lot of white dots - looks like specular highlights gone wrong. Picture attached.
     

    Attached Files:

  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Hmm, is this using enlighten or the new progressive lightmapper? I wonder if there's a way to trick it into using the correct shadow casting pass..
     
  3. Vagabond_

    Vagabond_

    Joined:
    Aug 26, 2014
    Posts:
    933
    This is with the Progressive Lightmapper !
    Any way of tricking or hacking it would be welcome !
    I am not a graphics programmer and could not deal with such thing !
     
  4. mmaclaurin

    mmaclaurin

    Joined:
    Dec 18, 2016
    Posts:
    204
    Wanted to clarify that this is a bug report :) I think.
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Maybe; hard to say without seeing the texture data. What wetness does, effectively, is darken the albedo and increase the smoothness of the texture based on the porisity and existing smoothness/metal values of the textures.
     
  6. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    I'm having trouble with the terrain blending module. I have an 8x8 set of terrain tiles (created with Terrain Composer 2), with a Microsplat material/shader set up on them. I've enabled Terrain Blending on the shader, and generated terrain descriptor data. But when I add the Microsplat Blendable Object component to the mesh sitting on the terrain, it says "Terrain shader is not setup for blending, please enable this on the terrain material in the Shader Generator section." I've toggled that off and on again on the MS material, no help.

    But then I created a new terrain in that same scene and it works great. So it seems like the problem is because I've got this 8x8 set of terrains, all using the same MS material/shader...? Any ideas?

    Using Unity 2017.3.1 on Mac 10.12.6, Metal editor not enabled.

    thanks
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    I've had a few people with 'jiggle the handle' issues like this in the last few months, but have not been able to find out exactly what is going wrong for them. My suspicion is that some information gets incorrectly cached somehow, or that it cannot find the blendable object shader for some reason, but I haven't been able to figure out how to get it into this state myself. I do note that TC2 has been used in the 3 cases I've seen with this, so perhaps some interaction between the two? Was there a specific action you did before it started happening or anything like that?
     
  8. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    It's a pretty fresh scene: I've been setting up TC2 nodes, then Microsplat and now some rocks. I've tried duplicating one of those TC2 terrain tiles and moving it out of the TerrainArea folder in the hierarchy, to try to disassociate it from TC2, but that didn't help.

    Oh, I did notice one thing: On the terrain where it doesn't work, under Terrain Descriptor Data Memory: 8192kb, it says:
    Blendable Material: None (Material)

    Whereas on the terrain where it does work, that isn't there. Useful?
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Yes- I'd have to look at the code, but I believe it shows certain fields if it cannot find them so you can assign them.
     
  10. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    Ah, okay -- so I found a "BlendableObject Map1Terrain_x4_y4" material in my project -- so I assigned that to that slot and now terrain blending works! On all terrain tiles (or at least, on several of them that I've tried).

    This the only BlendableObject material in my project, and the name and datestamp indicate it's from another scene/terrain where I was also having trouble with terrain blending (but figured I'd wait and try it again with a new scene before I complained). So does it matter that this is from a different scene/terrain, or do I just need a single such material and use it in all scenes/terrains?
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Well, it should be the material in your MicroSplatData directory for the terrains that share that setup.. But come to think of it, it might not really matter that much which one it is, since the component fetches the data it needs anyway..
     
  12. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    it's not. It's in a folder for that other scene/terrain -- actually, that looks like a test terrain, not even the real terrain tile set I'm using in the other scene.. I guess maybe the problem is that it isn't getting generated with these TC2 tile sets, but somehow I did manage to generate one at some point. So is that material reusable for all terrains, or is there something specific per-terrain in it?
     
  13. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    786
    What is the correct way to fork a scene with a MicroSplat terrain? That is, how do I make a copy of an existing scene pointing to entirely separate assets, making changes to this newly created scene completely independent from the old one.

    I know I can copy terrain data file and reference the duplicate in the Terrain component to decouple terrain itself from the data used in a previous scene, but I don't know what to do with all these files created and managed by MicroSplat:

     
  14. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Why not just set it up fresh? What are you trying to share across the different versions of the scene?
     
  15. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    786
    Not really trying to share anything - on the opposite, I'm trying to disconnect everything. I'm trying to create a new version of the scene while keeping the previous one intact and completely disconnected from the new one. Re-dragging every single map reference into MicroSplat and replicating all the custom layer setting would take hours, so I'm interested in copying and re-linking MicroSplat files.

    Real case - I'm making several versions of a scene with slightly modified terrains, as we're deciding on the level design direction and want to evaluate a few variants at once. The new scenes are produced by duplicating terrain data, linking those duplicates to Terrain component and saving scenes as new files. That's the extent of what has to be done when MicroSplat isn't used.

    Forked scenes can contain, for example, some deformations (e.g. damage after bombing, craters etc.) and some changes to texturing layers. Right now, I can't modify MicroSplat configuration without breaking the look of the previous scene. Ideal workflow would be to know how to safely duplicate MicroSplat entities and relink those copies to my new scene, allowing me to change whatever I need without the need to reconfigure MicroSplat from scratch and without corrupting the old scene.
     
    Last edited: Apr 3, 2018
  16. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    The easiest is likely to make a copy of all your terrain data, save the scene in a new location, remove and re-add MicroSplat. You can then copy the texture array config, material, propdata, and shader from the old scene over the newly created one..
     
  17. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    786
    Thanks, that worked well!
     
  18. SimLoop

    SimLoop

    Joined:
    Jun 17, 2013
    Posts:
    25
    Question? I tried MicroSplat Core on my terrain and got some strange results. See attached images.
    Using Unity 2017.3.1f1
    Any ideas/suggestions?
    -Rob
     

    Attached Files:

  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Looks like your global texture scale is set to tile the textures a ton? Try changing it in the material settings..
     
  20. erenaydin

    erenaydin

    Joined:
    Mar 1, 2011
    Posts:
    366
  21. erenaydin

    erenaydin

    Joined:
    Mar 1, 2011
    Posts:
    366
    Is there a way to detect which stream or puddle is painted on any terrain position?
    I mean i want to kill the players if it's touch the lava. I can paint under the lava with killer texture id but on puddle, I want to make a water splash at a footstep.
     
  22. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    You can read that data from the texture which is created for the effect, which can be found on each MicroSplatTerrain component or from the material instance on the terrain.

    For static painting, the RGBA channels are weights for each effect. For dynamic effects, there are two buffers which is swaps between (You can see an example of how I read/display this data in the editor code)

    To get it exact, you'll want to compare this data with the height value of the texture on that terrain position.
     
    erenaydin likes this.
  23. erenaydin

    erenaydin

    Joined:
    Mar 1, 2011
    Posts:
    366
    I never thought it would be so simple. Done in 10 minutes. Thanks.
     
  24. antoripa

    antoripa

    Joined:
    Oct 19, 2015
    Posts:
    1,162
    Power of integration

     
    boysenberry likes this.
  25. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    I've got a little problem with the Terrain Blending module -- I'm putting rocks on steep slopes, and the blending is too high on the mesh. Maybe it's calculated from the middle of the mesh, not the surface? Screenshot shows it better than I can explain,. Any way I can adjust that downward?

    Also, it's awfully streaky. Looks great on angled-intersecting meshes, but it's like this on all the vertical intersections. I have Anti-Tiling (everything) and Triplanar (Height blended), but there are no options in the MS material to disable those on terrain-blended meshes.

    thanks!

    blending.png
     
  26. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    There's parameters to control how high up the mesh, the normal bias, etc, all on the terrain blending component that's on the object.
     
  27. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    yeah, i know -- but they don't help. The blending is too high on the mesh -- if I reduce the height, it shrinks but in this case towards the centerline of the blending, not to the bottom of the mesh. You can see in the screenshot that the blending doesn't even reach the bottom of the mesh. The whole thing seems offset from the bottom of the mesh. Here it is with Blend Distance of 0.1. blend distance .1.jpg
     
  28. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Oh, interesting- Did you try regenerating the terrain descriptor? Also make sure the texture that it creates is set to bypass sRGB. It should match exactly..
     
  29. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    I'm sure I had regenerated it just before posting (and sRGB is not checked), but I regenerated it a few more times, and now it's much better -- still off a bit but I can easily see how that's just due to the limits of the descriptor image's resolution.

    But the streaking is still pretty bad. I should have some options for anti-anti-tiling and triplanar, right? But I don't -- there's nothing nested under Terrain Blending row in the material inspector.

    blending2.jpg
     
  30. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Terrain blending performs the same techniques as the terrain shader, otherwise it wouldn't match- so if the terrain is triplanar, so is the blend. There is, however, a normal bias that controls the lighting between the two surfaces (since in this case, one is facing sideways while the other surface is facing up). Since triplanar uses the normal to determine the projection, the normal bias also controls how fast the blend happens between the two surfaces for the projection as well.
     
  31. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    Okay, but the manual says:

    When the Anti-Tiling module is installed and Detail Noise, Distance Noise, or Distance Resampling are enabled, options are available under the Terrain Blending option to disable each of these features on the blending shader. This is primarily useful with Triplanar Texturing enabled, as these features use standard UV mapping, and may cause streaking issues when blending on vertical surfaces.


    And I'm not seeing those options to disable anything.
     
  32. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Ok, I'll test tonight and see if they still show up for me- are you using the individual features of the anti-tile module, or the texture array based ones?
     
  33. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    I'm using all the options in the anti-tile module, but not using texture array at all (too many samplers).
     
  34. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Well, the texture array version actually saves samplers since it combines several separate features into one. Also let’s you specify the textures per terrain texture, which is nice, but increases bandwidth use and memory..
     
  35. Kappytn

    Kappytn

    Joined:
    May 22, 2017
    Posts:
    8
    Hi, I just bought Terrain Blending for Micro-splat but it is refusing to work on any projects. Every time I import it, it gives me this error:

    "Assets/MicroSplat/TerrainBlending/MicroSplatBlendableObject.cs(115,39): error CS1061: Type `MicroSplatTerrain' does not contain a definition for `GetBlendMatInstance' and no extension method `GetBlendMatInstance' of type `MicroSplatTerrain' could be found. Are you missing an assembly reference?"

    It doesn't show up under Shader Generator either. Is there any way I can fix this?
     
  36. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    do you have core installed?
     
  37. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    584
    Hi, I have still dark wind color at night. Not sure there is a solution already made for this issue. The environment lighting ambient color does not have any impact on the wind. Even if the 'sun' directional light has a sharp angle to the terrain, the wind color turns to black. Do you have any idea how to handle this?
    If not, I have to check the sun angle and have to make the wind color more transparent or more brighter, if needed. This would then be a kind of hack... The wind feature brings a lot of details in the environment, especially for top down games, cannot without anymore. ;)

    It think the wind color should act like the terrain to the lights, else the colors will be too different.

    bandicam 2018-04-08 14-06-28-250.jpg
     
    Last edited: Apr 8, 2018
  38. Kappytn

    Kappytn

    Joined:
    May 22, 2017
    Posts:
    8
    I do, yes.
    upload_2018-4-8_23-27-16.png
     
  39. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Try reinstalling from scratch- that method is definitely in core..
     
  40. Kappytn

    Kappytn

    Joined:
    May 22, 2017
    Posts:
    8
    Thank you, it works now :)
     
  41. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    584
    Hi, I updated the MicroSplatBlendableObject to handle LODGroups, just the sync() method must be modified. Unfortunatelly I found out that the speedtrees have sub-meshes and this error message appears "Sub-Meshes cannot not blend properly, only the first submesh will blend with the terrain.". Just one mesh gets the blending, in my case not the bark. Could this be somehow improved? Not sure what the reason for this limitation is. If the reason is, that all the meshes start blending at the bottom of the mesh and so the blending must be controlled for each of the sub-meshes separatelly, then let us at least select the mesh we want to blend or allow us to blend each sub-meshes manually.

    Code (CSharp):
    1. public void Sync()
    2.     {
    3.         List<Renderer> renderers = new List<Renderer>();
    4.         LODGroup lodg = GetComponent<LODGroup>();
    5.         if (lodg) {
    6.             LOD[] lods = lodg.GetLODs();
    7.             foreach (LOD lod in lods) {
    8.                 foreach (Renderer rend in lod.renderers) {
    9.                     renderers.Add(rend);
    10.                 }  
    11.             }
    12.         } else {
    13.             Renderer r = GetComponent<Renderer>();
    14.             if (r)
    15.                 renderers.Add(r);
    16.         }
    17.      
    18.         if (renderers.Count == 0) {
    19.             Debug.LogError("MicroSplatBlendableObject: No renderer found in LOD group or on the GameObject.");
    20.             return;
    21.         }
    22.         #if UNITY_EDITOR
    23.         // If we have a terrain, we might be moved over another terrain. So lets see if we're in the bounds of our current terrain
    24.         // and if not, clear it and try to get a new one..
    25.         bool testForNewTerrain = false;
    26.         if (msTerrain != null)
    27.         {
    28.             Terrain t = msTerrain.GetComponent<Terrain>();
    29.             if (t && t.terrainData != null)
    30.             {
    31.                 Renderer rend = GetComponent<Renderer>();
    32.                 var tbounds = TransformBounds(t.terrainData.bounds);
    33.              
    34.                 Bounds bounds = new Bounds();
    35.              
    36.                 for (int i = 0; i < renderers.Count; i++) {
    37.                     Renderer renderer = renderers[i];
    38.                     if (i == 0)
    39.                         bounds = renderer.bounds;
    40.                     else
    41.                         bounds.Encapsulate(renderer.bounds);
    42.                 }
    43.              
    44.                 if (!tbounds.Intersects(bounds))
    45.                 {
    46.                     testForNewTerrain = true;
    47.                 }
    48.             }
    49.         }
    50.         if (msTerrain == null || testForNewTerrain)
    51.         {
    52.             RaycastHit[] hits = Physics.RaycastAll(this.transform.position + Vector3.up * 100, Vector3.down, 500);
    53.             for (int i = 0; i < hits.Length; ++i)
    54.             {
    55.                 var h = hits[i];
    56.                 var t = h.collider.GetComponent<Terrain>();
    57.                 if (t != null)
    58.                 {
    59.                     var nt = t.GetComponent<MicroSplatTerrain>();
    60.                     if (nt != null)
    61.                     {
    62.                         msTerrain = nt;
    63.                         break;
    64.                     }
    65.                 }
    66.             }
    67.         }
    68.         #endif
    69.      
    70.         Material bmInstance = msTerrain.GetBlendMatInstance();
    71.         if (msTerrain == null && bmInstance)
    72.             return;
    73.      
    74.         foreach (Renderer r in renderers) {
    75.             var materials = r.sharedMaterials;
    76.             bool hasBlendMat = false;
    77.             for (int i = 0; i < materials.Length; ++i)
    78.             {
    79.                 if (materials[i] == bmInstance && bmInstance != null)
    80.                 {
    81.                     hasBlendMat = true;
    82.                     break;
    83.                 }
    84.                 else if (materials[i] == null || materials[i].IsKeywordEnabled("_TERRAINBLENDING"))
    85.                 {
    86.                     hasBlendMat = true;
    87.                     materials[i] = bmInstance;
    88.                     r.sharedMaterials = materials;
    89.                 }
    90.             }
    91.          
    92.             if (!hasBlendMat)
    93.             {
    94.                 System.Array.Resize<Material>(ref materials, materials.Length + 1);
    95.                 materials[materials.Length - 1] = bmInstance;
    96.                 r.sharedMaterials = materials;
    97.             }
    98.  
    99.             if (props == null)
    100.             {
    101.                 props = new MaterialPropertyBlock();
    102.             }
    103.  
    104.             props.SetVector("_TerrainBlendParams", new Vector4(blendDistance, blendContrast, msTerrain.transform.position.y, blendCurve));
    105.             props.SetVector("_SlopeBlendParams", new Vector4(slopeFilter, slopeContrast, slopeNoise, normalBlendDistance));
    106.             props.SetVector("_SnowBlendParams", new Vector4(snowWidth, 0, 0, 0));
    107.             props.SetVector("_FeatureFilters", new Vector4(doTerrainBlend ? 0.0f : 1.0f, doSnow ? 0.0f : 1.0f, 0, 0));
    108.             r.SetPropertyBlock(props);
    109.         }
    110.     }
     
  42. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,042
    Yeah, it's tempting, and it would let me drop the max texture count, but I'd still really want the Anti-Tile Array so I'm still up two samplers, and I'd rather use those on other awesome Microsplat features.

    Anyways, here's what I see when I enable Terrain Blending with Anti-Tile -- no sub-options to reduce streaking on vertical meshes. Should there be?

    blending antitile.png
     
  43. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    This is unfortunately a restriction of how Unity handles extra materials on a mesh. It assumes that you have 1 material per mesh, and if you have more, it draws them on the first mesh.
     
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    I suspect that it's not showing when you use the array version, but I'll check it next time I'm in the project and see if it's just some minor editor thing I forgot to expose..
     
  45. cassidyEline

    cassidyEline

    Joined:
    Apr 19, 2017
    Posts:
    1
    Ctrl + Z isn't working for me to undo terrain painting with Microsplat which creates issues for effiency of workflow for me. Is there a fix for this or a different key bind? Is there a way to turn it on or change the key bind?
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    That is entirely Unity's painting system, not mine..
     
  47. ellioman_flashbulb

    ellioman_flashbulb

    Joined:
    Jan 17, 2017
    Posts:
    7
    Heyhey,

    We recently got MicroSplat and bought some extra modules. I have a question regarding changing settings in runtime.

    In our game we change various settings depending on what graphics settings the user has selected and would like to extend that for some things in MicroSplat. Things like turning off tesselation, parallax mapping, Triplanar, etc.

    Is this possible? If yes, how would one go about doing that?
     
  48. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Generate several different shaders and swap the shader on the template material, then call MicroSplatTerrain.SyncAll()
     
    ellioman_flashbulb likes this.
  49. Adam_Starcaster

    Adam_Starcaster

    Joined:
    Dec 7, 2012
    Posts:
    36
    Having errors with Terrain Blending, every time we import a package it does this, and even updating Terrain Descriptor Data does not update the object. Also adds a material obviously that is always broken. Any advice?
    upload_2018-4-11_17-24-40.png
     
  50. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Looks like the shader has an error, which should display in the logs or when you select the shader.