Splat shader

I’m trying to create a splat shader which blends four textures based on the RGBA channels of a fifth texture. I’ve been mucking about with Bill’s LayerShader, but I can’t figure out a way using the fixed pipeline to blend based on anything other than the alpha channel.

Could someone perhaps point me in the right direction on this?

This can be hard to do in fixed function. About the only way I an think of is using dot product texture combiner, but then you’ll probably run into combiner count limit. In a shader that would be much easier.

How would I use the dot combiner to do this? I’m having a lot of trouble trying to understand Cg from the example given.

Eek, it’s not even documented! Adding note for myself to doc it…

It’s basically “dot3rgba” operator, so where you could write something like

combine texture * primary

in a similar way you can write

combine texture dot3rgba primary

This treats both arguments as signed numbers (black=-1.0, gray=0.0, white=1.0), does a dot product between them, and outputs the value to RGBA channels. There’s also a “dot3” operator, the only difference is that it outputs to RGB channels only, leaving alpha unmodified. Both are direct correspondence to ARB_texture_env_dot3 OpenGL extension.

…but now that I think of it, it probably will be really hard to blend four textures using RGBA channels as blend weights in fixed function.

That means we need more and better docs… Point taken :slight_smile: And the four-layer terrain shader is on it’s way to the wiki…

The shader is on the wiki: http://www.unifycommunity.com/wiki/index.php?title=TerrainFourLayer

Thanks very much, but the shader doesn’t work how I’d expect it to. It seems to be adding everything. Here is my material:

Here is the alpha channel for the mixing texture:

And here is the result:

Whoops, a typo bug was on the “mix the four layers” line (+ instead of *). I updated the shader on the wiki.

Works perfectly now. Thanks so much!