Search Unity

[Released] MegaSplat, a 256 texture splat mapping system..

Discussion in 'Assets and Asset Store' started by jbooth, Nov 16, 2016.

  1. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    Yep so I just did a super quick hack on the ForwardBase pass:
    upload_2017-5-30_15-21-20.png

    And that works! This appears to allow me to change the underlying verts, allowing any tessellation and other MegaSplat displacement features to work as normal. In addition to replicating it to the other passes, would this be the best place to perform this? Finally, is there currently a way to implement this without loosing changes if I modify the shader via your generator?
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    5.6 is still all kinds of busted, I suggest remaining on 5.5 for a few more weeks until they fix things.

    Do you get any errors from anything? I've heard bad things about Aquas causing issues with other assets, though I have no first hand knowledge of this myself as I've never used the asset. Are there any other major differences between your fresh project and this one? Have you considered copying the assets from your current project into the working one? When projects get upgraded through major revision, sometimes cruft accumulates from those previous versions.
     
    malkere likes this.
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    I'm working on a sort of plugin system now that would allow you to do stuff like this. Basically, it writes out a .cginc file with several functions in it which you can modify. I'll add one for the tessellated vertex as well. Then you could modify the .cginc and it would persist through changes without you having to edit the resulting shader..
     
    ftejada likes this.
  4. Fabbs

    Fabbs

    Joined:
    Dec 2, 2013
    Posts:
    26
    Guess im not using Megasplat for a while then :)
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Unfortunately there's not much I can do when Unity breaks an entire feature set, then doesn't fix it for three months..
     
  6. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    Great. So my later tests today revealed an issue I think you were alluding to: Unity LoDs the terrain mesh based upon the complexity of the heightmap in area chunks. This means that my vert displacement can become basically invisible if I try to displace on a very flat chunk of the map.

    Any thoughts on this?
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Yep, that's why MegaSplat doesn't actually work with vertices when it runs on a Unity Terrain (unlike when working on a mesh). Other than pushing the lod settings out, not much you can do about it since you have no control over things with Unity terrains.

    So the other option is to do this on the tessellated vertex instead of the actual vertex, and set the tessellation high enough that you always have something to displace. This will still be affected by the LODs (create swimming), but might work well enough for you.

    Another option is to ditch Unity terrains all together and use meshes, which have none of these issues..
     
  8. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    I may have to ditch the Terrains yeah. Though I've got no tools for making terrains out of arbitrary meshes at the moment. In the meantime, how do I do the vert operations on the tessellated verts?
     
  9. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    If your hacking it in the same way as before, do it on the tessVertex after it's been generated and interpolated. Look for the spot where it does the interpolation (search for bary.x * ) on each tessellated vertex, then sample after that..
     
    strich likes this.
  10. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    Okay great this is looking pretty good! I have one more feature request: It would be great to be able to provide an option to set your control textures as global, instead of material properties - It would allow me to direct access and modify them via things like Compute Shaders or other shaders.
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Does Unity require the property to be undefined for it to respond to a Shader.SetGlobal value? Ideally this would be something that you could apply to any property, as things like wet level and rain parameters might want to be global. This will be a big change, so might not make it into 1.08.

    Meanwhile, here's the current functions exposed for the custom function feature:

    Code (CSharp):
    1.  
    2. // this function is called in the vertex shader, before anything has been computed.
    3. // You can do things like modify the local position of the vertex (before triplanar texturing), etc..
    4. void CustomMegaSplatFunction_PreVertex(inout float3 localPosition, inout float3 normal, inout float3 tangent, inout float2 uv)
    5. {
    6. }
    7.  
    8. // this function is called after the tesselated vertex displacement has been calculated, if tessellation is enabled.
    9. // you must apply the offset if you want to see it, it's provided here so you can modify it further.
    10. void CustomMegaSplatFunction_PostDisplacement(inout float3 position, float3 offset, inout float3 normal, inout float3 tangent, inout float2 uv)
    11. {
    12.    // default implimentation is to apply the displacement offset unmodified
    13.    position += offset;
    14. }
    15.  
    16. // this function is called at the end of the pipeline, so you can modify the color, normal, smoothness, etc, before lighting is applied.
    17. void CustomMegaSplatFunction_Final(SplatInput si, inout MegaSplatLayer o)
    18. {
    19.  
    20. }
    21.  
     
  12. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    unfortunately I don't think you can force a variable to be global whilst also having a material property for it. I could be wrong though.
     
  13. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,109
    I've made some hacks to mapmagic, but mostly just terrain placement, distance from camera generation checks, etc. I'll try adding in the other packages I use one by one in a new project to see if Aquas or anything else breaks it, and export/import my assets into a new project if that doesn't show anything. I agree there is probably more than a few rusty screws having carried the project around for so long.

    update: I've added all the major tools I use into a new project with MegaSplat and it's working fine. So, hopefully my problem is an isolated case. I'll start trying to merge my prefabs in see if everything goes well =]

    update2: everything is in a new project and working fine. Suprised at how smooth that went! Just need to fix my lighting and a thousand other things =]
     
    Last edited: May 31, 2017
  14. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    So I spent a few hours debugging this last night- it appears to be some kind of Unity shader compiler bug. I've had to work around these before, but it'll take some inspecting of the resulting shader assembly to figure out what the hell it's doing. Odd workaround- turn on detail noise, and then parallax will work correctly. This is very odd, since the parallax code runs long before detail noise does - but par for the corse when dealing with bugs in the compiler. Anyway, I'll see if I can find a way to jiggle the handle and avoid it tonight..
     
    WildStyle69 likes this.
  15. Lijianjian

    Lijianjian

    Joined:
    Feb 26, 2017
    Posts:
    16
    I need some help ! When i update amplify shader editor to 1.0 I have this problem! jp02.jpg
     
  16. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Looks like the amplify guys have made that variable private. I'll send them an email, but you might want to post there as well. For now, you can go into their ParentNode.cs class and make that variable protected instead of private and it should fix it..
     
  17. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,720
    Quick question. If I convert a terrain to Megasplat and then decide to revert back to Unity terrain is it just a matter of changing the terrain material back to Standard? Or is the process more complicated than that? I want to test for performance, but if thing don't work out then I will want to revert back.
     
  18. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Yes, you should just be able to switch it back to standard. The converter only reads the splat data from the terrain, it doesn't clear it out..
     
  19. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    3,720
    Thanks.
     
  20. eastes

    eastes

    Joined:
    Sep 1, 2012
    Posts:
    49
    This is a great idea. Looking forward to this. I'd be willing to donate a steam key as part of the prize, but it's VR only unfortunately.
     
    jbooth and magique like this.
  21. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775


    Dev Log #20, going over the workflow of the custom code extensions.
     
  22. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    285
    FYI I got this working fairly trivially by simply commenting out the material property. I see you might need some work around your inspectors to support this feature, but from a shader perspective it is simple.
     
  23. camel82106

    camel82106

    Joined:
    Jul 2, 2013
    Posts:
    303
    Hi,
    I would like to provide a little feedback. As you know we don't have TC2 integration. Which is not your fault of course.

    So I must use your utility to convert terrain splats to megasplats. Which is relative ok for me. But that workflow starts to be cumbersome with multitile terrains and some other issues.
    • you must set up material for every terrain tile (maybe some concept of shared material properties for all tiles would be great for this, as you need to synchronize all properties through all tile materials)
    • you need to convert each terrain tile separately. It would be interesting to have some concept of selecting an parent terrain gameobject. So all child terrain gameobjects would be converted automatically.
    • Configuration of splat conversion is lost when I exit Unity. It would be nice to have ability to save it as preset to scriptable object. So I must configure texture mapping again and again when iterating on splats.
    Don't take it please as critics it's just constructive feedback. With those features you would basically have TC2 basic integration complete. It would only need to be executed manually. Which is probably better as conversion takes some time.

    Thanks!
    Peter
     
    Last edited: Jun 1, 2017
  24. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Great feedback, thanks! I can make the terrain converter save the conversion data into a file, and restore the last used values when you reopen it. I can also add a way to save this to a settings file.

    Multi-conversion is interesting because each terrain may have different textures, so what do you select as the source textures in the UI. So what I'll do there is make a "batch converter" tool, which takes one of the saved configuration files but doesn't present you with a GUI for it. Then you can select as many terrains as you want and hit apply. I can also look into having an optional "master material" on the converter, which will sync all the material properties to be the same on the batch converter.
     
    feckwagon and camel82106 like this.
  25. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,109
    I switched my new project to linear space working with enviro and megasplat reverted to the stone texture only problem I was having earlier. I switched it back to gamma and it went back to working =o is this expected?
     
  26. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Sorry, it can be hard to follow all the threads at once - this is the one where you were getting only one texture on a Unity terrain, but were not running 5.6? I don't see how linear vs. gamma would affect this though. One thought- did you perhaps forget to save the terrain texture before changing the setting, since that might cause a reload and clear anything in memory? If not, can you send me a repro project with it broken so I can take a look?
     
    Last edited: Jun 1, 2017
  27. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,109
    I'll try and reproduce it in a new project yes.
    I tried a froce regen of the texture via mapmagic, but it covers everything in a stone texture. As soon as Unity finishes switching back to gamma the grass and everything showed up again without regenerating. Running 5.5.
     
  28. jamesllama

    jamesllama

    Joined:
    Jun 1, 2017
    Posts:
    3
    Hi Jbooth, thanks for the super prompt reply , yea was thinking something like that. like rotating my source textures by a certain degree, doesn't have to be 90 but sure. In Substance painter i can rotate the brush by a combination of some keys I think holding down (Alt+RMB)
     
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Ok, I think you're thinking of something different, which is rotating the texture result that you paint- this is not possible, because you're not painting textures, you're painting which texture gets used on which location. The texture's orientation comes from the UV coordinates, which are shared by all textures. MegaSplat is combining all of those textures in realtime, not generating a massive texture which can contain arbitrary data. (Rage, for instance, used a giant virtual texture for their terrain- a landscape was many gigabytes of data, and it took literally days for them to bake it down from the source art).

    MegaSplat sometimes feels like Substance Painter because it lets you paint with so many textures, but the fundamental technique is completely different, as it doesn't create a final texture, but rather compose the texture for every pixel on the GPU..
     
  30. magic9cube

    magic9cube

    Joined:
    Jan 30, 2014
    Posts:
    58
    I'm using megasplat to paint procedural chunk based terrain. So far its working well. Now i'm trying to add another layer and puddles. I see in the manual i should use UV1, UV2 and UV3 for additional options. I guess i'm missing some knowledge here as it appears UV's in unity are vector2 arrays, so i'm not sure how to access those locations,UV1.W, UV2.ZW, UV3.X, UV3.Y, UV3.Z, UV3.W etc.
     

    Attached Files:

  31. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Unity UV's are Vector4's now, but they still have the old Vector2 versions around in the code. If you use SetUVs and GetUVs, you can get the vector4 versions.
     
    magic9cube likes this.
  32. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,109
    I imported MegaSplat 1.08 and MapMagic 1.8 into a fresh project in 5.5.0f3, put in a new MapMagic object, do all the MegaSplat fixes/assignments and it works. Switch to linear rendering and it breaks. I'm not smart enough to care which I'm using yet, so I just switched my main project back to gamma, but there you are =o
     
  33. sxkx360

    sxkx360

    Joined:
    Aug 18, 2013
    Posts:
    6
    Looking forward for the fix for Unity5.6+ but in the meantime as I´ll be doing terrain for mobileVR, is there any things I should consider beforehand to get the best output to my game? Keep up the awesome work!
     
  34. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    In the end, it always comes down to the quality of the textures you put in..

    I'd be interested to hear what kind of settings you end up with for Mobile VR. Performance is so tight, I'd imagine there are hard tradeoff's to be made and designed around.
     
  35. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,961
    In the new patch release today of 5.6 there is a fix:
    (899324) - Graphics: Fixed Texture and Cubemap Arrays only containing the first texture in Standalone builds.

    Is this the issue talked about here? If i get this latest version of Unity, will Megasplat work as expected?
     
  36. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    I'd be interested to know, as that's the bug!
     
  37. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    584
    Is there way to create traces/trails based on tessellation displacement. E.g. tank drives on sand and erases the tessalation under certain colliders. This would be the only one reason why I would have a small displacement, and by the amount of the displacement for each texture the depth of the trails could be controlled. Something like https://www.assetstore.unity3d.com/en/#!/search/page=1/sortby=relevance/query=wreckit .
     
  38. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    There's a tessellation dampening parameter, which can be painted onto vertices or into the terrain textures. You could author your textures with height values starting at 0.5 or so, and then when you apply the dampening the terrain would go down to 0.

    You might (not having used the asset, I don't know for sure) also be able to use the new custom code feature (in dev log 20) to integrate the asset you linked above into the megasplat shaders.
     
    mkgame likes this.
  39. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    584
    Thanks, this sounds good! No, I don't have that asset and I would go with the dampening solution anyway.
     
  40. gremberman

    gremberman

    Joined:
    Aug 10, 2014
    Posts:
    128
    Can somebody check MegaSplat with Unity 5.6.1p2 - does it work ok now? ;)
    It has some texture array fix. So maybe Unity team did it right finally :p
     
  41. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Well, I just checked in 5.6.1p2 w/ API set to OpenGL core, and I get nothing but black.

    I'm going to switch to auto-api and see if that helps, but likely won't be around when it gets done converting the project, so I won't know until later. However, that will render under Metal, which only supports up to shader model 3.5 (so no tessellation, snow, etc).

    So at first glance, it seems like this stuff is still pretty busted..
     
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775

    Ok - got this working after a library delete/reinstall. It looks like the Texture Array issue is finally fixed. But there is another issue, which is kind of complex, so I'll do my best to sum it up here:

    1. OpenGLCore on OSX supports up to shader model 4.6.
    2. MegaSplat creates shaders for model 3.5, but then bumps the shader model to shader model 4.0 when it needs more interpolators (data going from vertex->pixel shader) for stuff like snow, etc.
    3. Shader model 4.0 includes support for Geometry shaders, but MegaSplat (usually) doesn't use geometry shaders at all.
    4. When tessellation is enabled, the shader model is bumped to 4.6, which is the model required for tessellation.

    Now, Unity introduced Metal for OSX in 5.6; in builds, this is the default API, but the editor is still running on OpenGLCore. They plan to make the editor run on Metal in 2017.1.

    However, Apple does not support Geometry shaders, and the tessellation pipeline in Metal is very different than the one in Unity currently, and Unity does not support tessellation in Metal yet.

    What this means is that you get everything looking good in the editor, and half of it won't work in the build. You can fix this by removing OSX Metal support from the list of APIs in the graphics settings, which will go back to OpenGLCore, where everything works.

    When 2017.1 ships with Metal as default in the editor, many features are just going to stop working until users switch the editor and the build to not use Metal.

    The sad thing is that I set the model > 3.5 because I need extra interpolators, which Metal actually supports just fine. But you can't get access to them unless you set the shader model > 3.5 on PC/Consoles/etc, which Metal doesn't support. So there's really no shader model that says "I just want the extra interpolators, not tessellation and geometry shaders, etc".

    Anyway, I'm going to keep talking to Unity about possible ways to deal with this. For now, I would suggest that if you are going to use Unity 5.6 or 2017 on a mac, that you disable Metal rendering and use trusty ol OpenGL.

    Windows machines, etc, are unaffected by this mess.
     
  43. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,961
    Just bought this and looks like a pretty sweet thing!
    I do have 2 issues though:
    1. I get a lot of black all over, just the closest parts render with the shader.
    https://dl.dropboxusercontent.com/s/kpdk1kevwktczmk/shot_170602_211127.jpg

    2. Im trying to use the Texture Graph but i keep getting this error as soon as i hit "Prepare Selection" button:
    NullReferenceException: Object reference not set to an instance of an object
    JBooth.MegaSplat.NodeEditorFramework.NodeMegaSplatOutput+Job.Init (UnityEngine.Terrain t, JBooth.MegaSplat.NodeEditorFramework.NodeMegaSplatOutput masterNode) (at Assets/MegaSplat/Scripts/Editor/TextureGraph/Nodes/NodeMegaSplatOutput.cs:215)

    And the Texture cluster nodes just shows errors. I know i have to assign the Config which i have done with the diffuse array.
    https://dl.dropboxusercontent.com/s/cmgci7o13jddigd/shot_170602_211558.jpg

    Painting works just fine so no issue with the actual shader it seems.

    Edit: Seems like i only get the blackness if i sue the 2 layer shader. And now for some reaons i dont get errors anymore in Texture Graph, but instead i just get some sand/clay looking texture whatever i try to assign in the graph.
     
    Last edited: Jun 3, 2017
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    This is on a Unity terrain? You should add the "FixTerrainDistance" component to it- by default, Unity will create a low resolution version of the terrain for the distance, but since MegaSplat uses a completely different format it can't do this, so it just renders black. The component basically pushes that distance out really far so you never have that happen.

    If you post a shot of your graph, I can likely tell you what you're doing wrong. I'll see if I can reproduce the error you were getting; it's likely some case like pressing prepare with no terrain in your selection or some other edge case I didn't catch. If you get a clear repro let me know.
     
  45. coling1

    coling1

    Joined:
    Apr 23, 2015
    Posts:
    2
    I have really enjoyed using MegaSplat so far. However I am coming across an issue that I'm not sure how to fix:

    When I try to make a build (Windows build specifically) my texture blending is gone and only one of my textures appears. Probably something I'm doing wrong but any suggestions would be greatly appreciated. Thank you!
     
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Yes, Unity broke texture arrays in 5.6 such that in builds on the first texture shows. This is fixed as of the patch (5.6.1.p2) that was released today (though I have only tested the new version on OSX, so let me know if it works fine on windows too!)
     
  47. gremberman

    gremberman

    Joined:
    Aug 10, 2014
    Posts:
    128
    Well that's a good news! :)
    It seems like Unity guys can sometimes do things right :p
     
  48. XenaWarriorPrincessX

    XenaWarriorPrincessX

    Joined:
    Jul 30, 2014
    Posts:
    8
    Hey Jbooth I've had lots of joy using MegaSplat and it's really the tool i wanna keep using to make my dream landscape, it's really next level stuff. I recently upgraded to 1.08 and using Unity 5.5.0f3 on a Windows machine using DX11 but i've got a few errors, I'm just a C# programmer and don't know much about shader coding but here are some things ive ran into using Unity Terrain, not a mesh:

    This is all tested in a fresh project with just MegaSplat 1.08 imported.

    When I turn on distance noise texture the shader doesn't compile and turns pink giving the following error:
    Shader error in 'MegaSplat/Terrain': redefinition of 'uv' at line 1719 (on d3d11)

    Compiling Vertex program with SHADOWS_DEPTH LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP
    Shader error in 'MegaSplat/Terrain': redefinition of 'uv' at line 4620 (on d3d11)

    Compiling Vertex program with DIRECTIONAL SHADOWS_SCREEN DIRLIGHTMAP_COMBINED DYNAMICLIGHTMAP_ON LIGHTMAP_OFF
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP
    Shader error in 'MegaSplat/Terrain': redefinition of 'uv' at line 10418 (on d3d11)

    Compiling Vertex program with SHADOWS_DEPTH LIGHTMAP_OFF DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OFF
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP

    The detail noise texture does work as expected.

    Also when i enable puddle refraction and go to the painting tab it says puddles aren't enabled on the terrain shader, yet i can still paint perfectly it just doesn't show the controls of the brush size. Also at first the puddles are extremely black, like oil, until i turn the albedo modulate all the way down to 0, don't know if this is normal behaviour or not. No errors are thrown.

    The two last things are that the dampening and wetness painting controls show when they're turned on in the shader, but they don't do anything anymore. They used to in 1.07. Global wetness works but cant paint wetness separately nor use the tesselation dampening. It doesn't throw any errors.

    So I get the result I'd like, but can't use all the tools.
    Capture.JPG

    Thanks in advance.
     
  49. coling1

    coling1

    Joined:
    Apr 23, 2015
    Posts:
    2
    That did the trick! My build matches my game in-engine now. Thanks for getting back to me so promptly!
     
  50. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,775
    Yes, I have a fix for this and can send you a patch if it's blocking you. Just send me your invoice.

    Ah, that warning must not have been updated to check for the new mode. Thanks for the catch! Yes, albedo modulate is actually going to be removed in 1.09, it really doesn't make a ton of sense anymore, and when working in linear space, it turns the puddles into black goo. Setting it to 0 will have the same result as removing the feature.

    Strange- I'll see if I can repro and fix it. Thanks for the bug reports!
     
    XenaWarriorPrincessX likes this.