Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RTP - Relief Terrain Pack with geometry blend on AssetStore

Discussion in 'Assets and Asset Store' started by tomaszek, Dec 4, 2012.

  1. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    My terrain shaders and these of RSP pack have feature called "additional_shade_supprot" or "force_shade_support" in shader code defines which give an opportunity to lightmap terrain and RSP shader materials using any lightmap type. If directional, that would be better - we'll get specular lighting. With single/dual/lightprobes - we can still get proper diffuse lighting from one light source (bumps/normalmapping effect won't badly disappear).

    In demo example I don't use lightmapping, but realtime shadows (can be turned on in panel) with rather short distance for better resolution.
    The main point is that lightmapping doesn't (yet) work much nice with blended geometry as normal blending is realised realtime in vertex program basing on terrain normals encoded in vertices colors. We might think about overcoming it by aligning mesh normals to terrain normals at edges. I'll definitely think about such feature in next update which should be released shortly as a few minor issues are to be fixed, too.

    If you'd like to make sure it works with Beast, please follow this thread as I'll probably release lightmapped web player demo version as soon as I'll manage it.
     
    Last edited: Dec 12, 2012
  2. Samsson

    Samsson

    Joined:
    Oct 12, 2010
    Posts:
    165
    Windows 8 ...
     
  3. Samsson

    Samsson

    Joined:
    Oct 12, 2010
    Posts:
    165

    Thank you for your answers. If i ask on accurate informations, it's because i used those features on others game engine and it's pretty nice but always at a cost (let's be clear, your shaderrs are awesome ! And i tested them on RTP shader pack, it's optimised)

    About terrain blending optimisation, is it a big cost for rendering/triangle count ? (if there is more polys).
     
  4. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    As you stated - shaders are optimized. I can't tell what cost exactly you're talking about. Geometry blend shader works like this:

    1. first pass - mimic terrain. On fragments where it's completely covered by regular material, expensive shading (this of terrain complexity) is skipped
    2. second pass - regular shading with alpha blending on first pass. This shader pass covers all geometry
    3. above passes are realised in queue geometry-101. As terrain is realised in geometry-100 pixels of terrain that lay under geometry will be skipped. This way when you cover terrain with plenty of geometry blend objects, underlying terrain fragment shader costs nothing (little, only vertex processing, not fragments)

    Geometry blend shader costs only in areas where we see both geometry material and blended terrain material.

    Number of vertices processed are unrelated to my shader performance. It's more fragment shader intensive, not vertex shader. If your GPU is able to render it at good framerates, number of polygons of terrain or geometries are not that crucial.

    Meantime I tweaked something. Could you check again webplayer if geometry blend issues gone ? I've also fixed shadows weren't received by blended geometries (were only on parts that shows blended terrain). Your screenshot with the issue was from webplayer I assume ?

    Tom

    P.S. had to refresh browser contents as cache had old webplayer unity file version
     
    Last edited: Dec 13, 2012
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    unfortunately pom shading seems to be corrupted under os x in the current demo…
    but pm shading works perfectly and looks great.

    lars

    $pom_shading.jpg
     
  6. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Oops... The problem is I'm doing it a little blindly as I don't have OSX machine :/
    And what about this webplayer on OSX:

    http://www.stobierski.pl/unity/Terrain_WebPlayer_release/WebPlayer.html

    Tom
     
    Last edited: Dec 14, 2012
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
  8. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Ouch, let's give it another shot as previous attempt was maybe overfixed ("...leave well alone...").

    http://www.stobierski.pl/unity/Terrain_WebPlayer_release/WebPlayer.html

    I'm also thinking about this Win8 issue of Ronan Thibaudau. As I changed some things a bit - maybe it works now (that's what I secretly hope).

    @ronan.thibaudau: I would also need to know if this didn't work in POM shading only, or in every shading fallback?
     
  9. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    Had the same issue with everything except the default shaders
     
  10. MikaelTroc

    MikaelTroc

    Joined:
    Nov 2, 2012
    Posts:
    33

    It works on my two Windows 8 machines so its probably not a windows 8 problem.
     
  11. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Problem was on Samsson machine. He could tell if it works now.
     
  12. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    So POM / PM / SIMPLE shading - looks bad ? As I'm not able to see the issue on video - could you make a screenshot and draw places where you experience problems ? I need to get idea where it's in code. If it doesn't work in SIMPLE mode, that would narrow my guesses as this is the simpliest version of my shader. SIMPLE mode screenshot preferafbly (if it doesn't work there).

    P.S. don't miss browser cache refreshment :)
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,899
    this one works fine!
     
  14. Samsson

    Samsson

    Joined:
    Oct 12, 2010
    Posts:
    165
    It now works perfectly !
     
  15. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Ta da ! I'll push update to AssetStore today. I hope it'll be there before this weekend.

    Tom
     
  16. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Incoming update has resolved lightimapping of blended meshes by baking (in the background - user even don't know about it) normals/tangents in real mesh data.

    To lightmap terrain and and geometries users will have to enable "force_shade_support" defines everywhere (in fallbacks) in terrain shader and in geometry blend shader. This works sensible with single lighmapping (simulating diffuse lighting). With directional it might not work as expected as terrain itself doesn't have tangents needed by lightmapper. Using signle lightmap the only issue is when blended geometry casts shadows on the ground and lighmap is of smaller resolution. Areas of terrain below geometry at its edges might have shadows baked and blending might not be %100 accurate.

    And a detail that might be important for users that indent to buy it in near future - Christmass sale is coming ! :) (waiting for Unity AssetStore staff moderation). Maybe a few users more will come and buy it and could give some positive feedback here or as an AssetStore product review.
     
    Last edited: Dec 15, 2012
  17. mk1978

    mk1978

    Joined:
    Dec 27, 2009
    Posts:
    276
    Here is one beginner question in order to get started with RTP.

    Is there somewhere tutorial available how to create those mixed height maps for example with GIMP or Paint.net?

    Right after I posted the question I also found the answer! So the tool is actually included in this package.
     
    Last edited: Dec 15, 2012
  18. Samsson

    Samsson

    Joined:
    Oct 12, 2010
    Posts:
    165
    I've Just bought it !

    First impressions :

    Good :
    Shaders are optimised, UI is very nice with hepl box.
    Demo can be really optimised with Lighmapping Occlusion (occlusion itselft optimise it a lot).

    Would be great : Video Tutorial with complete workflow.

    I have some trouble with lightmapping and blended meshes, but i need to do more test to determine if it comes from me.
     
  19. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Some users have problems with this tool. Apparently you can not write into any location. Choose:

    Assets/any_file_name.png

    as a path.

    Should work and will write height png into main Assets folder.

    Hint: when you'll be making the heightmap second time you can just select existing heightmap file while opening tool window. This moment your selected file path will be used as path for heightmap (for overwrite - warning helpbox will appear).

    ATB, Tom
     
  20. timbo89

    timbo89

    Joined:
    Oct 7, 2012
    Posts:
    3
    I bought this a few days ago too, really quite pleased with it! I agree with Samsson a video tutorial would have been helpful at first but the documentation is good enough to read through. Ive attached my first test setting it all up, textures are still WIP, but Im really pleased with the height blending, that really has got me excited to use this:D
    http://imgur.com/NDoAQ
     
  21. Samsson

    Samsson

    Joined:
    Oct 12, 2010
    Posts:
    165
    Hey nice timbo !

    I'm working on a Huge scene with a lot of objects, as soon as i found how heihmaps works i post screenshots !
     
  22. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    I described it a bit 3 posts above yours. Lightmapping must be enabled in terrain shader and in geometry blend shader via uncommenting define. As I said - this could not work 100% accurate in places where blended object casts shadows on the terrain - this shadowed places might reveal intersection edge. I believe this is the issue of all current geometry blending tools, but I may be wrong. I see no practical solution for this as using terrain lightmap parts on blended object might be not possible (as we can't accurately move lightmap uv coords from terrain to mesh - their vertices just don't fit).

    I'll thinking about it anyway. Maybe at some stage better idea would come to mind.


    Tom
     
  23. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    For anybody that could miss it - Christmas sale just started.

    Don't know which criteria is used by Unity AssetStore staff to mark product as "hot deal" in AssetStore. I see many featured products with its %50, but is it for choosen one ?
     
    Last edited: Dec 18, 2012
  24. ChadH

    ChadH

    Joined:
    Aug 28, 2012
    Posts:
    101
    I just noticed that on the web demo, if I check "terrain self shadow", it will lock my computer up
    Have to do a full hard reset
    iMac 27"
    3.4 GHz i7
    12GB RAM
    AMD Radeon HD 6970M 1024 MB

    Don't understand why and am a little hesitant to buy due to this lock up issue (has happened on every occasion)
     
    Last edited: Dec 22, 2012
  25. Zozo2099

    Zozo2099

    Joined:
    Jul 15, 2012
    Posts:
    478
    I imported the package, the example scene works fine, now I create new scene and new terrain, when I add a detail map everything stays white on the terrain!!! even with lighting on! why? even when I add ReliefTerrain script to my terrain everything is white! I also tested an already built terrain and all textures disappeared into white surface! but if I delete ReliefTerrain package then the terrain looks normal and textured again! so what is going on?

    And please a video tutorial would be appreciated, Reading long pdf files is not my thing! Thanks
     
    Last edited: Dec 21, 2012
  26. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Hi, this is an initial guess - have you prepared atlases ? After adding detail maps to Unity terrain system regular way you have to prepare atlased versions - there is button in ReliefTerrain script inspector (foldout option "Detail maps - "Prepare atlases button...").
    Does it clarify your issue ?

    Tom
     
  27. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Chad - could you tell me if it occurs when you turn on terrain self shadow only or with smooth shadowing ? The problem with openGL is that this kind of shaders (hi-end using expanded texture sampling features) have to be GLSL. GLSL isn't precompiled, but is distributed as hi level language to end-user computer where GPU drivers make it working on specific machine. Every machine has different drivers which may compile my shader different way - that's the real pain with Mac platform. Of course I really want to help you but my options are very narrowed as it's technically impossible to have so many machines to test shader and tweak it the way it works.

    Although definitely no shader is supposed to hang any machine (that's the rule driver producers should keep, but they don't) if the problem is with smooth-shadows I've got idea what could went wrong (possible divide by zero which may not take that drastic effect). If it hangs just after you turn on shadowing (w/o smooth shadows) - sorry, I just can't help as far as I don't make nothing much different in shadowing part comparing to POM calculations themselves and this part works for you. Shadowing is pretty the same code/algorithm like calculating parallax texture offset but traced ray is different.

    ATB, Tom
     
    Last edited: Dec 22, 2012
  28. Zozo2099

    Zozo2099

    Joined:
    Jul 15, 2012
    Posts:
    478
    Hi, yes I tried it, but I always get this red error message:

    IndexOutOfRangeException: Array index is out of range.

    ReliefTerrainEditor.PrepareAtlases () (at Assets/ReliefPack/Editor/ReliefTerrain/ReliefTerrainEditor.cs:353)
    ReliefTerrainEditor.OnInspectorGUI () (at Assets/ReliefPack/Editor/ReliefTerrain/ReliefTerrainEditor.cs:40)
    UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:888)
    UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/14194e8ce88cdf47/Editor/Mono/Inspector/InspectorWindow.cs:243)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)


    BTW, I only test with one detail map in my terrain textures tab!
     
  29. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    I'll take a look what went wrong ASAP, but I doubt Unity would take my update before Christmass. I didn't tested it for that small number of detail maps (makes no sense to make atlas with one texture and rest blank - use different terrain replacement system if you don't need more :D ). I believe for larger number of detail maps it should just work like in demo scene. Thank you very much for giving me this feedback bug, but I'm asking you for a bit of patience in this holidays time (my family first, sorry...).

    Best Regards, Tom

    EDIT: replace line 353 in Assets/ReliefPack/Editor/ReliefTerrain/ReliefTerrainEditor.cs with this one - will work:

    Code (csharp):
    1.  
    2. splats[i]=new Texture2D(terrainComp.terrainData.splatPrototypes[num-1].texture.width, terrainComp.terrainData.splatPrototypes[num-1].texture.width);
    3.  
    EDIT 2: It's also true that RTP doesn't work well with less than 5 detail textures. As it's everything compacted into one pass using less detail texutres is wasting GPU computation power and its memory. I'll think about simplier version (4 POM without atlasing - should work bit faster) in next updates.
     
    Last edited: Dec 22, 2012
  30. ChadH

    ChadH

    Joined:
    Aug 28, 2012
    Posts:
    101
    This happens with self shadow only
     
  31. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Not much can be done on my side. The only thing I can think of is that static branching may cause troubles (while shouldn't). Below are 2 versions of web players where I turned off static branching on shadows. Shadows themselves are just turned on:

    http://www.stobierski.pl/unity/Terrain_soft_shadows/WebPlayer.html

    http://www.stobierski.pl/unity/Terrain_hard_shadows/WebPlayer.html

    If neither first nor second will work - I can't help. The problem might be anywhere and is beyond of my scope (there should be no shader that could crash Unity, but it does :/ ). However it might be the case that different version of the shader (updated later on) could work as it would compile into different code.

    Tom
     
  32. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Step-by-step instruction requsted by one of users, but might be useful for others:

    1. prepare 8 (less is wasting resources) diffuse maps (preferably 512x512 for performance reason). Alpha channel of diffuse maps will be used as specularity channel (using simply rgb textures is also OK, but whole texture will have the same - maximum - specularity).

    2. for each of detail map prepare normal map (standard Unity's) and height map (the same size as diffuse maps)

    3. add these 8 detail maps to the terrain you want to work on using standard Unity's terrain interface. You handle / paint your terrain as you'd do using regular Unity's terrain system.

    4. attach ReliefTerrain.cs script to that terrain

    5. in my script inspector unfold "Detail Maps" - set tiling, click button to prepare atlases. Slider is used to modify how sharp will be blending between different detail maps basing on their height maps

    6. You might need to unfold "Control (alpha) maps" and click first "refresh" button

    7. Unfold "Normal maps" in terrain script inspector and put there normal maps (in the same order as diffuse maps are, of course). You might ommit some - will be considered "flat" but it still need GPU RAM and GPU computational power. Technicaly there are 4 textures created at runtime - each 2 textures normal pair is encoded into one texture (RG + BA). This is, however, transparent for user (you don't need to know it).

    8. Unfold "Height maps" section. You'll need to feed it by 2 textures. First will represent heightmaps 0-3 (associated with detail maps 0-3), second will represent heightmaps 4-7. Eight in sum. To prepare such 4 channel heightmaps (RGBA - every color channel represent different heightmap) use attached tool "Window / Relief Tools / 4 to 1 texture channel mixer". Tool will need 4 textures of the same size. You can specify which channel of source texture will be used as output channel.

    For example choosing R,R,B,G will result in target texture that has:

    - red channel from red channel of the first source texture (R),
    - green channel from red channel of the second source texture (R),
    - blue channel from blue channel of the third source texture (B),
    - alpha channel from green channel of the fourth source texture (G).

    Resultant height texture will represent 4 height maps. So you simply put 4 source heightmaps (grayscale) that are associated with first 4 diffuse maps, adjust channels if needed and get first "compiled" heightmap.
    Then choose second 4 source heightmaps and get second "compiled" heightmap. These two "compiled" heightmaps are just needed as params for our "Height maps" section.

    Some users got problems with specyfing working folder for output "compiled" heightmaps. Proper path should be like this:

    Assets/filename.png

    which will put "filename.png" into main assets folder. If you need to put it into another place:

    Assets/folder name/filename.png

    and so on.

    Hint: if you had texture object selected in project window the moment you invoked the mixing tool, then this file will be treated as "target" - output path (might be overwritten, asked before)

    9. Specify "Global colorMap" - RGB(A) texture that will cover the whole terrain and will multiply it's color with detailmaps. There are 3 distance ranges there - at the very close camera distance (near blend) no global color map is used. Global color map is fully used at distances far than "far blend", and gradualy at distances "mid blend" to "far blend".

    10. Specify "Global normalMap". It's very usable when we'd like to add faked detail at distance (low-poly terrain at far distance which looks like high-poly). You can adjust "tiling scale" there, so that even using small (256x256 perlin noise normal map) texture will give fine results. You might, however, use hi-res global normalmap that cover whole terrain if you want (set tiling to 1 then).

    11. Settings:

    - Distance degradation - distances where full POM/PM computations are realised. Making these distances too big will drop the performance (and won't improve the quality as we don't see tiny details at far distances anyway). Keeping it too small will cause that terrain won't be rendered at full quality close to the camera.

    - POM/PM Extrude Height - how deep to extrude the terrain

    - Color/position solver - number of steps 15-30 are reasonable. Step length - 1-4 are fine. 2 works good for my heightmaps. Too hight value - better performance, but you'll loose the quality. Too low value - the opposite.

    - Self-shadow solver - the same as above. Smoothing steps - steps to realise smoothing (apply only for smooth self-shadowing). Bigger number of steps can drop the performance. I guess values used by me are just fine, but you might tweak them.

    - Shading strength for light - used only when you uncomment such line (a few occurences):

    #define force_shade_support

    in very subshader (find this using script text editor search feature)

    in files "ReliefTerrainReplacement.shader" and "ReliefTerrainGeometryBlend.shader".

    It's used for lightmapping terrain (single or dual, terrain can't be used with directional lighmaps as it doesn't have tangents).

    12. "Detail color blend" foldout - for each of detailmap you can mix it with itself but using different tiling. This is useful when you'd like to hide "patternization" issue (distinct patterns when larger area is covered by the same detail texture so that we see many tiles)
     
    Last edited: Jan 7, 2013
  33. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Script code fragment that will setup different LOD level ( POM / PM / SIMPLE / CLASSIC):

    Code (csharp):
    1.  
    2. Shader replaceShader=Shader.Find("Hidden/TerrainEngine/Splatmap/Lightmap-FirstPass");
    3. Shader geometryBlendShader=Shader.Find("Relief Pack/TerrainGeometryBlend");
    4.  
    5. replaceShader.maximumLOD=700; // 650 for PM, 500 for SIMPLE, 400 for CLASSIC
    6. geometryBlendShader.maximumLOD=700;
    7.  
    8. Terrain terrain=(GameObject.Find("Terrain").GetComponent (typeof(Terrain))) as Terrain; // "Terrain" is game object name in scene which is our terrain
    9. ReliefTerrain script=terrain.GetComponent(typeof(ReliefTerrain)) as ReliefTerrain;
    10. script.InjectBasicMaterialParams();
    11.  
     
    Last edited: Jan 8, 2013
  34. dirtybassett

    dirtybassett

    Joined:
    Oct 3, 2012
    Posts:
    59
    Shader doesn't seem to work in DX11 mode.
     
  35. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Haven't tried it yet, but it is intented to work in DX9 / OpenGL. In DX11 I'd just use tesellation instead of parallax mapping - which is anyway good idea to introduce in next RTP updates (special version of shader for DX11).

    Tom
     
  36. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    For DX11 issue - the reason RTP shaders don't compile right for DX11 is they have one tiny line of code which is almost uncatchable - especialy when Unity shader compiler resists to give right line number of problematic code. With shader consisting of hundreds of lines this can be real pain (believe me) :).

    Anyway the tiny line has been catched at last:
    Code (csharp):
    1.  
    2.         float4 rayPos = float4(IN._uv_Relief.xy, 1.001, mip_selector);
    3.  
    should look like this

    Code (csharp):
    1.  
    2.         float4 rayPos = float4(IN._uv_Relief.xy, 1.001, mip_selector.x);
    3.  
    I'll make update of RTP ASAP, but I'd like the same time to put there some other improvements, meantime DX11 users could try above solution (find/replace this in shaders). Tell me if it works for you.

    I also think that for special case of DX11 shader should be rewritten anyway to get most of new features like tessellation instead of parallax computations. I'll look into this and try to implement the way it works the same ... but better (it however shouldn't break the way RTP works so that you're able to "upgrade" to new DX11 shader version w/o much hassle).

    ATB, Tom

    P.S. Is it only my GT540M drivers on laptop (Win7) pretty unstable, or... (shader start work after above fix, but Unity itself causes display driver errors from time to time :/ ). Seems like Unity has still long way to master its features...
     
    Last edited: Jan 10, 2013
  37. deckard

    deckard

    Joined:
    Sep 15, 2009
    Posts:
    158
    Hello Tomaszek,

    I have just purchase the Relief Terrain Pack and I am very disappointed because I can't get the example scene to work on my PC. Although your example scene works fine when I launch your webplayer demo, it seems that the shader just falls back to diffuse when I open it in Unity.

    In fact, the shader only works on the blend geometry but not at all on the terrain.

    I am using Unity 4.0 but not in DX11 mode.

    How can I solve this?

    Thanks a lot for your help.
     
  38. deckard

    deckard

    Joined:
    Sep 15, 2009
    Posts:
    158
    I have just tested the example scene in Unity 3.5. It works just fine.
    The reason why the shaders fall back to diffuse in Unity 4.0 is that they don't compile, even in d3d11_9x mode.

    Are you planning to make an Unity 4.0 compatible version of your pack available any time soon? (at least in d3d11_9x mode)
     
  39. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Making things working on Unity4 is top priority now. Which platform / GPU you're on ? I tested it on my XP/GT240 in Unity4 (DX11 mode off) - works fine. Anyway I'll be looking into the issue of potential d3d11_9x compilation errors.
     
  40. deckard

    deckard

    Joined:
    Sep 15, 2009
    Posts:
    158
    I am using Windows 7 64bits / GeForce GTX680

    Would you like me to send you the list of the compilation errors on my PC?
     
  41. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Did you get my priv message with DX11 issue treatment ?

    What we should aim for is making this working in d3d11 mode. d3d11_9x is shader version for Windows RT which is for now skipped by me (very fussy platform which probably won't work with my shader as it's unable to unroll some loops inside shader code).
     
    Last edited: Jan 11, 2013
  42. deckard

    deckard

    Joined:
    Sep 15, 2009
    Posts:
    158
    Hello Tomaszek,

    Thanks a lot for your private message and the attached shaders.

    I have tested them in Unity 4.0 and here is the result:

    - The new shaders seem to work fine in Unity 4.0 with DirectX11 mode OFF. This is great news! By the way I thought that d3d11_9x typically meant "Unity 4.0 with DirectX11 mode OFF". My mistake :$

    - The new shaders are half working in Unity 4.0 with DirectX11 mode ON:
    - in the editor I can launch the example scene with the shaders working but with random 1s-2s image freeze. The PC even crashed once.
    - launching a build in windowed mode gets the same results as in the editor: random freezes
    - a build crashes at launch in full screen mode

    Here are the compilation errors I get:
    - ReliefTerrainReplacement shader
    Program 'frag-surf', Microcode Compiler internal error at line 721
    Program 'frag-surf', Microcode Compiler internal error at line 876

    - Terrain2Geometry shader:
    Program 'frag-surf', Microcode Compiler internal error at line 706
    Program 'frag-surf', Microcode Compiler internal error at line 862

    Both the AddPass shader and the ReliefTerrainGeometryBlend shader show no error

    I hope that this will help.

    Thanks again.
     
  43. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    I'll try to check it again in DX11 mode on my laptop (I also experienced freezes / crashes). I hope there is anything I can do with it, cos it doesn't sound much optimistic (shader might not work if quite badly written, but crashes are out of my scope !). I'll probably even try to rewrite DX11 versions of shader from scratch. I'll post it ASAP.
     
  44. deckard

    deckard

    Joined:
    Sep 15, 2009
    Posts:
    158
    I have spent several hours testing your package with my terrain data and I must say that I am very pleased with the rendering quality and ease of use.

    I don't understand how to modify the splat map manually though. I have been unable to modify the applied splatmap with your script so far, neither by drag and dropping the texture map in the slot nor by clicking select and browsing the assets. I must do something wrong.

    I am currently using "Tom's Terrain Tools" instead to assign my proprietary splatmaps.

    Manually combining the masks (generated with World Machine in my case) in Photoshop to generate the RGBA splatmap proves very tedious so your "4 to 1 channels mixer" tool is a great idea. But I believe that this tool does not generate the correct data currently.

    It seems that you are basically copying each greyscale mask to one of the channels of the final RGBA splatmap. In my opinion, this does not produce the desired result.
    We can compare the various materials of the terrain to layers placed on top of each other, starting with the R channel layer, then the G channel layer and up to the A channel layer.

    Suppose you want to texture a terrain with only two surface types, for example "grass" and "rocks". You could use the R channel layer for the "grass" and the G channel layer for the "rock". The two other channels would remain unused.

    If you decide to manually paint the splatmap in Unity, here is what will happen:
    - unity will automatically and entirely fill the R channel with the base layer: "grass".
    - then you will use the brush to paint the "rock" layer, drawing into the G channel of the splatmap.
    - you will end up with Red and Green only splatmap, defining where the "grass" and "rock" layers have to be placed on the terrain.

    Now suppose you decide to use an external software like World Machine to generate the mask for the "rock" layer. World Machine will generate a black and white mask, white representing the area where the "rock" layer is supposed to appear.
    the "grass" layer is represented by a very simple mask which is entirely white because it is the base layer.

    If you use the "4 to 1 channels mixer" tool, you will place the R channel of the entirely white mask in the first slot (the G or B channel would work too) and the R channel of the "rock" mask in the second slot.
    You will leave the two remaining slots empty and generate the splatmap.

    The tool will generate an image containing an entirely filled R channel and a G channel filled only in the "rock" area of the terrain. The B and A channels remain empty.

    if you compare the two splatmaps, the one manually painted in Unity and the one generated and processed with the channel mixer tool, they are not consistent:
    - the Unity splatmap is Red and Green only
    - the generated splatmap is Red in the "grass" area and Yellow (R+G) in the "rock" area.

    This means that instead of placing only "rock" in the area where the G channel is white (the "rock" mask), the shader will mix the "grass" and the "rock" in those area.

    The only way to generate the correct data would be for each channel to act as a mask for the underlaying one. The process to automatically generate the final splatmap would be a bit more complex to code but it would be great if you could update the tool.

    In fact, it would also be great if you could rather do a "8 to 2 channels mixer" tool which would use the 8 masks in input and automatically generate the two splatmaps. Because the masking problem which occurs between the channels of a given splatmap also occurs between the two splatmaps.
     
    Last edited: Jan 12, 2013
  45. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Deckard,

    Your approach proves you perfectly understand how Unity terrain splatmapping works, but my "4 to 1" mixer works .. different :). It's not supposed to make splatmaps (control maps). It's intended to merge 4 textures with and choosing arbitrary channels we can combine them into one 4 channel _height_ map for RTP (not control map). Control maps I'm showing in my script is what Unity generates and I put it there with save feature to let users copy this. I didn't implement splat manipulation other than Unity's built-in. As now it have to be implemented by user, but your idea is great and I think feature that allow users import alpha (grayscale) textures from 3rd party tools like WorldMachine and inject the results into RTP, but this should be different kind of script.

    First - when we've got white grass texture and grayscale rock texture (white - rock, black - underlying layer) we should "normalize" resultant texture so that sum of r+g+b+a channels of splat map gives 1 (or less in case we've got more than 4 layers used). I have to to take a look which kind of output WorldMachine generates and then write some kind of script that would take this and make correct splat map that could be used in RTP. This is not big problem and such feature would be present in coming RTP update. What worry me more is this DX11 instability (this is not only problem of my shader, I've got info from somebody using different DX11 shader which also causes display drivers freeze... so Unity QA / graphic programmers DO something !).
     
  46. deckard

    deckard

    Joined:
    Sep 15, 2009
    Posts:
    158
    Thansk a lot for your explanation I really thought that the 4 channels mixer tool was for splatmaps, not heightmaps.

    a splatmask combination tool would be really great. Doing it manually in Photoshop drives me crazy. I should write a Photoshop script to automate the process.

    You are right about the normalization of the splatmap. Tom's Terrain Tool performs it when importing the splatmap. But you still have to generate them in an external tool.

    World Machine exports the masks as greyscale pictures in 8bits or 16bits and in a variety of formats. I am not using the 16bits option since each channel of the splatmap is in 8bits anyway.

    Let's hope that the Unity developers will find the DX11 problem. Have you reported a bug?
     
  47. caldrin

    caldrin

    Joined:
    Dec 4, 2011
    Posts:
    127
    I msut be doing somthing wrong still hehe..



    Why do i get grey blobs instead of POM height?
     
  48. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    As played whole day on my DX11 laptop (built-in Intel HD3000 as DX10, GT540M as DX11 on Win7) I hopefully detected the issue. The problem isn't much logical, but seems to break shader. So tell me if this works for you:

    1. comment all lines (in all shaders) that starts with (this crashes in DX11 / openGL on GT540M HD3000):

    _TERRAIN_DIST_STEPS*=

    2. comment all lines (in all shaders) that starts with (this does not compile right for openGL on HD3000):

    _TERRAIN_SHADOW_STEPS=min(

    These lines are not necessary - constitue a little bit of performance gain in some situations, but in our case they seem to introduce some kind if "overoptimization" issue :).

    If it only works for you in DX11 mode - we've got it...

    I'll also work on splat import features you'd like to have.
     
  49. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862

    Do you use all 8 detail layers in RTP ? System doesn't work much good with 4 or less layers. I'm doing simple version of shader for 4 layers for next RTP update (no atlasing will be needed).
     
  50. caldrin

    caldrin

    Joined:
    Dec 4, 2011
    Posts:
    127
    ah only used 4 as a test.. no probs i shall up it to 8,

    thanks