Additive particles and XEffects

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
mjstone
Posts: 8
Joined: Mon May 18, 2009 7:33 pm

Additive particles and XEffects

Post by mjstone »

What is the best way to use particles with XEffects? I have some explosion particles using additive blending and they're getting shadowed. In fact they get dimmed when they're in front of any darkened area and not just in shadow. You can see this effect on the animated sphere in XEffects Example2. How can I avoid this? I'm not calling addShadowToNode() on my particle nodes.

(Edit: Using XEffectsR_1_2)
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Hmmm this is actually a tough nut to crack. You can do addShadowToNode on the particle system and set it's shadow type to ESM_CAST and that would make them bright again, but then the particles will cast shadows and the transparent parts will be bright making everything behind the particles look bright too.

The only way around it that I can think of is to draw the particle system after XEffects is done with all this (And anything else additive). There are a few problems with this method though because you would need to make sure the depth buffer stays intact from when the scene was drawn, and you need to set the scene manager's render pass to transparent to draw transparent scene nodes (I don't think the scene manager's render pass is publically exposed at the moment).

The easiest way around this really is to just use the old XEffects over at http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=23638 (Should give slightly better performance too, at the cost of a few features), you would need to update the code to deal with the new Irrlicht version though.

Until then I'll put this on my todo list for XEffectsR, hopefully should be fixed by the next release (Can't say when!).
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
mjstone
Posts: 8
Joined: Mon May 18, 2009 7:33 pm

Post by mjstone »

Thanks for your reply BlindSide. Your timing is perfect -- I'd just finished trying all of the things you suggest, and was stuck, having just failed to get the depth buffer to stay valid, like this...

Code: Select all

     ... in EffectHandler::update(), about to do light modulation ...

     driver->setRenderTarget(
                PostProcessingRoutinesSize  ? ScreenRTT : outputTarget, 
                true, 
                false, // <-- clearZBuffer now false
                SColor(0x0));

    ... original light modulation code here ...

    for(u32 i=0; i<AdditivePassNodes.size(); ++i) {
        AdditivePassNodes[i]->OnAnimate(device->getTimer()->getTime());
        AdditivePassNodes[i]->render();
    }
I'm obviously missing something though, as my particles get drawn in front of things that they shouldn't. I expect the above must be naive considering a dedicated depth pass is required for the depth-based effects. Also, the nodes in AdditivePassNodes are still getting drawn in the main render pass, which looks a little awkward to fix.

I'll try the old XEffects. What features are missing?
Hirte
Posts: 73
Joined: Sat Apr 01, 2006 1:32 pm

Post by Hirte »

Is your scene depth completely messed up?
Try and set antialiasing to false, that helped me with this problem;)
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I could tell you what features are missing from the old XEffects, or I could chat about the issues with depth buffers and render targets, OR I could spend a few minutes fixing your specific problem, I think I'll do that last one thank you. :P

Here's an updated XEffectsR with the issue fixed: http://irrlichtirc.g0dsoft.com/BlindSid ... _1_2_1.zip

You have to use the new function, excludeNodeFromLightingCalculations(). I added a particle system to the source code of the first example to demonstrate it's usage, tested in OpenGL and DirectX. It also works with alpha channel transparency. It's not perfect (I think it lags behind one frame), but it's good enough (TM).

Here's a screenshot:

Image

Cheers,

BlindSide
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
mjstone
Posts: 8
Joined: Mon May 18, 2009 7:33 pm

Post by mjstone »

Wow, that's much quicker than I expected!

And it works -- almost ;-). Actually I oversimplified and didn't tell you that I'm actually using pre-multiplied alpha. Specifically...

Code: Select all

    psnode->setMaterialType(irr::video::EMT_ONETEXTURE_BLEND);
    psnode->getMaterial(0).MaterialTypeParam = irr::video::pack_texureBlendFunc(
        irr::video::EBF_ONE, 
        irr::video::EBF_ONE_MINUS_SRC_ALPHA, 
        irr::video::EMFN_MODULATE_1X);
The more conventional modes work fine though, and I might switch to those anyway. (Otherwise I can probably work the rest out.) I'd been experimenting with smoke and flames in a single texture, but I'm not sure there's a huge advantage.

Also, the compiled executables don't run for me (previous versions have done). I get no error messages in the console, just the following, after the option selections. (Changing renderers or other options doesn't seem to help).

Code: Select all

Irrlicht Engine version 1.6 SVN
Microsoft Windows XP Professional Service Pack 3 (Build 2600)
Using renderer: Direct3D 9.0
ATI Radeon HD 3850 ati2dvag.dll 6.14.10.6734
Finally, while I have your attention, depthMC and shadowMC aren't getting dropped, so they get flagged as memory leaks when I enable the Visual Studio leak checks.

Thanks, and keep up the good work!
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Finally, while I have your attention, depthMC and shadowMC aren't getting dropped, so they get flagged as memory leaks when I enable the Visual Studio leak checks.
:oops: Thanks for spotting that!

Yeah I didn't compile the executables this time so it's still the old versions (With the new dll, so it doesn't match), this isn't really an official release anyway.

If you're vaguely familiar with writing shaders it shouldn't be too hard to implement your custom blending mode alongside the other ones. It does have to be done for each blending mode though, no way around that I suppose. By "pre-multiplied" alpha you mean setting the alpha in the diffuse color and it gets multiplied with the texture alpha so you can fade things in and out?
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
mjstone
Posts: 8
Joined: Mon May 18, 2009 7:33 pm

Post by mjstone »

BlindSide wrote:If you're vaguely familiar with writing shaders...
Yep. No problem.
BlindSide wrote:By "pre-multiplied" alpha you mean setting the alpha in the diffuse color and it gets multiplied with the texture alpha so you can fade things in and out?
I mean the rgb*alpha calculation is "premultiplied" in the texture (e.g. done in Photoshop). In effect the texture's colour channels indicate how much colour to add, and the alpha channel is how much background colour to remove. Here is an excellent description of the benefits: http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Premultiplied%20alpha]]
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

That's very interesting. You can probably get what you want by setting the base material of the "WhiteWash" shader to EMT_ONETEXTURE_BLEND and set the MaterialTypeParam like you've done. Do a search for EMT_TRANSPARENT_ALPHA_CHANNEL in EffectHandler.cpp and replace every occurance with EMT_ONETEXTURE_BLEND (Or implement it similarly) and it should work without having to modify the shaders at all.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply