I would like to render an object that is semitransparent (in fact, the material itself is quite simple - just an unlit solid color with alpha), and I can achieve that, with this shader:
Shader "FlatMultiply" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType" = "Transparent"
"Queue" = "Transparent" }
Pass { ColorMask 0 }
Pass {
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Color [_Color]
}
}
}
However, when two objects with this shader go behind each other, the light is “double occluded” and it ends up more opaque. I don’t want this. Rather, I would like the light to be only once-colored. How can I achieve this effect?
Computationally, I would try to find which pixels are touching my material, then render the background, then darken those pixels I found in the first pass, but I don’t have the shader-fu necessary to pull this off. Anyone have any ideas?
EDIT: The AlphaVertexLitZ shader does the trick for the transparency problem (and I’ve incorporated the technique into the code segment above), but it is designed for a single object with a non-convex geometry. Is there a way for me to use this shader so that it applies to all objects with my material in the scene as a whole? I suppose I could achieve the effect I want by collecting all objects in the scene into one mesh and using this shader on it, but that will incur monstrous overhead, and would defeat the purpose of having separate objects. Can I specify that I want all objects to be rendered in the same pass in ShaderLab?