[SOLVED]HELP PLEASE - Simple 2 Color Alpha Shader

Shaders confuse me. I got things working in several layers of materials, but in the end I think it can be in one material and not the multiple materials is giving me problems under the new iPhone build.

I want a diffuse shader that

I can set a LETTER (a black letter PNG on a clear background)
ForegroundColor (the color I want the black letter to be
BackgroundColor

And If I set the LETTER to an image of an A, and the Foreground color as White and the background color as Blue, it would have a White ‘A’ against a blue background. Shouldn’t be too difficult, should it?

PLEASE HELP!!!

This should do the trick:

Shader "SimpleText" 
{
	Properties 
	{
		_Background ("Background Color", Color) = (0,0,0,1)
		_Foreground ("Foreground Color", Color) = (1,1,1,1)
		_Mask ("Mask (A)", 2D) = "white" {}
	}
	SubShader 
	{
		Lighting Off
		
		Pass
		{
			SetTexture [_Mask]
			{
				ConstantColor [_Background]
				combine constant
			}
	
			SetTexture [_Mask] 
			{
				ConstantColor [_Foreground]
				combine constant lerp (texture alpha) previous
	        }
		}
	} 
}

Work’s perfectly! Thank you!!!

Hi. The script is close to what I’m looking for.

Instead of constant, is it possible to include diffuse and specular lighting influence?

This will do basic vertex lighting with specular:

Shader "TwoTone VertexLit" {
	Properties {
		_Background ("Background Color", Color) = (0,0,0,1)
		_Foreground ("Foreground Color", Color) = (1,1,1,1)
		_Shininess ("Shininess", Range(0.01, 1)) = 0.7
		_Mask ("Mask (A)", 2D) = "white" {}
	}
	SubShader {
		Material {
			Diffuse (1,1,1,1)
			Ambient (1,1,1,1)
			Specular (1,1,1,1)
			Shininess [_Shininess]
		}
		
		SeperateSpecular On
		Lighting On

		Pass {
			SetTexture [_Mask] {
				ConstantColor [_Background]
				combine constant
			}

			SetTexture [_Mask] {
				ConstantColor [_Foreground]
				combine constant lerp (texture alpha) previous
			}
			
			SetTexture[_Mask] {
				combine previous * primary, previous
			}
		}
	}
}

The script works, but I’m looking for fragment instead of vertex shader as it’s important that the vertex shading “artifacts” are not visible.

Sorry I should have been more clear.

I’ve created a globe using Unity’s built-in shader Specular Bump. I like to be able to assign the Sea Land colors seperately using a script with the help of an alpha matte. Currently the build-in shader only allows me to use a color texture ( with alpha ) to color the globe.

I’ve downloaded the Built-in shader and tried to incorporate the above scripts, but I’m really weak with shaders. Any help appreciated.

204303–7527–$normal_bumpspec_143.shader (9.31 KB)

You should be able to make that shader do what you want. You’ll have to modify the fragment shader (beginning with float4 frag…) and have it use the alpha channel of the main texture to generate the colour. The only variables you’ll need to add are the sea and land colours. In addition to adding them to the material block, you’ll need to add them to the Cg block, just like _Shininess has been added. This makes them available for use in the fragment program.

Good to know it’s possible.

However with my limited shader CG knowledge, I’m really having difficulty.

Currently it’s taking _Main. How do I use it’s alpha channel?

I manage to add the sea Land variables to the material block, but where’s the CG block and how do I add the variables?

An example shader script will really help.
Thanks.

The Cg block of the shader is the part that begins with CGPROGRAM and ends with ENDCG. It looks like C, which Shaderlab otherwise doesn’t. You should read the first five chapters of the Cg Tutorial to get started with Cg.