Terrain Decal Shader [RELEASED]

Hi there,

after some time of working on my terrain decal shader, testing and optimizing it i finally sent it to the asset store.

released: ats Terrain Decals | VFX Shaders | Unity Asset Store

Add up to 4 different normal mapped decals to your terrain -
perfectly blending with the default terrain textures at almost no additional rendering costs.

This shader gives you the possibilty to use 4 normal mapped detail textures plus 2 independend decals plus 2 decals based on the terrain’s detail maps to spice up your terrain.

Watch the shader in action: http://bit.ly/Ux2anY

Features

  • no extra geometry needed, no extra draw call: all computation is done within the terrain shader - within a single shader pass.
  • almost as fast as just using 4 detail maps and the standard first-pass shader.
  • decals are blended based on their heightmap and allow you to seamlessly add small details like cobblestones, dry leaves or flowers.
  • simply add decals using unity’s built in terrain paint tool.
  • shader supports enhanced multi uv mixing providing crisp details on close viewings distances fading into lively normal mapped structures on far viewing distances.

1 Like

Stats

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

decal shader
4 splats bump mapped [1 using multi uv mixing] plus 4 different decal textures
camera render: 0.8 – 0.9 ms
draw calls: 120
fps: 26.0

simple bumped terrain shader
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

The ability that this shader allows you painting roads on terrain with stones fading away gives this shader high value. I am wondering how do you control blending of texture? You have said that it is by heightmap but what exactly does this means? The higher the terrain more full is texture?

Also Lars do you think there is any possibility that you could implement this for meshes too? I would really need it for rock and ice meshes so that different decals could be painted on, i am guessing that it would require some sort of vertex painting to do that. Not sure if you are doing terrain shaders only but if not then this could also be usefull.

Wow, looks lovely Lars. What’s the price going to be?

Edit: Just finished looking at the demo, make that a “double Wow!”. :wink: I think this will be a “must have” for realistic terrain creation. Looking forward to getting this! Which versions of Unity will this be compatible with? Would it work with earlier versions (ie. 3.4)? Still have a couple projects I haven’t updated yet.

hi janpec,
blending is controlled by 2 factors: opacity in the decal splatmap and the heightmap of the decal texture (which is stored in the alpha channel of the diffuse map).
like for the 4 detail terrain textures there is a special splat map just for decals which controls their distribution. this allows you to simply paint decals onto your terrain using unity’s built in paint tool.
by painting decals onto the terrain you specify where to place decals and at which opacity.
this opacity is then taken by the shader. but in the case of the decals it does not simply blend between the detail and the decal maps but also looks up the decal’s heightmap and draws only those pixels of the decal textures whose height is above the opacity given by the splat map (no “if” or simple “cut out” but rather by manipulation the contrast of the heightmap so you will get decals with very small but nice soft edges like shown in the next picture):

1043038--38706--$Bildschirmfoto 2012-09-23 um 14.04.19.png

as far as blending and opacity is concerned please have a look at the picture below: it shows decals drawn with 20%, 40%, 60% and 80% opacity (from left to right).

1043038--38704--$03create.jpg

as far as the heightmap of the decals is concerned: it is a rather simple greyscale image which defines the height for a given pixel: 0 = lowest height / 1 = full height, so the heightmap of the cobblestone texture looks like this (left: diffuse / right: heightmap):

1043038--38705--$cobbles_alpha.jpg

your are right: in order to use a shader like this on regular meshes you will need to specify the distribution of the decals either by a splat map or vertex colors.
for regular meshes i would rather go with vertex colors and their is already a solution to do so on the asset store.
maybe you would have to change the blending function. but i am pretty sure that if the author reissgrant hasn’t already written such kind of blend shader he will do it for you.

lars

thanks bigkahuna,

the price will be 5$ – not free this time but rather suitable i think: less than 2 beers…
i have written the shader in unity 3.5.x? but it should also work with unity 3.4 i guess.
and i will bring it to unity 4 when it has been released.

lars

Yes there is but it doesnt have as good blending mode as your terrain shader, you have much more advanced blending and painting method thats why i was asking.

$ 5 or free is almost the same thing. Great product and great price. Future customer. :wink:

thanks, i hope you will think so!

cheers,
lars

hi janpec,

i am glad i found a way to use the built in painting tools as writing my own painting system has never been an option for me.

as i don’t own reissgrant’s vertex painter i do not know how his painting methods works on arbitrary meshes, but if you need a heightmap based blend shader i would just ask him for one. i can’t imagine but in case he could need some help on the shader he can just contact me.

lars

Agreed.

FYI the webplayer runs surprisingly well on my ancient MBP with x1600 graphics. Can’t wait to try this on my dev machine.

hi bigkahuna,

thanks.
in fact i could hardly measure any difference between using a “bumped diffuse first-pass terrain” shader and the decal shader: it is 3 more texture lookups and some computation but all happens within one single pass. so its faster to use the decal shader (4 standard splats + 2/2 decals) than using 8 standard splats (which would force a second pass).

lars

Thats probably because they’re memory-bandwidth limited, rather than computation limited. So the two extra textures might cost something, but the lookups and computations are concealed by the memory bandwidth stuff. On some hardware you could probably get away with even heavier computations, though on other hardware that would cost extra.

hi there,

i have been off for a few days –*but meanwhile the decal shader has been accepted by the asset store!

lars

As I’ve long been waiting for. Thank you so much.

you are welcome :wink:

I’m very bad speak English, so using Google translator.
So what am I?
I use to work your shader. Shader uses two terrains.
Terrain Decals and Terrain Paint. When included both terrain
1048916--38964--$sshot-3.jpg
Then, I shut off Terrain Paint
1048916--38963--$sshot-4.jpg
Of course the performance increase.
But this is not surprising.
All decals on the ground remained.
Why then use Terrain Paint?

And, yes in Unity 3d 4beta work!!!

This looks insanely cool. This is probably a very effective way to make paths and such. But how is it compatible with your other shaders?

hi Alexmarch1,
i am glad that the shader and its workaround seem to work for you – even in unity 4 beta!

now to your question:
the second terrain is only needed when editing/painting the decals.
the distribution of texture 5 - 8 of the 2nd terrain (which represent the 4 decals) are painted to and stored in the 2nd splatmap of the 2nd terrain.
(the first terrain – the one you actually work with – has only one splatmap.)

it is absolutely ok and very recommended to turn off the second terrain after you have finished painting the decals.
you can even delete it from the hierachy – but not from your project tab.
as you have already noticed doing so will bring back the number of tris and draw calls to what you would expect.

but as you might want to edit the decals later on i would recommend to only utrn the second terrain off and not to delete it from the hierarchy.

lars

hi sevenbits,

this shader is NOT compatible to any other terrain shader as there can only be one!
so if you want to use decals you can’t have any color map. or snow.
but you can have multi uv mixing (like in ats v.2): in fact the shader already supports multi uv mixing (to improve texture tiling) in a much more advanced way like the ats v2 shader does.

it does not support color maps or snow as it already reaches the limits of shader model 3: the max. number of textures in sm 3.0 is 16. so you will have to decide to either go with a color map shader, the snow shader or decal shader.

i have written the decal shader just to give you the highest amount of detail textures possible within one shader pass, so you can use 6/8 textures instead of just 4 without nearly any draw back as far as performance is concerned.

the color map and snow shader were designed to support just different scenarios.
but whereas the color map shader really needs all 16 available textures of sm 3.0 the snow shader could be simplified (dropping the snow texture → replacing it by a simple white… and dropping the snow distribution texture replacing by: – nothing…) to support decals.

lars