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

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Yeah, this is the windows only compiler bug I'm looking into. Haven't found a workaround yet - works fine on OSX..
     
    txarly likes this.
  2. txarly

    txarly

    Joined:
    Apr 27, 2016
    Posts:
    197
    ok waiting in this case :( .Thanks
     
  3. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    Dredging up an old post because this bugbear still faces us.

    I'm currently hitting this wall...again... when building (not in the editor) for two different shaders in my project, MicroSplat being one.

    Unity is running in DX11 mode, I'm rendering in deferred mode, building to winx64 dx11 (only), not using LW or HDRP, in Unity 2018.4.2f1 My project is targeted to a very specific, high end hardware, so I don't care about other platforms or compatibility with other render engines. My dev environment is the only target system this build will ever run on. It's frustrating that it works in the editor scene and failing because it's trying to build for some variant that I likely don't need or care about.

    I am forcing shader model 5. The MicroSplat features I'm using are anti-tiling, terrain blending, 3-way texture clusters, triplanar, 12 terrain textures, a few per-texture params, and wind/glitter enabled (and it looks great so I'd really like to keep it that way). I've got procedural textures and advanced detail modules installed, but not enabled. This is showing 18 maps in the shader, without counting sharing.

    You mention dx11 supports 32 samplers -- is there some magic trick to get this working in Unity? Targeting dx11 only in my player settings still results in it crapping out at 16.

    Any other suggestions to either get more samplers enabled or things I can toggle off to free up a sampler here or there? Any way disable shader variants I'm not using in my scene that are pushing it over?

    MicroSplat shader maps lists as:
    upload_2019-6-19_15-48-33.png upload_2019-6-19_15-53-12.png
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    So MicroSplat shares samplers whenever it can; to be honest dx11 night still be limited to 16 samplers, I can’t remember, but DX11 can share samplers where as OpenGL cannot and is forced to use a unique sampler for every texture.

    That said, I’m surprised your hitting the limit. Most of those features share the diffuse sampler, or use an unique one if something specific is needed (point sampling, etc).

    Internally unity creates variants for many different lighting possibilities, which can have more or less samplers, which makes it hard to measure or predict any of this.
     
  5. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    I'm surprised I'm hitting the limit as well, since within the editor I'm able to enable additional MicroSplat modules, like tessellation/ parallax, without it failing.

    One strange thing is it reports this error on two shaders when building, but half the time it says "build succeeded" anyway and the build runs fine, including those two 'problematic' shaders which it reported failed. So seems likely that it's some variant I don't really need.

    The other half the time it says "build failed" and I get nothing. I haven't been able to isolate why it fails vs not -- I'm not changing anything between attempts.
     
  6. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    I mean you have 18 textures, and I know several of those are shared. Is it possible your target hardware is not running in the mode you think it is? Like OpenGL or something?
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Actually, does the error say which platform it’s compiling when you get it? Because you can pragma out platforms you don’t need if it’s not yours
     
  8. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    ok is this enough?

    upload_2019-6-20_16-36-51.png
     
  9. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    Yah, the error says d3d11.

    When I look at the shader variants, I can see some flags I don't need, like lightprobes (my terrain is lightmapped) although I don't know if those are the versions that are adding the extra passes

    The exact error is


    Code (CSharp):
    1. Shader error in 'Hidden/MicroSplat/Mars Terrain_Base-1222765776': maximum ps_5_0 sampler register index (16) exceeded at line 2139 (on d3d11)
    2. Compiling Fragment program with UNITY_PASS_FORWARDBASE DIRECTIONAL SHADOWS_SCREEN LIGHTMAP_ON DIRLIGHTMAP_COMBINED LIGHTMAP_SHADOW_MIXING SHADOWS_SHADOWMASK LIGHTPROBE_SH INSTANCING_ON
    3. 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
    see anything suspicious in the defines?
     
  10. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    New question

    I have some objects that I've added terrain blending to, and now want to remove it. I removed the script attached to the object, but the second material / shader for object blending is hanging on. How do I remove that without nuking terrain blending for everything?
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Set the material count to 1 on the meshrenderer..
     
  12. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    oh, duh. thanks. :)
     
  13. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    568
    Hi Jason,

    I've been having alot of fun with the asset and would like to thank you for it. Great job!

    Some questions though:
    1) When using stochastic mode textures like man-made tiles must be excluded from this method in order to retain their intended straight lines and overall "patternness" - so I went into the per texture properties and toggled the "stochastic disabled" on and set it to one. This worked once. But now it is failing to work as it did before. Is there something I've overlooked?

    2) The height blending looks too smooth (I don't mean the transition, I mean the contours) - I'd expect more varied contours cutting into other textures below, more interlocking. Fiddling with the global interpolation contrast only adjusts the transition width but doesn't help with the actual contours. Also: enabling per texture interpolation contrast has no effect.
    How contrasty should height maps be for this feature? Maybe mine are too soft.

    3) Is there a very simple example substance setup to have a look at? I'd like to use the substance feature (dragging just the substance into the slot and letting MS extract the maps automatically).

    4) Do I have to assign Unity-native texture layers to the terrain first to make use of MicroSplat? Or is MS able to assign texture layers to the terrain on its own based on the Textures we can add to the MicroSplatConfig asset?
    Expressed differently: do I have to setup textures twice - once for Unity and once for MS?

    I'm on Unity 2019.3.0a4, so this might be a reason why something's odd at my end.
     
  14. Larzarus

    Larzarus

    Joined:
    Jun 4, 2016
    Posts:
    27
    So I don't know if this is a clue, but I'm also getting the register exceeded error on the terrain blending shader as well. Is that expected if the main terrain shader has the error?


    Shader error in 'MicroSplat/Mars Terrain_BlendWithTerrain': maximum ps_5_0 sampler register index (16) exceeded at line 3128 (on d3d11)
    Compiling Fragment program with UNITY_PASS_FORWARDBASE DIRECTIONAL SHADOWS_SCREEN LIGHTMAP_ON DIRLIGHTMAP_COMBINED LIGHTMAP_SHADOW_MIXING SHADOWS_SHADOWMASK
    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
     
  15. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    676
    I can't seem to get normal blending to work. Maybe I've misunderstood what it's supposed to do? I thought it would blend the normals of the object with the normals of the terrain, but the setting doesn't do anything like that.

    This is from a fresh new project with only micro splat + object blending, running the object blending example. Normals aren't blended:

    https://gyazo.com/c239677648495d5917c22eb29cfeac12

    The seam between the object and terrain is very noticeable.
     
  16. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624

    1. Perhaps your property data object got unhooked somehow? Do other per-texture properties work?
    2. The way the shader works is by drawing the object a second time, the first with whatever shader you have assigned to the object, the second with the terrain shader. The upside of this is that you can use whatever shader you want for your object, the downside is that the second pass can't know anything about the first shader. So there can't really be height blending.
    3. You just drag it into the slot and is will grab the textures from it- but you'll need the substance plugin installed as Unity removed native support a while back.
    4. No, after conversion you can just edit the TextureArrayConfig and MicroSplat will generate and sync the layers from there keeping the layers in sync.
     
  17. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    That would be expected since that shader requires extra samplers over the standard terrain one.
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    The normal blend slider only works when you are using certain options. I can have another check and hide it when not in the correct modes, as that's usually what I do.
     
  19. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    676
    What options need to be enabled?
     
  20. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    127
    Further to my error messages - Invalid texture format: 29
    UnityEngine.Graphics:CopyTexture(Texture, Int32, Int32, Texture, Int32, Int32)


    I didn't get a reply so took of crunch compression from both source and in the MicroSplatConfig. This seems to have sorted the problem. I am using Unity 5.6.7
     
  21. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Hmm, perhaps crunch doesn't support texture arrays?
     
  22. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Ok, looking over the code it should control the blending of the normals interpolation distance - so at 0 the normal goes from the terrain normal to the object normal instantly, at 1 it takes 1 meter in distance. I was getting confused with the "Object Normal Blending" option, which allows you to supply a normal map for the base object.
     
  23. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    676
    Ok, sure, but as you can see from the picture I provided, that's not how it behaves. Changing the normal distance slider has no effect.
     
  24. Harjawalda

    Harjawalda

    Joined:
    Sep 1, 2018
    Posts:
    10
    Hi Jason, I have a persistent lighting problem, essentially it seems I get too much light, or re flexion from the ground especially when having the light source behind me. I tried a lot of different settings, vanilla lighting, enviro lighting but cant seem to get rid of it. Do you have an idea what is the source and what I could do to prevent this from happening?

    wm_against_lightsource.png
     
  25. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    There's about a million lighting options in Unity, but often what people complain about is the specular response on glazing angles from the GGX lighting model Unity uses. You can try one of the other lighting modes in MicroSplat, but they will force forward rendering on the terrain if you're using deferred. In deferred, you can modify the deferred lighting shader, but that modifies it for all opaque objects.
     
  26. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Hello Jbooth, did you get my screen shot? Also something similar is happening to me too:

    Destroying object "UnityBlack" is not allowed at this time.
    UnityEngine.Object:DestroyImmediate(Object)
    MicroSplatTerrainEditor:BakingGUI(MicroSplatTerrain) (at Assets/Plugins/MicroSplat/Core/Scripts/Editor/MicroSplatTerrainEditor_Baking.cs:116)
    MicroSplatTerrainEditor:OnInspectorGUI() (at Assets/Plugins/MicroSplat/Core/Scripts/Editor/MicroSplatTerrainEditor.cs:233)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    The reason I am now trying this is because I want to check if I can bake the procedural generated textures in order to get a lighter shader. Is this something possible?

    P.S.: I noticed that changing the shader generator settings impact noticeably the frame rate, so I may just get away with that
     
    Last edited: Jun 21, 2019
  27. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Baking back the procedurals to splat maps will make the shader faster in most cases, but thats the part which has the windows compile issue right now..
     
  28. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    568
    That might have been the case. I've just deleted all the assets from the MicroSplatData folder and both removed the MS component from the terrain and cleared its texture assginments.
    After assigning a new MS component and converting the terrain to MS data I seem to be back on track. Per Texture Settings are working now again.
    What I didn't test with the new setup was stochastic texture sampling. Crossing fingers that this will play nicely.

    Hmm, I think we were talking about different things here. But I'm satisfied with the results I'm getting now since the Per Texture Settings are working again. With these I was able to adjust Height Offset and Height Contrast per texture to my liking.

    That's what I already have in place. What I was asking for was a default substance output graph you would suggest for MS. Sorry if I wasn't precise enough.
    Something along the lines: Metallic goes into output Metallic, Red Channel. Smoothness (inverted Roughness) goes into output Metallic, Green Channel.
    The idea behind that question was to have everything setup in Substance Designer so I do not need to manually adjust any settings in MS since everything would be in the correct places at import time.
    I think I am close to that output graph - the only problem with the default setup of MS that I currently see is that it seems to expect both Metallic and Smoothness to be in the Green channel of the Metallic texture. That's a conflict. Metallic could be Red Channel per default since it is usually either black or white and doesn't need many bits to cover inbetween values.

    Great!
     
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    When reading from substances it doesn't care what channel the data is in, it grabs it from the substance output of the appropriate name.
     
  30. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    883
    Ah ok so it doesn't work atm and it must be fixed?
     
  31. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Not on windows, have a bug in with Unity, but also trying to find a way to hack around it..
     
    sebas77 likes this.
  32. RobinKarlegrund

    RobinKarlegrund

    Joined:
    Feb 26, 2019
    Posts:
    5
    Hi Jason!
    If I would like to override the output of the microsplat main shader ("o.Albedo = albedo.rgb") with just one of the textures that I've feed microsplat with, how would I do that? I know this is more of a shader basic knowledge question but I would really appreciate any help I can get. Thanks!
     
  33. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    you mean like a single texture from the array? If you'd want it as a permanent option you'd have to add it to the debug enumeration, serialize it in the pack/unpack methods, and add an #if to the end of the fragment files in core that does whatever you want it to do..
     
  34. mik52

    mik52

    Joined:
    May 10, 2015
    Posts:
    4
    Are there plans to make Microsplat work with Amandin-E's Digger app?
     
  35. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    We started on it, but never finished..
     
  36. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    694
    How do I use microsplat on imported terrain mesh ?
     
  37. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    The mesh module for MicroSplat is not available yet; currently only Unity Terrains are supported.
     
  38. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    694
    Could you add supoort for it?
     
  39. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    When I get around to finishing it..
     
  40. sunseeker1988

    sunseeker1988

    Joined:
    Jul 10, 2014
    Posts:
    398
    Just wondering how I can adjust aniso levels. Seems adjusting the aniso level on the texture in unity does not change anything.
     
  41. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    You have to adjust it in the Texture Array Config, as the original textures are no longer used for texturing.
     
    sunseeker1988 likes this.
  42. sunseeker1988

    sunseeker1988

    Joined:
    Jul 10, 2014
    Posts:
    398
    Thanks jason, I did edit the texture array config and I increased the asino level to 4 then tried max value and It still looks like Image Below. Maybe this is a Unity limitation. Are these two areas correctable for asino levels?
    AsinoIssue.PNG
     
  43. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Hard to tell from a screenshot. Depending on which version of Unity you are using you might be able to adjust the aniso level right on the texture array itself.
     
    sunseeker1988 likes this.
  44. sunseeker1988

    sunseeker1988

    Joined:
    Jul 10, 2014
    Posts:
    398
    found out I needed to set anisotropic textures to forced on in quality settings and not per texture.
     
  45. crazymonkay

    crazymonkay

    Joined:
    Apr 1, 2013
    Posts:
    97
    Hey there,

    Just discovered this while I was looking around at terrain shaders, the fact that the core module is free is awesome!

    Something I wanted to ask before I start digging into it, is it possible to change the terrain textures at runtime? For example in my project I know the terrain is going to have some pre-determined number of texture "slots", but I need to be able to swap out the diffuse, normal, height, etc textures for each slot at runtime.
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Yes, you can compress the available textures into the same size/format and use Graphics.CopyTexture to copy the data into your target array. Easiest is to just use the texture array config to pack them automatically for you, so you don’t have to understand the internal formats.
     
  47. crazymonkay

    crazymonkay

    Joined:
    Apr 1, 2013
    Posts:
    97
    Excellent! I'll definitely be looking into integrating this into my project then. Thanks!
     
  48. sekever-n00b

    sekever-n00b

    Joined:
    Nov 4, 2017
    Posts:
    43
    Hi!
    Cant tell if this was asked before but would there be a way to paint with Procedural Texturing on mesh? And thx for so many already released freaking good stuff!
     
    Last edited: Jul 5, 2019
  49. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,624
    Not really - I have an unreleased mesh module that would allow it though. The other option is to use the terrain blending module and have it blend the terrain texture rules over the mesh, but this would be more expensive than a native mesh solution would be.
     
  50. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    127
    Hi - I've hit a problem with blending. All looks good in the editor. Then I hit run and all blending vanishes. Stop running and everything looks fine again.

    I have updated the Terrain Descriptor, updated the MicroSplatConfig but still no luck.