x


Shader that combines two textures' alpha channels?

Hello.

I'm looking for a transparent diffuse shader that combines two textures' alpha channels like this

alt text I think there was a standard shader in one of the online repositories that does this, but I can't find it anymore.

Appreciate your help!

thanks, vivien


Edit: Related to the above: What could I do to animate (scroll) the texture 1 and it's alpha and keep texture 2 static? (The result would be a scrolling transparent texture with a static alpha that makes it f.i fade at the borders)

Thanks!

more ▼

asked Oct 08 '10 at 07:48 AM

VivienS gravatar image

VivienS
325 24 28 37

Related to your Edit: Add this:

float2 uv_AlphaMap

to the struct Input {...} function and change: o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_MainTex).r; to:

o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_AlphaMap).r;

You can scroll the first texture with this script attached to your gameobject with the material that uses the shader:

var scrollSpeed : float = 0.05;
var scrollVector : Vector2 = Vector2(0, 1);

function Update () {
    renderer.material.SetTextureOffset ("_MainTex", scrollVector * Time.time * scrollSpeed);
}
Feb 24 at 09:58 PM Azial
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

How did you end up with some white in your red/green/blue channels? ^^

Anyway, here you go:

Shader "Transparent/Diffuse + Extra Alpha"
{
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
}

SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 200

CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
sampler2D _AlphaMap;
float4 _Color;

struct Input {
    float2 uv_MainTex;
};

void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_MainTex).r;
}
ENDCG
}

Fallback "Transparent/VertexLit"
}

Sinon vous auriez pu me demander directement.

V.

more ▼

answered Oct 08 '10 at 10:33 AM

taoa gravatar image

taoa
1.6k 8 13 34

wow thanks! that was what I was looking for :) merci for your time & effort!

Oct 08 '10 at 12:56 PM VivienS

@RGB channels: Mh, I was wondering about that too.. ^^ but it was comperhensible, that's the most important thing. thx again.

Oct 08 '10 at 12:59 PM VivienS

Vote for me dammit!

Oct 15 '10 at 07:43 AM taoa

+1 Dammit! :)

Oct 17 '10 at 02:55 AM Tzan

^^
:)

Oct 18 '10 at 08:08 AM taoa
(comments are locked)
10|3000 characters needed characters left

Nice Shader, for those who want it as additive Shader (useful for fire-effects like in WoW since Wotlk) I wrote this:

Shader "Custom/AdditivMask" {
    Properties {
    _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    _MainTex ("Particle Texture", 2D) = "white" {}
    _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
    }

    SubShader {
       Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
       Blend SrcAlpha One
       AlphaTest Greater .01
       ColorMask RGB
       Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
       BindChannels {
         Bind "Color", color
         Bind "Vertex", vertex
         Bind "TexCoord", texcoord
       }
       LOD 200

       CGPROGRAM
       #pragma surface surf Lambert

       sampler2D _MainTex;
       sampler2D _AlphaMap;
       fixed4 _TintColor;

       struct Input {
         float2 uv_MainTex;
         float2 uv_AlphaMap;
       };

       void surf (Input IN, inout SurfaceOutput o) {
         half4 c = tex2D (_MainTex, IN.uv_MainTex) * _TintColor;
         o.Albedo = c.rgb;
         o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_AlphaMap).r;
       }
       ENDCG
    } 
    FallBack "Diffuse"
}
more ▼

answered Feb 24 at 11:20 PM

Azial gravatar image

Azial
53 1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1650
x327

asked: Oct 08 '10 at 07:48 AM

Seen: 3129 times

Last Updated: Feb 24 at 11:20 PM