Hi, I am trying to use an alpha channel (or another texture) as a mask for a second texture. Normally something like the following works fine Code (csharp): Pass{ Material { Diffuse [_Color] } Lighting On // Set up alpha blending Blend SrcAlpha OneMinusSrcAlpha SetTexture [_PathTex] { Combine texture * primary, texture } but what I need is for the texture "_PathTex" to be tiled with a much higher frequency than the alpha mask ie. the "Scale" in the placement for the texture might be say 16, whilst the "Scale" for the alpha mask might just be 1. Does this make sence? thanks, Richard.
It's OK - I think I have sorted it for the moment: Code (csharp): Blend OneMinusSrcAlpha SrcColor SetTexture [_HillTex_B] { Combine texture * previous } seems to do the trick. Richard.
Hi Nicholas, That is what I have been doing - I'll post some images shortly to try illustrate what I am after. thanks, Richard.
Well, I am stuck. This is how far I have got: Code (csharp): Shader "TerrainShaderMkII" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _PathTex ("Path Texture (RGB) Mask (A)", 2D) = "white" _PathMaskTex ("Path Mask (Grey) ", 2D) = "white" _PlainTex_A ("PlainTex_A (RGB) Mask (A)", 2D) = "white" _PlainTex_B ("PlainTex_B (RGB) Mask (A)", 2D) = "white" } SubShader { // Base texture - bottom layer (rendered first) Pass{ Material { Diffuse [_Color] } Lighting On } //end pass // ============= // path Texture // ============= Pass{ Material { Diffuse [_Color] } Lighting On SetTexture [_PathTex] { Combine texture * primary } } // end pass // ============= // path mask // ============= Pass{ Material { Emission (1,1,1,1) } Lighting On // Blend current_tex_pass previous_tex_pass Blend OneMinusSrcColor SrcColor SetTexture [_PathMaskTex] { Combine texture * previous } } //end pass // ============= // path texture // ============= // Pass{ // Material { // Diffuse [_Color] // } // Lighting On // Blend OneMinusSrcAlpha SrcColor // SetTexture [PlainTex_A] { // Combine texture * previous // // } // } // end pass } FallBack " Diffuse", 1 } and this is what I get (see image). As you can see the cobbles tile with a large Scale=32, whilst the path mask only has scale=1. That gives the path where the mask is white which is fine. However, I now want the black reagion of the mask to render with the "PlainTex_A" texture, also with a large scale=32. I am stuck - do I need multi texturing to do this? thanks, Richard.
In general, multitexture is the way to go. I've just added some examples for it last night, so take a look here: http://tikiwiki.otee.dk/tikiwiki/tiki-index.php?page_ref_id=254
Richard, that is a really cool shader combining 2 different tiling frequencies with alpha. Is the above code snippet you posted what it takes to get it to work? Nicholas, what's this http://tikiwiki.otee.dk/tikiwiki site. Is it a wiki run by OTEE, why is this the first time I've seen it? Is this going to be another wiki in parallel to Outcast's wiki?
It's the internal wiki used at OTEE for writing the Unity documentation. It's public access to the bleeding edge changes in the docs before they are extracted and put up on http://otee.dk/ . Being a life snap shot into a work in progress, the docs will contain more errors than the published ones, but it is occasionally useful to get external parties to take a look at it before release to iron them out.
I'll post some code and screen snaps in a day or two - it is working quite well now -- just wish we had lod for terrains richard.
I have been wishing for some system like this for a while. Good going and I hope you will be willing to share!
Nice work! Any chance of getting a copy of that shader pretty please? I am doing some terrain and would like to use this method for terrain details (roads, etc.) Thanks, -Jeremy
Here you go: Code (csharp): Shader "Terrain3L" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _Shininess ("Shininess", Range (0.01, 1)) = 0.7 _PathTex ("Path Texture (RGB) Mask (A)", 2D) = "black" _PathMaskTex ("Path Mask (A)", 2D) = "black" _MudTex ("Mud (RGB)", 2D) = "white" _MudMaskTex ("Mud Mask (A)", 2D) = "black" _GrassTex ("Grass", 2D) = "white" _GrassMaskTex ("Grass Mask (A)", 2D) = "black" } SubShader { Pass{ Material { Diffuse (1,1,1,1) } Lighting On SetTexture [_PathTex] { combine texture * previous } SetTexture [_PathMaskTex] { Combine texture lerp (texture) previous } } // end pass Pass{ Blend one one SetTexture [_GrassTex] { combine texture } SetTexture [_GrassMaskTex] { Combine texture lerp (texture) previous } } // end pass Pass{ Blend one one SetTexture [_MudTex] { combine texture } SetTexture [_MudMaskTex] { Combine texture lerp (texture) previous } } // end pass } FallBack " Diffuse", 1 } The shader above has three layers but you can add as many as you like (And your card can take). It is rather crude code as I am not a shader expert - but it works in simple cases. Attached should be a screen snap of the shader in Unity and an image of the three alpha masks. Note the scale of the placments for the various textures. cheers, Richard. Edit: Ooops - forgot to open the Grass placement - the scale is the same as the Mud: 150.
There is also Bills shader on Unifywiki: http://unify.bluegillweb.com/scriptwiki/index.php/LayerShader Richard.
Thanks a lot man. Very nice of you to share your code with us. I have been talking to Bill and using his shader which works great. Do you notice much slowdowns with this shader with each layer in it's own pass? I have very little knowledge of shaders and was just curious. It is so cool what you can do with this stuff...I have too much I want to learn, far too little time lol. Thanks again, -Jeremy
No problem! I havene't really tested the shader in any time critical game (or a marginal graphics card) so don't really know how it would perform. I only found Bills shader after I had written mine so will now give his a go to see if the masking is easier re workflow. cheers, Richard.
i'm using a similar approach to yours Richard and all seems fine by me. here's mine. Code (csharp): Shader "4LayerTerrain" { Properties { _Color ("Main Color", Color) = (0,0,0,0) _SnowTex ("Snow Texture (RGB)", 2D) = "white" _SnowMask ("Snow Mask (Gray)", 2D) = "white" _RockTex ("Rock Texture (RGB)", 2D) = "white" _RockMask ("Rock Mask (Gray)", 2D) = "white" _GrassTex ("Grass Texture (RGB)", 2D) = "white" _GrassMask ("Grass Mask (Gray)", 2D) = "white" _PathsTex ("Path Texture (RGB)", 2D) = "white" _PathsMask ("Path Mask (Gray)", 2D) = "white" } SubShader { Pass{ Material { Diffuse (0,0,0,0) } SetTexture [_SnowTex] SetTexture [_SnowMask]{ combine texture } } // end pass Pass{ Blend one one SetTexture [_RockMask] SetTexture [_RockTex] { combine texture * previous} } // end pass Pass{ Blend one one SetTexture [_GrassMask] SetTexture [_GrassTex] { combine texture * previous} } // end pass Pass{ Blend one one SetTexture [_PathsMask] SetTexture [_PathsTex]{ combine texture * previous} } // end pass } FallBack " Diffuse", 1 } i'll try to post a better screenie later...