Search Unity

terrain decals shader

Discussion in 'Works In Progress - Archive' started by larsbertram1, Sep 18, 2012.

  1. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    i would just like to show the shader i am working on right now which is a terrain shader that will allow you to add decals to the built in terrain without adding any geometry nor forcing any additional draw call nor shader pass: it is just a single pass shader which will allow you to use 4 detail splats + 4 detail normal splats and 4 (or even 9) additional detail decals (normal mapped) blended in according to height.

    the shader will cost only 3 additional textures being passed to it: 1 diffuse map atlas, 1 normal map atlas, 1 splatmap, so it works well within the sm 3.0 boundaries (which is 16 texture samplers – currently used like: 1 splatmap, 4 diffuse texures, 4 normal maps, 2 lightmaps).

    i am not sure whether it will support perfectly tiling detail decals as the only way i have found to incorporate these is using the "tex2Dlod" command – it gives you perfectly tiling textures but does not support anisotropic filtering.
    so i am thinking about not supporting continuous tiling textures but just single decals using the standard "tex2D" command.

    this is what i have right now:

    image 01: comparision of using tex2dlod and tex2d
    in a still image even using "tex2Dlod" looks good, but moving around the terrain will produce some rather strange artifacts.

    $tex2d _lod.jpg


    image 02: texture atlas used for the decals

    $texture_preview.jpg


    image 03: texture atlas anisotropic filtered but not allowing to use continuously tiling textures in order to hide seams. well – of course this is not what i wanted to archive but in the other hand: hey, those are just decals! just think of some smaller stones here and there, some dry twigs or blossoms…

    $tex2d_nontiling.jpg


    performance
    my first tests look quite promising:
    – using the standard terrain shader with the given terrain (size: 1000 x 200 x 1000 m, heightmap resolution: 1025, pixel error: 5) which does not support any bump mapping at all, using 4 splat maps will cost 0,31 ms in deferred rendering.
    – using the standard terrain shader with the given terrain, which does not support any bumpmapping at all, using 8 splat maps will cost 0,4 ms in deferred rendering.

    – using the modified terrain shader with the given terrain (4 detail splats + 4 normal maps + 4 terrain decals icliding their normal maps) will cost 0,31 ms in deferred rendering.

    (mac book pro, nvidia geforce 9400M)


    and now?
    well – i would really like to get some feedback: is a decal shader interesting to you – even if it does not support seamlessly tiling textures?
    do you have any other idea?

    lars
     
    Last edited: Sep 18, 2012
  2. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    It seems like this would mostly be useful when you need uneven coverage of the terrain...like leaves, or stone here and there.
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    i guess, you are right.
    but even those details would make any terrain much more unique and interesting, wouldn’t it?

    lars
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    but the best solution i can find is to use "tex2dlod" and fade in and out the decals!
    so you can have seamlessly decals.

    image

    $fading.jpg


    watch the webplayer: http://bit.ly/RpKStU

    it shows seamlessly tiled terrain decals using "tex2Dlod" and fading in and out them in order to minimize artifacts due to the missing anisotropic filtering.


    lars
     
    Last edited: Sep 19, 2012
  5. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Oh, I wasn't trying to say "it's boring, what good is it". Please don't think that, it wasn't my intent at all.

    Being able to add more detail to the terrain, without a big performance penalty is always a good thing I would think! And seeing how the numbers are -underneath- some textures, but over others...that's -very- interesting. I'm picturing old stone pathways, covered by dirt and grass.
     
  6. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    I'm curious...I was playing with the projector shader, and getting solid color projectors to paint onto the terrain (no transparency). It's a really nice effect, and I'd be interested in your thoughts on using this to get a similar effect.


    I realize this is an icon sort of effect, but it seems like it could be used to paint tiled textures onto the terrain also. I'm a complete amateur at shaders, but if a projector shader could use a splatmap, to paint tiled textures...I dunno. Just wondering.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi jc,

    as far as projected decals are concerned:
    – they do not support bumpmapping
    – they are veeeeeeeeeeeeery expensive to render as the terrain would have to be rendered at least twice…

    –> i don’t think that using projectors is a good solution at all.

    sorry about this,
    lars
     
  8. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Interesting i was in need of such shader half year ago, i found one solution on Moddb, forgot whats the project name but this one seams much easier to do.

    Oh i just run webplayer, this is way better than i thought at start. Looks awesome. One thing, is there any chance that you could get this working with your color terrain shader? Also can you change decal size that you want to paint, or is decal always the same size?
     
    Last edited: Sep 19, 2012
  9. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Thanks lars...I was afraid of that. I'll have to continue to projectors sparingly :)
    Meanwhile, I'm curious to see the uses that come out of this shader!
     
  10. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I think any kind of shader that will allow for detailing specific areas of the terrain is good in my book. If it can utilize normal and spec maps all the better!
     
  11. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    i just wanted to show you the possibility to layer decals on top of each other:

    image 01: shows 4 detail terrain textures mixed with 3 different decals layered on top of each other.

    View attachment 38602


    lars
     
    Last edited: Sep 22, 2012
  12. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Lars last picture looks great, i am wondering one thing: Lets say for example that i want to make grassy part and rocky part of terrain, where there are both parts very exagurated and clearly different, which means there is all rock texture where rocks are and all grass where grass is. Is it possible to somehow do that considering that you can use only 4 textures, this would mean that 2 textures would be for main base detail texture and 2 of them would be decals. Is that possible or do all textures have to be decals with alpha channel?
     
  13. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi janpec,

    i guess i haven’t explained very well how the shader works, so i will try again:
    first of all it is a regular terrain shader supporting 4 detail textures (plus their normal maps).
    you can paint those just like you are used to do using unity’s terrain paintbrush or import a splatmap.

    on top of these 4 regular terrain textures you have 4 additional bumped terrain decals. those are blended with the terrain textures using their respective heightmap and can even be placed on top of each other.

    so all together you have up to 8 bumped terrain textures – all drawn within on single shader pass.


    saying this means that it should not be any problem to draw rocks and grass… it is just like on any other unity terrain!
    just a have look at the pictures attached.

    lars



    image 01: just the base terrain textures: rock, sand grass –*ordinary blened

    View attachment 38605


    image 02: base terrain textures plus 2 decals (cobblestones and leaves)

    View attachment 38606
     
  14. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Lars this is exactly what i meant, its way too good. Now there is ultimate question, do you think that you could anyhow implement this with your color terrain shader? Becouse the thing is this is at the momment very difficult position, both shaders / solutions are great but i still wouldnt use this one over color terrain, if you could combine them both it would be awesome.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi janpec,

    thanks...
    as far as the colormap shader is concerned: it already uses 11 texture samplers ( + 2 for lightmapping) --> there are 3 left…
    that would be enough if you were using atlased decal textures – but that would be a very, very heavy shader!

    right now i am into rendering speed. it looks a bit like using tex2dlod is very slow – at least on my machine.
    so i might fall back to regular textures which would mean: max 2 decals…

    i will keep you updated.


    lars
     
  16. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    I think we need a new feature on the forum. Subscribe to poster.

    Your stuff is impressive as always!
     
  17. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Lol indeed, the good thing is that his stuff is always bumped on first page otherwise it would be a shame.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks.
     
  19. Schlumpfsack

    Schlumpfsack

    Joined:
    May 30, 2010
    Posts:
    608
    why isn't unity recruiting you?

    impressive, like the rest of your work.
     
  20. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    now i have done all different versions of the shader and did the first tests.
    unfortunately my bad dreams came true: using "tex2dlod" is pretty heavy.

    but the decal shader using 2 regular textures + packed normal maps (both not atlased) is pretty fast – almost as fast as a simple bumped diffuse terrain shader supporting 4 textures (4 diffuse + 4 normal).
    so you can have 2 additional decal textures at more or less no costs (despite the texture memory of course…)!
    another advantage: anisotropic filtering is back! so we don’t have to fade out the decal textures and can have them even at very far viewing distances – nicely tiled and filtered.
    there is only one drawback: both decal normal maps have to be composed into on DXT5nm-like texture which means that both normal maps will have the same resolution.

    im am pretty surprised by the fact that the 2 decals atlased shader is not significantly faster than the 4 decals atlased shader although is does only 5 additional texturelookups compared to 9 texturelookups which the 4 decals atlased shader has to perform.

    comparing the decal shaders using texture atlasing and the 2 pass terrain shader supporting 8 detail textures plus normal maps it seems not to make much sense to use texture atlasing unless the number of draw calls and triangles is not the bottleneck of your rendering pipeline – hmmmpf…
    this might even get better with unity 4 as we don’t have to pass additional textures as global textures to the shader as far as i know. so may be the nearby future will bring 8 detail textures + normal maps + 4 decal textures (2 in each pass).




    the stats

    mac book pro, nvidia geforce 9400M – deferred rendering / real time shadows enabled

    decal shader

    2 decals using regular textures:
    camera render: 0.8 – 0.9 ms
    draw calls: 120
    fps: 26.0

    2 decals atlased textures:
    camera render: 1.75 – 1.9 ms
    draw calls: 120
    fps: 19

    4 decals using atlased textures:
    camera render: 1.8 – 1.9 ms
    draw calls: 120
    fps: 15


    simple bumped terrain shaders

    simple terrain 4 splats bump mapped
    (more or less the standard shader from sixtimesnothing)
    camera render: 0.8 – 0.9 ms
    draw calls: 120
    fps: 26.5

    simple terrain 8 splats bump mapped
    (double pass)
    camer render: 1.0 – 1.1 ms
    draw calls: 209
    fps: 25
     
    Last edited: Sep 19, 2012
  21. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    thanks schlumpfsack, but there a lot of other people unity could or even should hire – before thinking about hiring me as there is no rocket science in most of the things i do.

    lars
     
  22. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Your shaders are great. Why not blend the colormap into the lightmap? That's two in one...As for your colormap shader, is it possible on any terrain size? or does it needs to be 1024x1024? Now i'm using the TriPlanar bump shader and it gives the best result. It would be great to have different tilling option in splat texture and normal map texture.
     
  23. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi eagle

    it is always a charming idea to combine as many things as possible and in fact i abused the lightmap back in unity (indie) 2.0 to get a much more colorfull terrain – but nowadays unity 4 is just around the corner, we have 3 different kind of lightmaps, i own pro using real time shadows and a lot of people use dynamic lighting. especially when it comes to large terrains having a day and night cycle is pretty common i think.
    so there is no way to bake color information into any lightmap as there just won’t be any.
    next: lightmaps are lightmaps. there are compressed in a totally different way than regular diffuse textures.
    of course there might be cases in which your solution would work*– but they are pretty rare i think. so you will have to adjust the shader yourself to fit your personal needs.

    as i have seen in the description of your – pretty powerful tool i guess – terrain composer you are doing something like this:
    i can’t imagine that this solution will be rocksolid nor will it be comfortable. it might not even be the fastest solution.
    – let’s say you got indie and bake all lighting in the terrain (single lightmap) --> might be ok then if you find a good texture compression fitting both the needs of the lightmap and the color map.
    – let’s say you want real time shadows in deferred rendering: you would have to copy color information to both far and near distance lightmap fitting their special needs – rather nasty. and you would have to update the combinded lightmap when ever you recalc the lightmaps.
    – hmm, what is about directional lightmaps? for mobile this might be a good way to go but who uses unity’s built in terrains on mobile devices?
    my conclusion would be: just handle the colormap as single colormap or combine it with something related like a global spec map. lighting simply has nothing to do with the terrain itself, so it should not be treated within the same texture.

    of course it supports terrains of any size – and even multiple terrains (with only some minor drawbacks…)

    fine. but unfortunately i does neither support deferred rendering nor lightmaps… as far as the tiling is concerned: there are no parameters exposed in the setup script but you can edit the shader to tweak it the way you would like it. my version of farfarer’s orginal version supports multi uv mixing, so this should be a very good point to start from.


    lars
     
    Last edited: Sep 20, 2012
  24. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Hello Lars,

    I haven't thought about colormap with day night cycle, but you are right, then it wouldn't work. Actually I didn't know that there was a terrain shader with a colormap for Unity, then I found out this week you created one. I haven't digged that deep into shaders, but I'm going to learn all about it. First I thought that projecting a colormap could be a solution, but that's taking too much performance. So I was thinking about making my own shader, but that would take some time. Then I thought, why not mix it with the lightmap, it works but you have to change the whole lightmap settings to make it work, it's not the cleanest solution I agree. Now I see there's already a shader that has this feature. It's really great. With Terrain Composer you can create a colormap and use it the way you want...

    How about Tesselation in Unity4? you know anything about it? It would be great to have that feature with terrain...

    Nathaniel
     
  25. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Tessellation in general is already done on terrain basically with LODs, the more you get closer the more detailed the terrain gets. Default tessellation that is currently in Unity is not really providing anything additionally needed for terrain since it does the same job as LODs do, but detail tessellation would make a difference, as long as we get some shaders. Lars might be good solution for that, but i am afraid that those shaders are really difficult to implement.
     
  26. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Why not add padding to the atlas? It will need to be the mip count squared, so a 512x512 map with 5 mip levels will require a padding of 16 pixels.
     
  27. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi nathaniel,

    we all all learn a lot each day – especially about unity‘s terrains as all its functions are not documented at all.
    so any thought or approach is really worth being tested and thought over.
    for this reason i did not want to blame you but just share some thoughts. i hope you got it this way.

    as far as unity 4 and tesselation is concerned: no, i do not know anything about it, but i would doubt that tesselation will have any effects on terrains at all.

    lars
     
  28. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi duke, i am glad to see you here.

    as far as padding is concerned: i have tested it all. my "texture2lod" indeed uses a 16px padding and works pretty well – but is rather slow: in fact it takes about 3 times compared to render the terrain using "tex2d".
    well, it needs some calculation on the lambda defining the mipmap level, but those lines are really simple math –what the shader really slows down is the tex2dlod lookup i guess. that is the reason why i won’t spend more time on investigating into this.

    you might want to read this post, where i describe my efforts in detail: http://forum.unity3d.com/threads/151660-shader-supporting-tiling-texture-atlases

    but if you have any suggestions on doing it faster, please do not hesitate to share them.

    lars
     
  29. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Hello Lars,

    Yes you are right about this, we all learn. Thank you for your valuable information. I think we all agree that the terrain needs to be improved as it's a major hole of Unity compared to Frosbite 2, Cryengine 3, etc. I'm glad people like you are working on the shaders to improve it.

    I read some interesting documentation how the terrain works in Frosbite:
    http://developer.amd.com/media/gpu_assets/Andersson-TerrainRendering(Siggraph07).pdf
    http://publications.dice.se/attachments/GDC12_Terrain_in_Battlefield3.pdf

    As for tesselation, isn't it possible to add more vertices with tesselation to the heightmap with a detail map? Instead of using a normal map.

    Nathaniel
     
    Last edited: Sep 21, 2012
  30. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    theoretically it should be possible to use tesselation with the terrain (i am really not into this) – but without any additional information (like displacement maps) it would just smooth the terrain i guess. at least it should help to reduce the popping between the different lod levels.

    lars
     
  31. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi there,

    i would just like to keep you updated about how the shader develops:
    right now i have got a version which allows you to use 2 individual decals + 2 decals using 2 of the 4 terrain detail textures running at almost the same speed as a "standard" bumped terrain shader.

    image01: cobblestones and dry leaves added as individual decal using 2 extra textures, rock added as decal using the regular detail texture of the terrain.

    $3decals.jpg


    but what are decals using the regular terrain detail textures good for?
    they will allow you to define different seams between the terrain textures: so you can have smooth blending as well as rather hard edges.

    image02: comparison of smooth blending just using the terrain detail texture and redefined edges by adding a decal that uses one of the terain detail textures (rock – of course).

    $rock_decal.jpg


    image03: another example of how you can tweak the blending by adding decals using one of the terrain textures (left) and standard blending (right) – of course you can do both on the same terrain: just go with smooth blending and / or add some decals here and there.

    $peebles_decal.jpg

    updated webplayer: http://bit.ly/Ux2anY

    lars
     
    Last edited: Sep 21, 2012
  32. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Wow looks really impressive...
     
    Last edited: Sep 21, 2012
  33. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
  34. cod

    cod

    Joined:
    Nov 26, 2011
    Posts:
    267
    hey lars, do u use xnormal to create normalmaps?
     
  35. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    no, but crazy bump.
     
  36. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Lars this is turning into similar visual quallity that ID software engine has for terrain, only if you could use 200 textures would that make better.
     
  37. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    do i get you right?
    you want to use 200 textures? well, you can do so using a texture atlas…
    but to be honest: you can easily have 4 regular textures + 9 decals from an atlas –
    or 8 + 9 using 2 passes – but using any atlas is pretty expensive to render as my tests have shown.

    so i will go with:
    4 detail textures + 2 independent /2 terrain detail map decals or even
    4 detail textures + 3 independent /1 terrain detail mapdecals

    lars
     
  38. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Awesome work as ever Lars. Big thumbs up!
    Bookmarked.
     
  39. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Yeh Lars, ID software is using insane ammount of textures, but those are not being streamed or painted like regular terrains, but rather something like Mudbox or any other 3d painting software where you are painting mesh however you want it. Those textures are then somehow stored on atlas which has different structure than Unity terrain atlas, i dont know how looks becouse nothing from ID has been released.
    Check this video to see what i mean:




    Not that i expect anything like this from single person in Unity, but maybe you would get some additional ideas from it.
     
  40. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
  41. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    Honestly...I'm more and more disappointed with Unity's terrains. If I had a dollar for every time I read the phrase "does not work on terrains", I'd have many dollars.


    If I had the shader skills...I would create a package for the asset store (free of course), that would work as a replacement.

    It would do this by
    1. Providing replacement terrain shaders that do absolutely nothing.
    2. Have a script attached that lowers the terrain settings to lowest detail.
    3. Provide a mesh component and script that reads the terrain height data, and creates a mesh that follows the terrain height.
    4. Provide mesh shaders that accept textures, bump maps, etc.
    5. Attach this to any terrain I wanted to move past 1991.

    This would allow people the freedom to use decent shaders, without the terrain restrictions, and still use the trees and vegetation.

    Would the terrain itself be as fast? At this point, I personally don't care, if it offers a decent looking terrain that isn't hamstrung in the number of textures it can handle, with bumps :\
     
  42. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Hey Lars

    Thumbs up btw, that webplayer rocks... I really love the way you always make everything come together as a whole.

    Can you please extend your webplayer to have a shader toggle, to turn the decals on and off... I'd love to see the actual impact. Right now I'm a bit confused how the tiling and blending actually works.

    Cheers
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi unlogick,

    good point!
    i have just updated thw webplayer. hit "2" to toogle the decals:
    webplayer: http://bit.ly/Ux2anY

    as far as tiling and blending actually works: all terrain decals tile perfectly over the terrain (well – as perfect as your texture does…) so i is possible to paint a whole terrain just using decals.
    blending is done using a heightmap (stored in the alpha channel of each texture): only pixels whose height is above the decals opacity (stored in the decal spaltmap) are drawn.

    image01: three different decals with opacites from 20% to 100%

    $decal_blending.jpg

    image02 area covered by a rock decal compared to the regular detail terrain texture

    $area_of_decal.jpg



    lars
     
  44. mk1978

    mk1978

    Joined:
    Dec 27, 2009
    Posts:
    276
    Some amateur questions! Do you think that I would be able to use this solution for making bunkers in my golf course visualization?

    I have been using Tom's Terrain Tools for texturing a golf course, but bunkers are causing some problems. This is because of border between different textures, see link below. I would like to have nice clean border between sand and grass texture. Also, there are about 60 bunkers in the golf course, which could cause some problems with running the visualization.
    http://forum.unity3d.com/threads/93711-Cut-terrain

    I already thought that I could us decals for creating bunkers (sand part). Based on Lars's comments, using dacals could cause some problems when sunning the visualization.
    http://forum.unity3d.com/threads/141792-Decal-System

     
  45. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Do you need something like this? My tool Terrain Composer can do that kind of heightmap editing and texturing very easy. All you need is to paint the top view of the bunkers with gradient edges in an image (on the down right corner). And set some filter settings, about the deepness, etc, and for the colormap/texturing and done, this is only the colormap by the way...www.terraincomposer.com



     
    Last edited: Sep 22, 2012
  46. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi mk197,

    unfortunately terrain decals will not really help you to paint bunkers having sharp texture edges.
    in fact decals do support sharp edges but those do not follow the drawn shape of the decal but just its heightmap:

    $decalbunker.jpg

    the outer shape or distribution of the decal is defined by the decal splatmap which usually has a lower resolution as the decal on screen. therefore the shader will have to interpolate the decal splat map which will soften its edges. as the decal splat map is combined with the high resolution decal height map the decal WILL have sharp edges but these do not follow the shape drawn to the splat map but only the decal’s heightmap.

    $decalbunker_splatres.jpg

    so in order to draw a sharp edged shape onto the terrain (and into the decal splat map) you would have to have a very high resolution splat map for the decals.
    just have a look at the images posted by eagle555. he uses a very hight resolution splatmap which reduces texture blending or soft edges between the grass and the sand texture to a very small area. but there is still some soft edge.
    so the best would be to have a splat map of nearly infinite resolution...

    the only solution i can think of is to generate a high resolution splat map within the shader by looking up 9 neighbouring pixels of the splat map and then calculating the highres version using a customized interpolation function.
    more information about image filtering can be found here: http://http.developer.nvidia.com/GPUGems/gpugems_ch24.html

    but this would be a completely different shader.

    lars
     
  47. eagle555

    eagle555

    Joined:
    Aug 28, 2011
    Posts:
    2,705
    Yes I use a splatmap resolution of 2048 and a heightmap resolution of 2048, with a terrain size of 10000*600*10000. The edges can be made sharper as I used a transition curve to go from one color to the other, but if you want an even bigger resolution, then you could split your terrain in 4 tiles of 2048*2048, and have 4 times as much resolution...of course it will have some impact on performance.
     
    Last edited: Sep 22, 2012
  48. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    @Lars: Man that is awesome. What I like most is the non blended edges. I know the guys from sixtimesnothing already did something like this a year or two ago. Using height to blend bump maps together using their heightmaps. But this terrain+decal is just taking it all the way. :)

    Only problem I see is that you need a technical texture guy to build the alpha for the decals. That mix of technical and artsy is a rare breed. I guess I'll just stick to substances for generating my decals. Any ETA on when you will release this shader to the wild?
     
  49. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902
    hi unlogick,
    thanks!

    as far as the heightmaps are concerned: i did all the heightmaps in photoshop with just some tweaks in contrast and some painting… so it should not be a problem for anybody to generate those heightmaps.

    i am just preparing the package and will it send to the asset store within the next minutes i hope.
    it is pretty late already…

    lars
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,902