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. Sovcenko

    Sovcenko

    Joined:
    Apr 17, 2018
    Posts:
    2
    Dear Jason, first of all, Microsplat is awesome. Thank you.
    That being said, I kinda need to get a toony/cell shading effect on my game. I saw your "low poly" asset, but I need to achieve another kind of rendering (like Borderlands for the obvious example). I have some basic knowledge in shader, but not enough to goes blindly into your code.
    - Is there a way to change the "contrast" of the light/shadows ? To sharpen the shadows ?
    - Is there a way to add some global quantization effect without post-processing, into the terrain directly ?
    - Is there a way to add an outline on the terrain without post-processing ?

    Thank you again.
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Depending on how lighting is done (baked, realtime), you can modify the shadow maps or shadowing shaders in unity to get different results. Generally, outlines and quantization is going to be better handled in post processing, why do you want to do it directly in the terrain shader? Outlines on specific objects usually involve drawing the object more than once which can be bad for performance (you draw it expanded slightly as black, then draw it again over itself).
     
  3. Blarghle

    Blarghle

    Joined:
    Aug 19, 2014
    Posts:
    15
    Hi Jason, this is a wonderful tool, a sorely needed component for unity's terrain system right now.
    I've been working with splatmaps generated from World Machine and importing them onto the terrain, but which texture layers correspond to which splatmap channel is unclear. Right now I'm importing two splatmap .tgas, with a splatmap loaded into each channel of each texture, for 8 splatmaps total.

    I assume I have to mirror the texture layer order with the splat map channel order?
    Which splatmap channel gets assigned to which texture layer?
    It would be very useful to be able to assign channels to texture layers from within the inspector, it would cut back on a lot of photoshop channel shuffling for large groups of terrains with many layers. If not, labelling them would be quite useful.

    I've also seen a few bugs with LWRP support, for instance enabling per-pixel normals in the material breaks the shader in a way it can't recover from. The terrain disappears and disabling per-pixel normals doesn't bring it back. Replacing the material file with a fresh one is the only thing I've found that will recover it.

    My unity version is 2019.2.3f1, using LWRP 6.9.1

    EDIT: I just realized that the reason I'm having trouble figuring out the layer order is because it doesn't look like it's using the second splatmap texture at all.
    I imported two debug splat maps to my terrain, and changed all my texture layers to rgb colors. The debug splat maps are text labels in each channel of each texture, ie R1, G1, etc. The textures appear to load in flipped on both axis, which isn't a huge deal, but the last four of my 8 materials don't display at all. I've updated my texture array, and both splatmaps appear to be attached to my terrain properly. I get one of the "Duplicate basemap name: '_MainTex'. Ignoring" errors, maybe that's related. Am I doing something wrong?
    Capture.PNG Capture2.PNG Capture3.PNG
     
    Last edited: Sep 10, 2019
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Splat maps are RGBA format, if you leave the alpha out it will default to 1, which would make the fourth texture get a weight of 1.
     
  5. ncho

    ncho

    Joined:
    Feb 1, 2014
    Posts:
    89
    Is there an option to control mipmapping the same way as with the standard Unity shader? At least I can't find any options regarding it...
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    What do you mean?
     
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,520
    For custom splat maps, is the math for uv localtoworld and worldtolocal the same as when using unity's splats?
     
  8. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,520
    Jumbled a few things into a single file as I have more abstraction around it, but hopefully this is useful.

    It's a simple abstraction around working with custom splats. Couple of utility functions for converting to colors and back. Threw in a localtoworld and worldtolocal also as static methods.

    https://gist.github.com/gamemachine/b2e33112c4b173f868b37bbb47ef9b63
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Yes, the only difference is which textures are used to look up the weights.
     
  10. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,520
    A terrain flipping module would be nice FYI. Only took a few minutes to hand modify the shader to support that (shadows no idea), but I'd pay a few bucks just to not have to customize your shader generation pipeline.
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Terrain flipping?
     
  12. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,520
    For caves and underground areas. Works pretty well actually. Cull front flip normals and after modeling invert heightmap.
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Would be pretty easy to add your options to a module - Doesn't seem like the kind of thing the average user would use, but could be given away open source or free or something.. Throw me a diff of your changes and an example scene showing it off and I'd setup the module code..
     
    Last edited: Sep 20, 2019
  14. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,542
    @jbooth : I just got Microsplat last month and haven't had a chance to use it until today.
    But I'm having a problem. If I tick UV Scale, no matter what numbers I give the UV's the entire terrain goes blurry.
    upload_2019-9-22_4-15-32.png upload_2019-9-22_4-15-47.png
    upload_2019-9-22_4-18-6.png


    No matter what i set the number too the result stays exactly the same.
    I'm using Map Magic, so not sure if that's the culprit (the third thumbnail shows the error for map magic). I know Map Magic isn't your product, just wasn't sure if it was important to list the error for you as I'm not sure if it's related - I followed the MM dev's video tutorial on how to make it work. Which everything works fine, so far everything works fine except turning on UV Scale, then the terrain blurs out entirely.

    EDIT: It turns out all the per texture properties aren't working at all.
    For example if I tick "tint" the entire terrain goes a super dark gray nearly black.

    I saw someone in the last page mention per texture properties weren't working for them and you said to check the propData, well I click the on "MarsMaterial_propdata" and it's simply just empty.

    Edit 2: I also purchased the mesh and terrain blending feature earlier and it's not working correctly.

    I go into the material for the terrain and enable the blending options then I put on the Micro Splat Blendable Object script onto my test cube and it goes purple and gives an error saying ("Terrain shader is not setup for blending, please enable this on the terrain material in the Shader Generator section").

    Edit 3: I can confirm it works properly on your demo scene.
     
    Last edited: Sep 22, 2019
  15. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,542
    Nevermind I got it working, it was a glitch in the Map Magic Custom Shader output node, I just removed it and replaced it and bam worked.

    @Wolfos ^^^ Not sure if you're using Map Magic, but if you are, this might be your issue. as none of my Per Texture properties were working until I did that.

    (NOTE: @jbooth Blendable objects still don't work).
    Ahh I see why it didn't work, but this begs the question, is this doable with Map Magic? Because I want to utilize the realtime generation. I can't go in and press "Generate Terrain Descriptor Data" by hand if it's randomly generated with Map Magic.
     
    Last edited: Sep 22, 2019
    protopop likes this.
  16. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    743
    Nah, the propdata object (on the microsplat terrain script > debug > per texture data) was incorrectly assigned.
     
  17. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,542
    Ah okay, glad you got it mate :)
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    The right solution would be to have map magic node generate this data, as it has the heights and normals already, it would just need to write them to a texture for the blending data.
     
    mmaclaurin likes this.
  19. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,542
    Thank you. I'll attempt to give it a shot I suppose.
     
  20. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    216
    Hey there,

    If I own all the addons for Microsplat would it be possible to get a key for the bundled version? Just to make importing easier, as importing the 11 independent modules takes a bit more time
     
  21. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    There’s not really a way to do this within the store system. We get vouchers, but only a dozen per year.
     
  22. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    216
    Darn D:
     
  23. juiced12

    juiced12

    Joined:
    Nov 8, 2018
    Posts:
    24
    I've purchased the procedural texturing add on, however I'm not able to bake the procedural to terrain. I'm getting a shader error but I'm not experienced with the shader language.

    Error:

    "Shader error in 'Hidden/MicroSplat/RenderBake_ProceduralSplatOutput0A': Fragment program 'frag_surf': Unrecognized sampler 'sampler_diffuse' - does not match any texture and is not a recognized inline name (should contain filter and wrap modes)."

    Anyone have any ideas?

    Thanks
     
  24. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Yeah, this happens on Windows. Best I can tell it's some kind of internal compiler error where it changes the sampler name from sampler_Diffuse to sampler_diffuse for no reason. Still trying to find a hack around it..
     
  25. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,210
    This is a MapMagic + MicroSplat question thought id ask here - I can see the two together are popular and im not surprised because Microsplay makes Mapmagic terrain look great.

    Ive almost tracked down this issue. Using MicroSplat with MapMagic and the MicroSplatMapMagicSync.cs file to sync it across all terrains. this works great in Unity 2019.2 on Mac

    The issue is on iOS. I get an error that sounds like the MicroSplat instance on newly generated terrain isn't appearing, so there's a null reference. It means that some of the terrains generate but just as flat terrain, while other ones generate just fine.

    NullReferenceException: Object reference not set to an instance of an object.

    at MicroSplatTerrain.Sync () [0x00000] in <00000000000000000000000000000000>:0
    at MicroSplatTerrain.SyncAll () [0x00000] in <00000000000000000000000000000000>:0
    at MapMagic.MapMagic+ChangeEvent.Invoke (UnityEngine.Terrain terrain) [0x00000] in <00000000000000000000000000000000>:0
    at MapMagic.GeneratorsAsset+<Apply>d__13.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    at MapMagic.Chunk+<ApplyRoutine>d__40.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    at MapMagic.ThreadWorker.CoroutineFn () [0x00000] in <00000000000000000000000000000000>:0
    at MapMagic.ThreadWorker.UpdateApply () [0x00000] in <00000000000000000000000000000000>:0
    at MapMagic.ThreadWorker.Refresh () [0x00000] in <00000000000000000000000000000000>:0​

    I feel like im so close to the solution but can't quite get it and im hoping smarter minds may have an idea. Ive pretty much narrowed it down to the MicroSplatMapMagicSync.cs file (which is a very simple file) because I can use MicroSplat on a single terrain no problem (looks great) - its just with the syncing across some new terrains it seems to be missing. often in conjunction with an error like
    Right neighbor of the terrain has a different heightmap resolution. Stop neighboring.
    Which I am not sure is related but I mention it because maybe that is related to why some terrains on the grid generate and some stay flat.

    For reference here's the sync script im using

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using JBooth.MicroSplat;
    5.  
    6.  
    7. namespace EternalLife
    8. {
    9.     public class MicroSplatMapMagicSync : MonoBehaviour
    10.     {
    11.         public Material MicrosplatMaterial;
    12.         public MicroSplatPropData PropData;
    13.  
    14.         public void Start()
    15.         {
    16.             MapMagic.MapMagic.OnGenerateFailed -= MapMagic_OnGenerateFailed;
    17.             MapMagic.MapMagic.OnGenerateCompleted -= MapMagic_OnGenerateCompleted;
    18.  
    19.             MapMagic.MapMagic.OnGenerateFailed += MapMagic_OnGenerateFailed;
    20.             MapMagic.MapMagic.OnGenerateCompleted += MapMagic_OnGenerateCompleted;
    21.         }
    22.  
    23.         private void MapMagic_OnGenerateCompleted(Terrain terrain)
    24.         {
    25.             MicroSplatTerrain mst = terrain.GetComponent<MicroSplatTerrain>();
    26.             if (mst == null)
    27.             {
    28.                 mst = terrain.gameObject.AddComponent<MicroSplatTerrain>();
    29.             }
    30.             mst.templateMaterial = this.MicrosplatMaterial;
    31.             mst.propData = this.PropData;
    32.             MicroSplatTerrain.SyncAll();
    33.         }
    34.  
    35.         private void MapMagic_OnGenerateFailed(Terrain terrain)
    36.         {
    37.             Debug.Log("Generation failed for terrain: " + terrain.name);
    38.         }
    39.  
    40.         public void OnDestroy()
    41.         {
    42.             MapMagic.MapMagic.OnGenerateFailed -= MapMagic_OnGenerateFailed;
    43.             MapMagic.MapMagic.OnGenerateCompleted -= MapMagic_OnGenerateCompleted;
    44.         }
    45.     }
    46. }
     
  26. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,210
    I just found out that mapmagic has a custom shader node we can use for microsplat instead of the script I’ve been using. I’m going to try it out and see if it solves the problem
     
  27. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    412
    Yes if I remember correctly, the sync script was the old/inofficial way. Then MM added MS support to the custom node later on.
     
    protopop likes this.
  28. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,210
    It works:) It runs really fast nd MicroSplat looks amazing in MapMagic.

    For anyone it helps I stopped using the old sync script that is floating around and used this MapMagic tutorial for integrating Microsplat natively

     
    iddqd likes this.
  29. Creepgin

    Creepgin

    Joined:
    Dec 14, 2010
    Posts:
    362
    @jbooth Has the baking feature for procedural texturing module ever worked on Windows (since the release in April)? I'm also waiting on a fix on this. But if it's going to take awhile, you may want to clarify/put a disclaimer about this feature in the asset description to prevent potential bad reviews. (Not from me ofc :))
     
  30. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    No, I dev on OSX and it's not the kind of issue I'd expect. I actually spent a few hours this morning rewriting a ton of that code to try to work around it, but no luck yet. I'll change the description if I don't find a way around it soon. It really makes no sense, the code itself is very simple..
     
    protopop and Creepgin like this.
  31. alexisdavidson

    alexisdavidson

    Joined:
    Apr 28, 2015
    Posts:
    14
    Hello, I bought the Lightweight pipeline support but the terrain appears pink. I read in the documentation that I need to to setup the lightweight render loop.
    I don't know how and can't find any documentation on it. Any help or link?
     
  32. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    you need to consult unity’s documentation and install/setup the LWRP. Once that’s done you can select the light weight render loop on the material and the shader will be recompiled for that pipeline.
     
    protopop likes this.
  33. alexisdavidson

    alexisdavidson

    Joined:
    Apr 28, 2015
    Posts:
    14
    That worked out, thanks a lot for the quick reply :)
     
  34. AppHappyStudios

    AppHappyStudios

    Joined:
    Jun 13, 2013
    Posts:
    45
    Hey I am having issues on Unity 2019.2 with the latest microsplat on Android. I have 3 terrains, all with the same material settings but different terrain settings. The largest one is giving a solid white texture at distance.
    Screen Shot 2019-10-11 at 8.13.54 PM.png Screen Shot 2019-10-11 at 8.54.59 PM.png
    It is 2000x2000 could that be an issue? It appears across x86,ARM, and ARM64 alike, emulator and device.
     
    Last edited: Oct 12, 2019
  35. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    hard to say without seeing your setup, but I’d check the references on the terrain components to make sure they are all pointed to what you think they are pointed to, and that the PropData references are all assigned.
     
  36. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    This is now fixed (or really worked around), uploading a new version to the store now.
     
    Creepgin likes this.
  37. ncho

    ncho

    Joined:
    Feb 1, 2014
    Posts:
    89
    Hi Jason, is the Microsplat for Meshes add-on still planned for release some day?
     
    Noogy and iddqd like this.
  38. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    I have some bug in the painter which only happens on DX/Metal platforms that I need to fix before it can be released, and I've just slacked rather than trying to fix it.
     
    konsic and Noogy like this.
  39. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    412
    Really looking forward to it!
     
    Noogy likes this.
  40. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    33
    @jbooth does the glitter effect work from a fixed top down perspective like in diablo 3?
     
  41. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    It's designed closer to Journey's glitter effect which is view and light dependent. But if your comfortable with shader code you could easily hard code one of those angles such that it's triggered from whatever perspective you want.
     
  42. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    33
    Sounds a bit like a soft no? Reagrding shaders, sadly i'm pretty much clueless in that aspect.
     
  43. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    573
    @macish
    If I understand jbooth right you can search the shader code for the occurance of the glitter calculation and substitute any camera vectors used in these situations by some vector of your own liking. When playing with that vector you can force the glittering even at angles that wouldn't normally glitter in top down situations.
     
  44. macish

    macish

    Joined:
    Oct 29, 2018
    Posts:
    33
    I dont have the addons yet so i can't test it out. I guess i'm gonna just give it a try then ;)
     
  45. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    133
    I have this same issue. I don't quite see where I am going over the 16 OSX limit. I have 10 terrain textures, puddles, streams, terrain blending. Debug says Shader Model: 3.5, Texture Samples : 9, Regular Samples : 12. Also could you help me with this advice: "there's no reason to sample the control map Unity provides for textures 13-16, so you can reduce this down to get a sampler back." Do you mean I should reduce the Max Texture Count to 12?
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Samplers are not the same as samples. You can have as many samplers as you want. Basically, in older APIs you have textures and samplers- a sampler samples a texture, and they were paired. So if you have 1 texture you have 1 sampler to sample it with. MicroSplat uses Texture Arrays, so the diffuse and normal array would consume 2 samplers, regardless of how many terrain textures you use. Puddles and streams consume more samplers, because they have their own unique textures. And the control maps for splat maps as well. So if you set the max texture count to 16, then that takes 4 control maps, and therefor four samplers. So setting that to 12 in your case will save you one sampler.

    On most newer APIs sharing works, and this isn't an issue.
     
  47. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    56
    Hi
    Im not sure what am doing wrong your example scene work with this setting... Clipboard.png
    So mine 0 and 1 textures works, 2 and 3 looks like they didnt receive the given Distance Resample information
    Using MM terrain, Micro Splat Terrain (Script) has been Sync, im out of ides
     
  48. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,785
    Other than your resample distances both being set to 0 (this would mean you never see the close textures, which I assume is just testing) it all looks fine. Are you saying that wherever textures 2 and 3 in your array are used they don't respect the resample scale? That seems unlikely given how the code works, it doesn't really know or care about which textures it's operating on. Can you try painting a big area of one of the textures and then editing the resample scale to make sure it's not scaling up/down with it?
     
  49. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    56
    Just so that you know I tried my other Micro splat creations and this works. But on this current creation ist not a joke even if it seam one, ill try to rebuild Micro splat components maybe its that. But here is this my talk about; image1; green is Tex1,Blue Tex2,Orange Tex3 the rest is Tex1 1.jpg 2.jpg
     
  50. sunseeker1988

    sunseeker1988

    Joined:
    Jul 10, 2014
    Posts:
    413
    some great results with microsplat on my textures! reworked the maps and got even better results in microsplat. first picture is a puddle drying up inbetween the tesselation and displacement of the dirt texture. i lerped this global shader propertie to achieve puddle effects from rain that dry up after it rains and fill up when it rains. Terrain Weed Farming Game.jpg Terrain Weed Farming Game 2.jpg
     
    wzxy1322, Rowlan, nirvanajie and 5 others like this.
unityunity