Particle tips TexturesForAlphaBlendAdditive
For PK-Fx Editor version : any
Main page: Particle tutorials
Popcorn allows you to use a few 'AlphaBlend_Additive' materials for billboard and ribbon renderers.
These can be very useful in a number of cases, but authoring textures that work well with them can be a little tricky.
These "AlphaBlend_Additive" materials are also commonly called "premultiplied alpha" materials. They allow to draw textures with both regular alpha-blended parts, and purely additive parts.
Basically, the RGB channels contain an emissive color, and the alpha contains an opacity/extinction amount applied to the background. Therefore, a solid gray-128 RGB texture with a fully black alpha will additively blend solid gray on top of the scene, but a fully solid gray-128 RGB texture with a fully white alpha will draw an opaque solid gray-128 square on the scene.
Texture with premultiplied alpha and somme yellow pure-emissive parts
Here, to emphasize the emissive parts, we're actually rendering 10 particles on top of each other, hence the slightly "volumetric" look
Why do I want to use that?
Two main reasons:
1- Richer material
Inside the same sprite, you can paint both solid smoke and bright sparks. You can make a flipbook of a flame burning with nice additive emission, yet with opaque smoke parts.
If you have an explosion with 10 layers, but all layers use the same material and the same texture atlas, your whole explosion will be drawn in a single drawcall, and better: the particles will be properly sorted, no matter which layer they come from. This gives you proper sorting of small additive bright sparks against the smoke/dust clouds.
How do I export a texture that works properly?
The tricky part is that some texture formats assume that if the alpha is zero, then there's no point in storing the RGB information, because the texels will be transparent anyway.
For this material, it's obviously plain wrong, as the RGB store our emissive, even if alpha is zero.
If you're using photoshop, these formats will work:
- DDS with any format that stores alpha, incl. DXT3 (BC1) or DXT5 (BC2) (The NVIDIA's photoshop DDS plugin should keep the RGB information)
- PNG (in our tests, seemed to work, if you paint your RGB and alpha separately, then use layer to transparency)
Other tools might or might not work.
Here are the steps that work for us:
|1.||in the 'channels' panel, add a new channel named 'Alpha', in addition to the existing RGB channels, this will store the alpha|
|2.||paint whatever alpha you want. black is transparent/no extinction, white is opaque/full extinction.|
|3.||to get regular alpha blended behavior, copy your alpha channel to a regular RGB layer on top of your existing color layer|
|4.||set the alpha layer blend mode to 'Multiply'|
|5.||save as TGA, or export with NVIDIA's DDS plugin.|
Gamma space / sRGB
When doing the RGB / Alpha layer multiply in the photoshop layers, You must be careful about gamma space. Does your final render engine have a linear-space lighting pipeline? does it blend in sRGB space? is your texture in sRGB?
ideally, the ideal multiply should be done in linear space:
- convert original RGB from sRGB to linear space
- convert alpha channel from sRGB to linear space
- multiply RGB with alpha
- convert result back from linear to sRGB space