I am not experienced enough with the fixed function pipeline. Hopefully someone can help.
At the end of the post is a simple shader which always draws the ‘_MainTexture’ except if it had to draw a pixel with ‘_Color’. In that case it uses ‘_ReplaceTex’.
Is it possible to write such a shader without cg?
It is possible that there will be more than 256 different colors or alpha values. But I could split it up for that case. The first tests were successful and the shader was very simple to implement.
Shader "Experiment/Replace Alpha Area" {
// Idea:
// Always draw '_MainTex'.
// In the case that '_Alpha' and the alpha value in
// '_ReplaceTexWithAlphaLookup'
// are the same, draw the rgb colors of
// '_ReplaceTexWithAlphaLookup' without
// it's alpha component.
Properties {
_Alpha ("Replace Alpha", Range (0.0, 1.0)) = 0.0
_MainTexture ("Main Texture", 2D) = "white" {}
_ReplaceTextureWithAlphaLookup ("Replace Texture with Alpha Lookup", 2D) = "white" {}
}
SubShader {
Pass {
SetTexture [_MainTexture] { combine texture }
}
Pass {
AlphaTest Equal [_Alpha]
SetTexture [_ReplaceTextureWithAlphaLookup] {combine texture}
}
}
}