Simple Additive shader with Alpha

Hi everyone,

I’ve been looking for a shader in unity that does both additive with an alpha channel. But seems like there isn’t much talk about the alpha channel part. I found a simple additive shader online, but has no alpha channel.
I’m not much of coder, but can someone shine a light on this simple shader. Your help is greatly appreciated.
Thanks in advanced.

Kue,

Shader "My Shaders/ColorAdditiveShader" {
    Properties {
        _Color ("Main Color, Alpha", Color) = (1,1,1,1)
        _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}    
    }
    Category {
        ZWrite Off
        Lighting Off
        Tags {Queue=Transparent}
        Blend One One
        Color [_Color]
        SubShader {
            Pass {
                Cull Back
            }
        }
    }
}

This is easy to do. But before I tell you how to do it, please tell me why you’d want to. Why can’t you just premultiply the RGB by the A? Are you using the RGB elsewhere, without muliplication?

Hi Jessy,

Here is a link to an image kinda explaining what I want to achieve

If you know other ways to do this, I would really appreciate the help.
thanks.

Kue,

Okay, I see. I don’t know what your channels look like, right now. But what you need, is this:

RGB is black wherever you only want to see the background.
Alpha is black everywhere, except the mask for the text.

Shader "Premultiplied" {
	
Properties {
	_MainTex ("Texture  (A = Opacity/Additive Blend)", 2D) = ""    
}

SubShader {
	Tags {Queue = Overlay}
	Blend One OneMinusSrcAlpha
	Pass {SetTexture[_MainTex]}
}

}

You could also invert the alpha channel, and use Blend One SrcAlpha. The results will be identical if you’re not using compression. However, I recommend the shader above, if you do use compression, because the textures should compress better when you have black RGB matching with black A, instead of white A.

Hey Jessy,

I’ve tried using the code you provided but, i’m not getting the result i needed.
Here is another illustration of the additive plus alpha. The texts on the buttons in the first illustration is not part of the button.
the effects on the button is what i wanted.
Hopefully the second illustration can help explain.
Again thanks for looking into this, Jessy.

Kue,

Like I said in my first response, there’s no point in using an alpha channel. The only reason you’d need that is if the text were part of the rest of the graphic, which you probably should do. Just multiply the alpha you have currently, by the RGB you have currently, and then just use the RGB with an additive shader. Or, because your shape is so simple, just model that - it will take only 6 triangles, require no texture at all, given the uniform color*, and it will be resolution-independent.

  • I think that’s what I’m seeing. I see a brighter outline in the last shot, but I don’t know if that’s intended or not. If it is, that would be 22 triangles, and you could use vertex colors.

Thanks Jessy for the help and suggestion. I’ll give it try.

Kue,