Blendmode/Alpha problem (Solved)

Hello there :slight_smile:

As a lil project of mine gets near the end, I decided it's time to fix glitches I couldnt be bothered to fix before.

So one of them is alpha looking ugly.

I made an explosion consisting of few png images, been using it's alpha channel for blending, it works okay when it happens above water, but sometimes(=more of the time), when it is above the geometry it gets mad and behaves as if there wasnt geometry under it, but a skybox.

Here is a screenie of how it looks in game, and how does explosion frame looks like:



http://img15.imageshack.us/img15/4518/jalpha.jpg

http://img5.imageshack.us/img5/1237/expl14.png



And a code:


        BlendState bs = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
        bs.setBlendEnabled(true);
        bs.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
        bs.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
        bs.setTestEnabled(true);
        bs.setTestFunction(BlendState.TestFunction.GreaterThan);
        bs.setEnabled(true);
        explosionSurface.setRenderState(bs);



Thanks & good night!

No hints? :frowning:

have you added the explosionSurface to the transparent render queue?


.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);

That's it!

Thanks a lot :slight_smile:

Yup, works like a charm now, thanks!

Seems that some of explos were rendered in a wrong order, anyway here's a final code:



        BlendState  bs = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
        bs.setBlendEnabled(true);
        bs.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
        bs.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
        bs.setTestEnabled(true);
        bs.setTestFunction(BlendState.TestFunction.GreaterThanOrEqualTo);
        bs.setEnabled(true);
        explosionSurface.setRenderState(bs);
        ZBufferState zbs = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        zbs.setEnabled(true);
        zbs.setFunction(ZBufferState.TestFunction.Always);
        explosionSurface.setRenderState(zbs);
        explosionSurface.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
        explosionSurface.updateRenderState();



Thanks!

dhdd's reply helped improve effect a lot. Now it works that each explosion spawns few quads with texture on it, making animation more random and live,  but there still seem  to be some glitches in it:



http://img5.imageshack.us/img5/9048/askmonkey.jpg





As you can notice some of the explosions (small one for instance) have black colour around them ignoring explosions below.

Any tip? Pleaseeeee?

Well i guess the explosion texture was created with a black background  :slight_smile:

i guess you have to replace the darker colours with alpha to get the desired effect.

Hey, thanks for the reply, but that's not the case I'm afraid.

For small explosions I'm using same texture (png with alpha channel, check out the 1st post) as to other ones, just the quad is smaller.

Cheers!

in that case it is a sorting issue. play with the TestFunction in your BlendState and if that all doesnt help try adding a ZBufferState. this may be a stupid idea but it doesnt take much time and wont hurt  :wink: