Heightmap-based (and now normal-based) material blending (WIP)

After watching this UDK vid, I wondered if I could write a simple shader for Unity to do the same, one that would hopefully also work on SM2.0 hardware.

I extended the parallax specular bump shader to use the heightmap of a material to determine whether or not to blend a second material onto it, so it appears that the depressed areas of the first material are filled in with the second material. To decide the area covered by the second material, I used the red channel of the vertex colour.

The results so far:

The following vertex colours:

yields:

And the shader just fits into the 64 instruction limit, with parallax of the first material.

there is a tool that already exist to do so. thread from reissgrant and another one from werewraith. extended with 3 vertex colors for blending material

Still, a very nice idea to use heightmaps to further influence the blend!

As Werewraith(whose blending demo is gorgeous, and does seem to be able to achieve the same effect - does it take depth into account?) says, this shader fills in the depressions of the primary material with the secondary material, allowing modelling of sand or snow on a hard surface. Maybe I didn’t make that clear enough. Further materials could be added, but not within the 64 instruction limit of SM 2.0, especially as the hard surface material really needs parallax offset mapping to increase the illusion of depth.

I was thinking it could be used with Reissgrant’s vertex painter tool to allow painting of sand/snow in the editor in realtime.

This looks really great, keep up the good work.

Good work. Another variation would be blending based on normals direction. Would that be able to fit into a 64 instruction set?

BTH

Thinking about it, that should (famous last words) even be easier. I’ll have a go.

Blending by normals direction (taking into account normal map as well):

In this case, a snow texture blended where the normals were pointing approximately up (given a slider to set the deviation from a vector set to up).

I was right, inasmuch as it was a little more difficult than I first thought, but only 38 instructions!

Great, great stuff!

A somewhat smoother version of the last shader:

My hands are starting to play up, so that’ll probably be it for a few days, but it was good fun!