Articles Archive
Articles Search
Director Wiki
 

Additive Blending Effects in Shockwave 3D

January 30, 2003
by Malachy Duffin

Additive blending between objects is a key feature when creating "eye candy" in 3D scenes, from effects like lens flares to light glows. The additive nature of the texture operation emulates the effect of the various textures mixing together. Some top games ( like Halo ) use additive blending to enhance the look of the graphics within their levels, from weapon glows to explosions.

This particular feature isn't present in the current version of Shockwave 3D, although I'm pretty sure it'll be added in the next update.

However there is a way of "hacking" it in there, and it will work across all of the rendering engines with a few exceptions. We are starting to use this more and more in some of our new titles from canDo, and seeing as it's the new year and all, we still have a bit of festive good will left in us and decided to release the info on how to do it along with some source. If you use it in a project, and you meet anyone from canDo at a future tradeshow, getting them a few jars of Irish nectar will suffice for payment!

I've included the code in a behaviour that can be used in existing projects with a minimum of fuss. By placing the behaviour at the bottom of the list, and having earlier renamed the shaders that will useadditive blend to include the word "Additive", the effect should work straight away.

Show Me an Example of It Working

Sure thing, click on the pretty picture....

Where Do I Get It?

Download the Director 8.5 file containing the behaviour in either ZIP or SIT archive format.

How Do I Use It?

Firstly, copy the "additive blending" behaviour script to your movie and drop it on your 3D sprite.

If you run the movie now, nothing will happen. This is because no shaders have been marked as additive. In order to do this, change the name of the required shader to include the word "Additive". It will now be picked up by the behaviour and converted to additive blending.

If you are using planes for a light effect, create them with "billBoard" in their name, or with "billBoard" in the object's userData, and the object will always point to the camera. Try to create your objects pointing upwards to the ceiling.

Run your program now and see if the effect is working. If it is, great! If not, run the sample program and see if it works with it. If not, your machine may not unfortunately support this hack!

How Does It Work?

Shockwave 3D doesn't natively support additive blending between objects, but it does support additive blending between shader texture layers, of which it has a total of 8. In order to enable additive blending with objects, we use a texture with an alpha channel of nothing in a texture layer below the layer that will contain the texture to blend.

A lot of 3D graphics cards support multi-pass texturing, so in order to enable the above, the blank texture must be used for a number of the lower layers of the shader. This number will be the same number of times as the 3D card can simultaneously handle textures, which can change between rendering modes.

The Lingo code for checking the number of textures that the 3D card can handle is...

    getrendererServices ().gethardwareinfo ()[#textureUnits]

If you look through the heavily commented code within the behaviour (erm... a virus must have removed them!), you should be able to see what's going on. The code was thrown together during a prototyping stage when we were seeing if this was possible, so it's a bit messy, but it works. If you want to tinker, the code is self explanatory, and if you don't, you should just be able to drop the code on to your existing project and use it.

Exceptions and Features

a) This technique won't work on graphics cards that can mix 8 textures at a time ( like the Radeon 9700 in Direct X 7 mode ). In this case, you should make sure that the textures have an alpha channel that the card can use to at least get some sort of effect, or remove the models used for the effect from the scene. If you have one of these cards, you'll notice that the red light texture doesn't blend and looks dodgy. This is what you want to avoid, so make sure that the alpha channel exists as a fallback, like on the other light. NOTE: This can now be worked around via the undocumented "nextShader" command.

b) This technique unfortunately doesn't work with particle systems as they only use a texture reference, not a shader reference.

c) Because this technique relies on the fact that it's drawing nothing until the 3D card has to perform additional operations to write to the screen, it's not as fast as if Shockwave 3D supported this feature natively within a single pass. It does however get carried out directly after the single pass, so it's not too inefficient.

d) There can be some rendering artifacts with a lot of overlaid objects due to the problems with sorting overlapping translucent objects in Shockwave 3D (again, this will hopefully be fixed in the next update of Shockwave).

e) It doesn't allow you to blend the additive effect, so you can't lower the amount of blending the texture has on the resulting scene. If additive translucency was supported directly, this would be possible, allowing for some very complex visual effects.

f) The code doesn't automatically handle multiple textures within the same shader, but if you take the time to understand the code, it should be straightforward to change it to handle any operations you like.

The End

Hopefully this technique works for you! Remember, it's a sort of hack, and totally unsupported, but canDo definitely plan to use it a lot for future projects, so good luck with it! Apologies for any typos or errors in the code, it's been thrown together pretty quickly to coincide with the developer article on canDo, but there should be enough here to get you up and running with this cool effect!

Happy new year to you all, and good luck with getting future lucrative Shockwave 3D projects!

NOTE: I've just read about an undocumented .nextShader property which should hopefully make it possible to support additive blending on 3D cards that can handle 8 or more texture operations at once. Implementing that is kept as a homework exercise, and should keep you lot busy for at least a few hours! Good luck, and I look forward to seeing some cool examples of this technique being used.

 Mal Duffin is the principal at CanDo Multimedia, and is actively involved in developing Shockwave 3D projects and games.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.