Blending Mode?

BlitzMax Forums/BlitzMax Programming/Blending Mode?

therevills(Posted 2012) [#1]
Hi All,

I am trying to create a fire effect, but the LIGHTBLEND blend makes it too "white" and seethru...

Is there a better blend to "add" the colours together (to make them "glow") but not create the image with so much alpha?

Ta!


Armitage 1982(Posted 2012) [#2]
I know that Oddball add a new Blending mode called MOD2XBLEND with Odd2D.mod
http://blitzmax.com/Community/posts.php?topic=90436

It's something quite easy to add yourself really.
This new Blending mode allow you to choose the amount of light blending.

128 Red, 128 Green and 128 Blue is considered as neutral and transparent.
Going over these values will give you custom Lightblend.

I'm using this to do simple lightening effect in dark level of my game :
https://picasaweb.google.com/118027744236209794583/MetagolfScreenshots#5678572035698158514


therevills(Posted 2012) [#3]
Thanks for that, I actually did add MOD2XBLEND, but not sure how to use it.

I've just created an image with a grey background(128,128,128) and my fire image (light grey/white), but when I apply a colour via SetColor and draw it I get a square image instead of the fire image. Also SetAlpha doesnt seem to work with it?


Armitage 1982(Posted 2012) [#4]
Yes that's probably the drawback of using Mox2XBlend... :(

Sadly, I don't know any other solutions currently.


therevills(Posted 2012) [#5]
Thanks for trying to help anyway :)

Any chance you could show me a quick example on how you used mod2x? Your fire effect does look cool :)

I've been looking at blending tutorials and it looks like most of them use additive which I guess is LIGHTBLEND.

http://blog.martincrownover.com/examples-tutorials/particle-example-fire/

I can nearly make them look good on a black background, but as soon as I use them on an image background they go to white/see-thru.

Last edited 2012


therevills(Posted 2012) [#6]
I've put together this example, so you can see the issue:

http://pastebin.com/vwWngCzM

(Edit I broke code box :()

As soon as the Cls Colour changes to a bright background, the effect is ruined :(

Last edited 2012


Oddball(Posted 2012) [#7]
Have you tried laying down an ALPHABLEND base and then layering a subtle LIGHTBLEND glow over the top. I've tried a quick 5 minute hack of your pastebin code. With a little refinement and maybe a changed LIGHTBLEND sprite it might be what you are after.


Use the DataDefs from the pastebin as they break the codebox.

Last edited 2012


therevills(Posted 2012) [#8]
Thanks for trying Oddball, yep thats okay and I have tried it, but it still doesnt look as nice.... I'm thinking of just bloody creating an image animation now :(

I've been doing some research:

http://gamedev.stackexchange.com/questions/22989/how-can-i-achieve-a-good-fire-effect-with-alpha-blending-and-particles

So this post's solution is rendering to a texture, which is a bit slow in BlitzMax...

The last post also suggests premultiplied alpha... which I couldnt get to work, I tried:
  glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA

Which I thought was what they were talking about here:

http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx


col(Posted 2012) [#9]
Hiya guys.

Not sure if this blend table can help you decide the correct blend mode to use to get your desired effect......




therevills(Posted 2012) [#10]
Ta Dave... sometimes when I mess with the blend functions I totally lose the alpha in the background, so I end up drawing squares...

Samah has suggested that I use a sort of masking function:

* Draw the particle as a mask with ALPHABLEND
* Draw the particle normally with LIGHTBLEND

Of course this means you are doing twice as much drawing as normal... but it kindof works:

http://pastebin.com/wEQMDR8d

Last edited 2012

And heres a few images of it:

On a black background... looking good:


On a pink background with no masking... not looking good:


On a pink background with with masking... looking decent:


Last edited 2012


col(Posted 2012) [#11]
Nice :)

The blending/masking works well there!


Armitage 1982(Posted 2012) [#12]
The mask method is pretty cool but indeed require a second pass.
That's mainly why I was searching a more efficient way to draw more sprites on the screen in batch mode for example.
This is really important with particles because the Max2D isn't focus on speed but on ease of use. Rendering is currently the only slow part in my game and particles is barely ok with 5 "viewport" rendering (with all game "stuff" included, 4 players split screens and another floating camera, you can eventually reach something like 1024 particles pool x 5 without too much slow down and you can certainly improve this in many ways ;).

I will think about it for my next engine (full openGL or not ?).
Currently my fire effect only work great on dark areas like you said before (fire is visible thanks to color and shadows after all no ?). I'm only using Mod2xBlend for the bright effect around my fire and like it's discussed in another topic the disadvantage is that everything rendered before is affected like parallax, etc. But well, it is superfluous to fix this detail in my case so :D

Is fire a dynamic object in your game ?
Cause sometimes you can reach a better look'n'feel with animated images of a real fire (or pre-rendered fire with alpha in TimelineFx for example, you may also take a look at the realtime module of it, great particles engine !). With nowadays RAM it's another alternative.
Particles releasing particles give impressive results visually but consume a lot of processing time if not very optimized.


therevills(Posted 2012) [#13]
Is fire a dynamic object in your game ?


Yeah I did want it to be...

or pre-rendered fire with alpha in TimelineFx


I didnt know that TimelineFX can output to a pre-rendered files... I guess it's disabled in the demo, I can't even see an option for it. How do you do it? Found it! Right-click on the effect in the library and select Animation Properties, then click the "record" icon...

Last edited 2012

Last edited 2012


AdamRedwoods(Posted 2012) [#14]
blend modes are tough to fiddle and get it exact.

To do this dynamically, you could try to render to an FBO texture (color 0,0,0 with alpha 0) and just draw the texture quad.


Armitage 1982(Posted 2012) [#15]
True, but don't forget that FBO cannot be achieved on many GMA card (notebook, old system, etc.) because GL_EXT_framebuffer_object is missing from the OpenGL extensions.