Simple alpha additive blend material.

I can’t seem to make a very basic alpha additive blend material for a laser blast. I’m using Unity 2019.4.

The model is just some quads and triangles.

The texture is some plasma with an alpha channel copying the main image.

I import the model and texture. Texture is set with Alpha Source as Input Texture Alpha.

I create a material that uses the Standard Shader, but neither rendering mode Transparent or Fade produce the correct result.

Transparent isn’t transparent on the black parts of the alpha channel.

Fade doesn’t blend things correctly, I need an additive blend but it looks like it’s using a multiply blend.

I’ve tried some of the other shaders apart from Standard, most of them are no good either. One of the particle shaders was close but it doesn’t allow for GPU instancing.

How do I set the material to blend the alpha channel properly? Any help appreciated.

The Standard shader’s “Transparent” rendering mode is intended for things like glass. Things that can be seen through, but which are still lit/glossy everywhere. Fade is a better option here, as things that are transparent are completely invisible, but it still assumes the parts that aren’t fully transparent are lit. The Standard shader has no additive blend mode, if that’s what you want, that is not an option it can achieve. However I don’t think that is what you want as any part of your mesh that overlaps will add making them brighter and obvious. You really just want traditional alpha blending, which is what the Fade option is.

The problem you’re having is you have both the alpha and color fading to black. That’s what you would use if you were doing premulitplied alpha blending, but Unity doesn’t actually have any shaders that do that properly (including those with “premultiplied” in the name). You can actually get the results you’re looking for by using a solid color texture with the same alpha you have now. Set the albedo color multiplier to black and using the same texture for both the albedo and emission, and set the rendering mode to fade. Really you probably want to use the Standard Specular shader and set the Specular color to black, as 0 metallic is not the same thing as no specular. Everything in the real world is shiny, and that’s what the Standard shader is trying to replicate.

But don’t do that. The Standard shader really isn’t designed for rendering an emissive only material.

The best shader for this that’s included with Unity is the Particles/Standard Unlit shader. It also doesn’t support GPU instancing in the traditional sense, but does support GPU instancing when used with a particle system. You’ll want to do the same solid color & alpha setup for that shader too … or any other Unity shader. But you can spawn your effects as particles and it’ll be significantly more efficient than using the auto-instancing of Unity. Potentially even more efficient than manual instancing since the particle system can handle sorting for you too.

However for the most control, you would need to write your own custom shader vertex fragment shader.

2 Likes

Fade = ‘bad blending’ you get is Alpha blending
(SrcAlpha, InvSrcAlpha)

meaning source (blaster) is multiplied by its alpha srcAlpha, result is a ‘double dark’ ghosting when blended

As bgolus mentions - if you flood that texture all magenta the dark ghosting will go away
(or delete your alpha channel instead)

as for an additive blend shader >Sprites/default **
should work, though you need to delete your alpha channel…or you just change the Tint to have alpha : 0

** compile shows Blend One,OneMinusSrcAlpha which will work for your texture as-is and GPU instancing is available on the material

P.s
alpha channels are not used in Additive blends, (er… they would never “need to be” +waste memory unless you want Red8 textures → alpha with _COLOR for RGB), it isn’t part of the math as the process is:
__One One__

you may want more : Blending, and visual stuff at popcorn

None of Unity’s additive shaders use Blend One One, they’re all Blend SrcAlpha One, so the alpha is used. But that means you want to use alpha or a fade to black in the color, not both. If you use both it’ll disappear much too fast.

yah I saw that too late,

EDIT! yes I get what you mean; particles/art expects colorOverTime (vertex.alpha) to be able to dissolve a particle rather than having to use the color → black to do it

so long as alpha is not changed from (1) the plain 24bit texture ostensibly works as (one,one) but yes SrcAlpha is expected/desired

It’s just because it allows for easy texture reuse. You can use the same texture with a solid color and alpha for both additive and alpha blended shaders. There’s no real added cost in doing so since a 24 bit texture with no alpha is guaranteed by the graphics APIs to have an alpha of 1.0, and all modern GPUs are constant time for any of the main blend types (there’s no advantage between One One, SrcAlpha One, or SrcAlpha OneMinusSrcAlpha).

Thanks for the answers. Good tip on the colour channel not needing to fade to black. I’m probably going to abandon this approach and instead use a particle system attached to an empty object, and move the empty objects around to get the laser blast effect.

I do find it weird I can’t do a simple alpha additive material. I’m new to Unity, I normally code everything in C++ and write HLSL shaders myself, so not being able to do something as simple as alpha additive on the standard material transparency is jarring. I’m still getting my head around doing things the “Unity” way.

You can absolutely write a simple additive shader. Just none ship with Unity because it’s rarely what people actually want. And a Blend SrcAlpha One is identical to an additive shader most of the time.

But again, the use case and the behavior you’re describing isn’t actually an additive shader anyway. It’s a traditional alpha blend.

This is what an additive shader looks like with a geometry cross like you have:

And this is what a traditional alpha blend looks like (with a correctly setup texture):

If you’re already familiar writing HLSL, then Unity shaders aren’t all that complicated. You’re just defining the render state and both stages for a single or potential multiple passes in a single file.

Yeah, the later is what I should have done. Doesn’t matter, I’ve starting using the trail renderer attached to a non-rendering object controlled by a script, and so far it’s working well.

I’m avoiding writing shaders for now, or any other unnecessary code, and want to try and do things the “unity” way as much as possible. Otherwise it defeats the purpose of me moving to Unity in the first place. Later on, as things get more complicated and I understand what Unity can and can’t do out of the box, then I might start coding some HLSL again. I wouldn’t mind giving the ShaderGraph or whatever it’s called a try too, after this first simple project.

For what it’s worth, I’ve yet to ship a Unity project that uses just the built in shaders. Hell, I’ve never shipped a project that used the original Standard shader without some amount of custom modifications. I’ve yet to ship a project that used any of the default particle shaders (on purpose). It’s a starting point that can get you 80% of the way, but it’s almost always going to be more efficient / easier (if you already have the know how) to write custom shaders for your use case than use anything built in.

1 Like

oh additive e.g. 'looks like 1 solid shape" - I thought you wanted [linear dodge] additive

URP ‘unlit’ does this just fine and gives the GPU instancing
6083769--660291--upload_2020-7-12_20-44-17.png
just make sure you feed the RGB color without the black since the Blend Mode : Alpha does that during
Blend SrcAlpha, 1-SrcAlpha
alpha is transparency’ helps projects thumbnails to not be squares (‘see’ what was intended)

sorry if you need HDRP example
im sure it can do this with some unlit standard shader, but I have no HDRP projects cause I work in mobile

i’d advocate the premult blend which works with your first texture and gives alpha + additive… but it is broken atm… :frowning:

Hey I got one question… Im making vfx for a mobile game and additive transparency showed much cheap solution than alpha blending… BUT as you know, you cant have dark colors… I somewhat understand blending logic, but still dont see why Blend SrcAlpha One fades material when color is darker. is there any way around this? or is alpha blend not that bad, it just has flickering problems

There is no performance difference between additive and alpha blending these days. That’s something that really only existed on very early GLES 1.0 mobile devices. And by “flickering”, I assume you’re referring to the fact the render order of alpha blend matters, where as it does not for additive. This is just a math thing. When adding numbers together, the order you add them in doesn’t change the result, thus additive blending also doesn’t care what order you render them in. Alpha blending does care about the order as the order changes the appearance of what is “on top” of something else.

If you really want to keep the lack of sorting, you can try using subtractive blending. But I highly recommend you just get used to using alpha blending and be mindful of sorting.

but how do people sort this in the vfx where everything is moving non stop? I set sort order in particle system but i still get flickering. Also, when i set trail going around my vfx, theres no way i can prevent order issues since the trail is in front and in back at same time…

The secret is … it flickers all of the time in other games. The only difference is it’s not an effect you made so you’re not staring at it that intently.

The other trick is to force a specific sorting order either using the Sorting Fudge in the particle renderer settings, or by putting a Sorting Group component on the parent game object and assigning the Order in Layer.

Big AAA games use very custom particle systems that use the equivalent of a single material and particle system for all effects in the game so they can be efficiently sorted and drawn in a single render call. Or use some form of order independent transparency approximation (often just opaque dithering + TAA to hide the crimes). Or … and this is the most common … they just let things flicker because 99.9% of players won’t notice.

1 Like

Ah yes I understand. That makes sense, thanks

I see a lot the combination of the two…(additive and alpha in single effect) is it possible to change blending via property block? also culling mode?

I found a solution to have additive blending and perfectly accurate dark colors…
modifiedColor.rgb = tex2DResult.r * i.color.rgb * clampResult * pow(2.0, (i.k_texcoord1.w)) + (i.k_texcoord1.w * tex2DResult.r);
this is a line in fragment that matters… controlled from particle system. i can control with pow(2.0, (i.k_texcoord1.w)) how dark do i want the color to be.