Use texture as a mask

Is it possible for one texture to act as a mask for another texture?

For example, lets say I have two textures on a polygon, A, and B. Parts of texture A are completely transparent (alpha=0) and others are opaque (alpha=1). Is it possible to have the transparent parts of texture A also cause texture B to be transparent in the same place, essentially acting like a mask?

To put some perspective on things, I’m trying to implement a “fog of war” on a 2d landscape, I’m doing that by overlaying the entire landscape by a large plane that uses a very low resolution texture where each pixel in the texture corresponds to one “square” in the 2d landscape. If I want the fog to cover that square I simply make that pixel alpha=1, or alpha=0 if I want to remove the fog. This works very nicely for my purposes, especially with filtering that smooths out the pixel edges. However, the fog ends up being a solid color, I would like to texture it a little.

I imagine something like that would be pretty straightforward with pixel shaders. Is it possible to do it without pixel shaders?

Sure. For example this shader uses one texture for the color and another one for the mask.

Shader "Mask" {
Properties {
	_MainTex ("Color (RGB)", 2D) = "white" {}
	_Mask ("Mask (A)", 2D) = "gray" {}
}
SubShader {
	Tags { "Queue" = "Transparent" }
	Pass {
		Blend SrcAlpha OneMinusSrcAlpha
		ZWrite Off
		AlphaTest Greater 0.01
		SetTexture [_MainTex] { combine texture }
		SetTexture [_Mask] { combine previous, texture }
	}
} 
}

BTW, shader related questions probably fit better in Shaderlab forum section.

Ah, you’ll notice I said that I was looking for a non-shader solution. For some odd reason I had it in my head that I can’t write custom shaders in Indie. Silly me. This shader works wonders, thank you very much, it’s perfect!

The above is not a pixel shader, just good ole’ multitexture. You can write pixel shaders in Indie as well of course.

I assumed that by “pixel shader” you just meant that your target hardware is old and won’t have them.