Search Unity

Splat shader

Discussion in 'Shaders' started by Daniel_Brauer, Jul 21, 2007.

  1. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    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?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    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.
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    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.
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    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
    Code (csharp):
    1. combine texture * primary
    in a similar way you can write
    Code (csharp):
    1. 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 :) And the four-layer terrain shader is on it's way to the wiki...
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
  6. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    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:
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Whoops, a typo bug was on the "mix the four layers" line (+ instead of *). I updated the shader on the wiki.
     
  8. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Works perfectly now. Thanks so much!