Hi, I tried the 3 and four layer shaders on the wiki and they work great. At the moment I have 3 questions: 1. I remember reading that the 4 layer shader has problems on some graphic cards. This is issue was supposed to get solved in Unity 2. Is this indeed solved now? 2. In the 4 layer shader it seems that the texture in the 4th layer (alpha channel) covers the whole object and therefor affecting the textures in the first 3 layers. I am probably doing something wrong here but I am pretty sure there are no areas with opacity in the splatmap. I used solid colors for the 1st 3 layers. 3. What I am looking for is an additional option to have the layers (or at least 1 of them) fade into opacity (using the alpha channel) to blend the part of the object using that layer with the background. Is this possible? Or maybe this can be done with the 4 layer shader? Many thanks, Raoul
Had my first steps into shaders this weekend and managed to make some small changes to the three layer shader: Code (csharp): Shader "Terrain/Three Layer" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Color 1 (RGB)", 2D) = "grey" {} _MainTex2 ("Color 2 (RGB)", 2D) = "grey" {} _MainTex3 ("Color 3 (RGB)", 2D) = "grey" {} _Mask ("Mixing Mask (RGBA)", 2D) = "white" {} } SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha Lighting On Material { Diffuse [_Color] Ambient [_Color] } CGPROGRAM // profiles arbfp1 #pragma fragment frag // fragmentoption ARB_fog_exp2 sampler2D _MainTex : register(s0); sampler2D _MainTex2 : register(s1); sampler2D _MainTex3 : register(s2); sampler2D _Mask : register(s3); struct v2f { float4 uv[5] : TEXCOORD0; float4 diffuse : COLOR; }; half4 frag( v2f i ) : COLOR { // get the four layer colors half4 color1 = tex2D( _MainTex, i.uv[0].xy ); half4 color2 = tex2D( _MainTex2, i.uv[1].xy ); half4 color3 = tex2D( _MainTex3, i.uv[2].xy ); // get the mixing mask texture half4 mask = tex2D( _Mask, i.uv[3].xy ); // mix the four layers half4 color = color1 * mask.r + color2 * mask.g + color3 * mask.b; // match mask alpha color.a = mask.a; //multiply and double by the lighting return color * i.diffuse * 2.0; } ENDCG SetTexture[_MainTex] {} SetTexture[_MainTex2] {} SetTexture[_MainTex3] {} SetTexture[_Mask] {} } } FallBack " VertexLit", 1 } added: Code (csharp): Blend SrcAlpha OneMinusSrcAlpha and Code (csharp): color.a = mask.a; This actually does blend the object with the background. See result below: The red is the background, the bricks and wood are 3 textures on a plane using the 3 layer shader. The mixing mask texture has opacity on the outside. As you can see the brick texture is much brighter in the parts with opacity. The color level of the material is set to white. If I move this to grey the brightness disappears but the overall look is too dark. I also tried controlling the brightness by changing: return color * i.diffuse * 2.0; to return color * i.diffuse * 4.0; In the shader. Unfortunately this leads to a similar result as below. Anyone knows how to fix this?
Actually this is not true, when changing the color to grey, the transparent area is still brighter. When I remove the "color.a = mask.a;" part from the shader the edges with full transparency have this same bright color. It seems that "color.a = mask.a;" does apply the alpha of the splat texture correctly to the output and the blending properties are set correctly. I belief the problem is in this line: half4 color = color1 * mask.r + color2 * mask.g + color3 * mask.b; The initial color of the areas with transparency is not set correctly. The only solution I, as a complete shader noob, can think of is to use a separate texture for the alpha channel? Or can all of this actually be done with one splat texture?