Transparrent Highlight shader

It’s a little bit tricky to explain what I want to do, but hopefully the images will help clarifying it.

I want to make a shader that takes two textures. The first texture should highlight the texture beneath it, using additive blending.

Texture 1: Black and white image used for Highlight.
Texture 2: RGBA image, alpha is telling what part to render.
Animated UV script is added to scroll the highlight image across the mesh.

So far (with help from a friend) I get this result:
The text alpha is correct and overlay is displaying sort of correct but the text is black.

This is the additive effect I want but it should only display within the alpha (which is the text border).

Here is the code so far (at the moment it displays the text correct but not the highlight, I can sort of see the highlight moving beneath the text when I animate the UV’s):

Here are the texture files: http://www.coindrop.dk/unityforum/highlightshadertextures.zip

Hope someone can point me in the right direction. :sunglasses:

Shader "Decal2" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_DecalTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

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

	
	
CGPROGRAM
#pragma surface surf Lambert alpha

sampler2D _MainTex;
sampler2D _DecalTex;
fixed4 _Color;

struct Input {
	float2 uv_MainTex;
	float2 uv_DecalTex;
};

void surf (Input IN, inout SurfaceOutput o) {
	fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
	half4 decal = tex2D(_DecalTex, IN.uv_DecalTex);
	
 c.rgb = lerp (c.rgb, decal.rgb, decal.a);
 //c.rgb = lerp (decal.rgb, c.rgb, decal.a);
 c.a *= decal.a; 
 c *= _Color;
 o.Albedo = c.rgb;
 o.Alpha = c.a;
	
}
ENDCG




}

Fallback "Diffuse"
}

You may try to replace line 31 with:

c.rgb = c.rgb + decal.rgb;

You Sir, have just ended a very long struggle for me to figure out this shader - Thank you so much!
As an artist is’t not always easy to figure this stuff out… Think i am getting better at it though :slight_smile:

For anyone who may wish to try out this shader, here are the texture files and the final code (you also need to animate the UV’s with a script):

Textures: http://www.coindrop.dk/unityforum/highlightshadertextures.zip

Shader "Decal2" {

Properties {

    _Color ("Main Color", Color) = (1,1,1,1)

    _MainTex ("Base (RGB)", 2D) = "white" {}

    _DecalTex ("Base (RGB) Trans (A)", 2D) = "white" {}

}

 
SubShader {


CGPROGRAM

#pragma surface surf Lambert alpha

 
sampler2D _MainTex;

sampler2D _DecalTex;

fixed4 _Color;
 

struct Input {

    float2 uv_MainTex;

    float2 uv_DecalTex;

};

 
void surf (Input IN, inout SurfaceOutput o) {

    fixed4 c = tex2D(_MainTex, IN.uv_MainTex);

    half4 decal = tex2D(_DecalTex, IN.uv_DecalTex);

    
c.rgb = c.rgb + decal.rgb;

 c.a *= decal.a; 

 c *= _Color;

 o.Albedo = c.rgb;

 o.Alpha = c.a;

    

}

ENDCG

 
}

 
Fallback "Diffuse"

}

I’m assuming your problem was due to the lerp function meaning that either the decal was showing through fully with the decal.a being 1:

c.rgb = lerp (c.rgb, decal.rgb, 1) = full decal texture.

When the decal was transparent (alpha 0):

c.rgb = lerp (c.rgb, decal.rgb, 0) = full normal texture (Except these areas are transparent)

Hence why if you reversed the lerp function:

c.rgb = lerp (decal.rgb, c.rgb, 1) = full normal texture (Black text)

you ended up using the main texture on the text, causing it to be black.

Yeah, I think that was the case. Thank you for the explanation :slight_smile: