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

    wirelessdreamer

    Joined:
    Apr 13, 2016
    Posts:
    134
    I'm seeing everything display properly in unity, but this is what I get in a windows build:
    upload_2020-7-30_9-58-8.png

    what i expected to see:
    upload_2020-7-30_9-58-33.png
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Are you loading via code/asset bundles or something?
     
  3. wirelessdreamer

    wirelessdreamer

    Joined:
    Apr 13, 2016
    Posts:
    134
    using photon for the scene load, its built into the project, not addressable, or asset bundle

    PhotonNetwork.LoadLevel((string)customData[0]);
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Try in a fresh project just loading the example scene in a build without Photon to rule out any MicroSplat issue. Once that's done, my bet is that something it needs isn't getting loaded, like the PropData object that's hooked to the MicroSplatTerrain component or something.
     
  5. wirelessdreamer

    wirelessdreamer

    Joined:
    Apr 13, 2016
    Posts:
    134
    I replaced the photon load scene, with normal unity and saw the same issue in a build. I'll come back to microsplat tests later on, perf seemed great in editor though. Thanks for the help.
     
  6. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    @jbooth Hi, I switched over to microsplat as terrain shader and its great ;) but I want to ask if it´s possible to change the per texture properties at runtime with a script. Lets say I want to change the smoothness of the 3rd texture of my textures. How do I do this?

    Thanks
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    There's an API on the PropData object, which you can get from the MicroSplatTerrain component. Something along the lines of:

    Code (CSharp):
    1. o.GetComponent<MircroSplatTerrain>().propData.SetValue(index, PerTexFloat.smoothness, value);
    2.  
     
    marcell123455 likes this.
  8. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Alright,

    tried that but he tells me something that I am trying to change a color and not a float...
    I don´t get it. Could you write a example? something to set the 3rd texture smootness to 0.5f for example

    thank you
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Who tells you something? Did you get an error message?
     
  10. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Visual Studio when I hover over the code. ^^´ Just an exampe would be nice.
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    so would an actual error.. the function has overloads for multiple types. And the example above is the actual code- are you new to coding? Index is the texture index you want to change, and value is the smoothness value you want.
     
    Last edited: Aug 3, 2020
  12. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    No I am definitely not new to coding. Yes this is what I tried but when I lets say:
    Code (CSharp):
    1. MyMircroSplatTerrainScriptReference.propData.SetValue(0, PerTexFloat.smoothness, 0.5f);
    than "PerTexFloat" is underlined red and it says it doesn´t exist.
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Most likely you haven't included the proper namespace..
     
  14. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    2019.4 LTS, I followed the documentation and get black bands where I expected blending.

    The demo scene works fine, but not this terrain. Generated with MapMagic2, anyone else seen this?

    upload_2020-8-3_17-22-52.png
     
  15. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I have not. I take it you generated the terrain descriptor?
     
  16. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Correct. Would you like to see the project?
     
  17. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    My hunch is that terrain blending is not working with custom splatmaps enabled. Sound right?
     
  18. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Adding "using JBooth.MicroSplat;" to the top of my script didn´t do the trick.
     
  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I wouldn't expect that to make a difference- but you could try with/without and see easily enough.
     
  20. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You can see it right in the class itself:

    Code (CSharp):
    1. public class MicroSplatPropData : ScriptableObject
    2. {
    3.    //...
    4.    public enum PerTexFloat
    5.    {
    6.       InterpolationContrast = 1*4+1,
    7.       NormalStrength = 2*4,
    8.       Smoothness = 2*4+1,
     
  21. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    I searched it in the script and could not found it. Then I was thinking and found out that I had a old version installed. Updating the asset solved the problem. Thank´s for you patience ^^
     
    protopop likes this.
  22. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Huh almost, When I do "TerrainMat.propData.SetValue(0, MicroSplatPropData.PerTexFloat.Smoothness, 0.1f);"
    I get a error: IndexOutOfRangeException: Invalid Color index(7)! no matter what int I use as index.
     
  23. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Odd, is the values array null or empty? It's a 32x32 buffer, so not having index 7 seems unlikely. Also, you'll want to call Sync on your target object (or MicroSplatObject.SyncAll()) after setting the value- this will synchronize it across multiple terrains if present, and sync it to the GPU.
     
  24. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    When I check if values or values[0] is null it says no it´s not. Any other ideas?
     
  25. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    What's the length of values? Should be 1024, which is much greater than 7..
     
  26. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I can confirm that the black terrain blending occurs when custom splatmaps are enabled. Disable the custom splat maps and the terrain blending renders correctly.
     
  27. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Ok, I'll look into this.
     
  28. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Ok, the simple repro is not showing the issue - everything works fine. What I suspect is happening is there's some kind of race condition between MM and the code which sets up the terrain blending. Like, the object you wish to blend is instantiated before MM sets the custom control maps, so when the data is copied it has no splat maps. If you press the sync button on the terrain, does it start blending? Also, does the MM component set the external splat maps on the MicroSplatTerrain component, or only directly on the material?
     
  29. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    1. No, sync button does not change anything.

    2. Not 100% sure of the question, however I am using the MM MicroSplat output node as shown in image.

    upload_2020-8-4_11-47-28.png
     
  30. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    If you look at the terrain, there should be a MicroSplatTerrain component on it, with the splat maps generated by MM on it. If they aren't there, then it's likely the MM code is setting the data directly on the material and needs to set the data on the MicroSplatTerrain component instead - because that's where it gets copied from to the blending material.
     
  31. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    Bingo. You found it. All splatmap slots are empty. I'll investigate the MM code. Thanks for your help.
     
  32. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
    Hi will microsplat works with mesh ? Unity terrain converted to mesh. But without your mesh module. So will it work with mesh terrain? Thank you.
     
  33. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    There's a module for doing mesh terrains- that's what it's for..
     
  34. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
    But my question is that I've already created the mesh terrain without using your module (mesh terrain) so can I still use microsplat core module with that? Because I don't have your mesh terrain module. That's why I'm asking. Thank you.
     
  35. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    No, the core module works for terrains- if it worked with meshes there wouldn't have been the need to write the Mesh Terrain or Mesh Workflow modules. Note that Mesh Terrains does not include painting tools, since you are expected to be working from a terrain - where as the Mesh Workflow module works with any mesh, but does not support some features that only work with terrain like geometry.
     
    mukki014 likes this.
  36. mukki014

    mukki014

    Joined:
    Jul 30, 2017
    Posts:
    164
    Okay. I get that now. Thank you for brief explanation. :)
     
  37. simonwittber

    simonwittber

    Joined:
    May 13, 2008
    Posts:
    228
    I had to edit MM2 MicroSplatOutput.cs and assign the textures in the ApplyData class.
     
    Last edited: Aug 4, 2020
  38. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Yes, values.Length is 1024...
     
  39. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Maybe submit that change back to MM if you could?
     
  40. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Then not sure why it would be throwing an out of bounds error with index 7..
     
  41. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Any Ideas of what I could do to "recreate" the arrays? maybe setting up the terrain and microsplat data for this terrain in general helps.
     
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I mean it's there and already created. Maybe step through the code and make sure it's doing what we expect it to be doing..
     
  43. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Would deleting the material and data assets for this terrain and recreating them help? Because I used a old version of Microsplat to create them. Maybe it´s not compatible with something? If so, which assets would I have to delete?
     
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Unlikely; from what you’ve said the array has data; you should be able to inspect it even and see what value is in index 7..
     
  45. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Value 7 is a yellow color. Is it possible that I send you my terrain and you take a look at it by yourself? Which files would I have to include?
     
    Last edited: Aug 5, 2020
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Ok, so I just got a chance to repro this- the parameterization is wrong in one of those functions, and it ends up trying to access index 7 of a color from the values array, not of the values array itself. Doh. Sorry about that,. Try replacing those functions with these..

    Code (CSharp):
    1.  
    2. public void SetValue (int textureIndex, PerTexFloat channel, float value)
    3.    {
    4.       float e = ((float)channel) / 4.0f;
    5.       int x = (int)e;
    6.       int y = Mathf.RoundToInt((e - x) * 4);
    7.       SetValue (textureIndex, x, y, value);
    8.    }
    9.    public void SetValue (int textureIndex, PerTexColor channel, Color value)
    10.    {
    11.       float e = ((float)channel) / 4.0f;
    12.       int x = (int)e;
    13.       SetValue (textureIndex, x, value);
    14.    }
    15.    public void SetValue (int textureIndex, PerTexVector2 channel, Vector2 value)
    16.    {
    17.       float e = ((float)channel) / 4.0f;
    18.       int x = (int)e;
    19.       int y = Mathf.RoundToInt ((e - x) * 4);
    20.       SetValue (textureIndex, x, y, value);
    21.    }
    22.  
    (Then remember to call Sync on your terrain, or MicroSplatObject.SyncAll() if many things are sharing the same material, after you have set all properties that you might want to set).
     
    marcell123455 likes this.
  47. marcell123455

    marcell123455

    Joined:
    Jun 18, 2014
    Posts:
    275
    Works ;) Thank you for this great asset.
     
  48. fredboy

    fredboy

    Joined:
    Nov 16, 2012
    Posts:
    3
    Hi Jason,
    I'm new to the Mega/Microsplat world but reading your comparison of the two I recently bought Megasplat (version 1.76) because I needed a mesh workflow for a project I'm doing for a local museum trying to do mini-science apps online via WebGL 2.0. I'm building on a model of comet 67p which has a texture map but at the scale of 4 km, it needs a plausible microtexturing from data which Megasplat seems to do brilliantly - UNTIL I switch platforms from Windows to WebGL in 2018.4.25f1 and it all goes "black" (it all returns fine when I switch it back, same behavior for both your example mesh and terrain workflows in Megasplat and also tested in older versions of 2018). I have OpenGL 4.6, and am set up for webGL 2.0 also just retested with the latest Nvidia drivers for my GTX1080 on MSI laptop. Setup is shown in attached images.

    Researching the problem, I have seen the terrain workflow work correctly in a Microsplat LWRP example using WebGL seen on simmer.io - found here: Play Microsplat LWRP Test in your browser | SIMMER.io

    I noticed on this forum, that there isn't much current Megasplat activity and that Microsplat now has a mesh workflow of its own (and it looks like a better way to splat over existing textures maybe). Also not found anything recent about WebGL issues which I take it to mean it works for most people or isn't supported and I missed that somewhere.

    I'm happy to go in the Microsplat direction (I don't need 100's of splat textures), but I see that the prerequisites are pretty much the same for both tools, so I'm wondering what I'm not setting up properly to make WebGL work in Megasplat?

    Also, should I be considering Microsplat going forward instead? I have other projects such as Mars HiRise data with large texture maps which can use terrain workflows or meshes.

    I've snapshot some of my setup screens in case that's helpful. (attached - apologies if it's not :)

    Thanks - the test results in Windows are already starting to be amazing! - excited to make this work if possible.

    Steve Utt (Fredboy)
    upload_2020-8-5_19-44-1.png
    upload_2020-8-5_19-44-56.png
    upload_2020-8-5_19-45-47.png
    upload_2020-8-5_19-46-23.png
     

    Attached Files:

  49. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Honestly I have no idea- I haven't run either on WebGL myself. My guess would be an issue with texture arrays, but if they work in MicroSplat it's not that- another possibility is something like non-square matrix's, but you'd see a shader compile error in the build log in that case.

    That said, yes, MicroSplat is basically where everything is these days- it has a ton more features, is modular, is considerably faster, and unless you need over 32 textures, it's better than MegaSplat across the board. I mostly keep MegaSplat around because there are a few projects and voxel engines that support it, so it still gets used..
     
  50. superkratos

    superkratos

    Joined:
    Sep 4, 2017
    Posts:
    112
    Hi, Jason. I I just bought a HDRP version with the latest terrain blend module and triplannar module today. But when I try them together, I got this stretched blend effect.. Seems like one axis of the triplannar effect is not working on the blended module? Can you tell me how this might be caused?:D
     

    Attached Files:

Thread Status:
Not open for further replies.