Posts

Showing posts with the label dstalpha

CG shaders Alpha Channels and blending

Typical alpha channel usage - for a quad with a leaf texture that has alpha values. We make sure we're inthe Transparent Queue and also use the Blend function. It takes two arguments, the first multiplies the incoming data (what is on the surface) and the second multiplies the existing data on the framebuffer (whatever is behind the object - Unity renders from back to front). Then both values are added. In the code example, SrcAlpha x surface colour will give you the surface col where the Alpha is white & zero where the Alpha is black. By multiplying the framebuffer with 1-srcalpha we take the inverse of the alpha map and get inverted results. Now when you add these values they should sit together as if the quad has correct transparency. If for instance, you had Blend SrcAlpha One, then  you'd have an additive effect of the background on your leaf. I've pasted some info about it below.. Cull Off - tells the shader not to discard the back-face data, which it does by defa...