Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
setBlendFunc help. — Gideros Forum

setBlendFunc help.

GregBUGGregBUG Guru
edited January 2012 in General questions
yes i know it's not documented yet but for my particle engine i really need it...

i need a little help..

for what I understood:

normal blending is:
setBlendFunc(BlendFactor.ZERO, BlendFactor.ZERO)
Additive Alpha Blending
setBlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE)
Solid Alpha Blending
setBlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ZERO)
but i can't find right combination of
screen alpha blending and multiply alpha blending

(and i don't know if the above are really correct ;;) )
any help? :)
TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
www.tntengine.com

Comments

  • atilimatilim Maintainer
    edited January 2012
    Hi Greg,

    You can use this (for example add to init.lua):
    Sprite.ALPHA = "alpha"
    Sprite.NO_ALPHA = "noAlpha"
    Sprite.ADD = "add"
    Sprite.MULTIPLY = "multiply"
    Sprite.SCREEN = "screen"
     
    function Sprite:setBlendMode(mode)
    	if type(mode) ~= "string" then
    		error("bad argument #2 to 'setBlendMode' (string expected, got "..type(mode)..")")
    	end
     
    	if mode == Sprite.ALPHA then
    		self:setBlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_SRC_ALPHA)
    	elseif mode == Sprite.NO_ALPHA then
    		self:setBlendFunc(BlendFactor.ONE, BlendFactor.ZERO)
    	elseif mode == Sprite.ADD then
    		self:setBlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE)
    	elseif mode == Sprite.MULTIPLY then
    		self:setBlendFunc(BlendFactor.DST_COLOR, BlendFactor.ONE_MINUS_SRC_ALPHA)
    	elseif mode == Sprite.SCREEN then
    		self:setBlendFunc(BlendFactor.ONE, BlendFactor.ONE_MINUS_SRC_COLOR)
    	else
    		error("Parameter 'blendMode' must be one of the accepted values.")
    	end
    end
     
    Sprite.clearBlendMode = Sprite.clearBlendFunc
    After we release the next version, you can safely remove this and continue. Because I've already added this function.

    cheers,
  • thank you very much!
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • GregBUGGregBUG Guru
    edited January 2012
    just tested and work fine...
    but
    screen blending works much like noAlpha :-S

    the "screen" blending that i want to do is (like in game*alad particles)
    like self:setBlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_DST_ALPHA)
    but is not perfect...

    @-)
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • GregBUGGregBUG Guru
    edited January 2012
    no this is a little bit different from ALPHA
    alfa is:
    (BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_SRC_ALPHA)
    what i tried is:
    (BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_DST_ALPHA)

    SCREEN blending used with an another game engine .. it's a middle way between ALPHA and ADD...
    i don't know if IT'S the correct way... but...

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    Hi,

    I've done some tests at http://www.andersriggelsen.dk/glblendfunc.php

    I think the most similar result to screen blend is (BlendFactor.SRC_ALPHA, BlendFactor.ONE_MINUS_SRC_COLOR)

    What do you think?

  • Hi! atilim!

    1st. thank for your time on this.

    yes the effect are very similar but there are visible black box around the sprites...
    if you want i could send to you the sources of particle engine and a litte test program...


    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    That would be great.
    I start to think, there may be no exact way to do screen blending.
  • email just sent... ;;)
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    edited January 2012
    Currently, I cannot see a way to implement screen blending with correct alpha. Maybe the function glBlendFuncSeperate can be a solution but currently I'm not sure if all Android devices support it (e.g. glBlendFuncSeperate is supported for iOS 3.0+). Right now, let's give support for additive and multiplicative blending and leave screen blending for the future releases.
  • ok. thanks atilim.

    add and mul blending may be enough for very many effects!

    thanks again for looking at this!. :P
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • atilimatilim Maintainer
    Hi GregBUG,

    With the introduction of premultipled alpha, now the screen blending mode works perfectly. I've added this to the setBlendMode function.
  • Oh that's fine atilim!!! Thanks.

    Dislikes: Apollo14

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
    +1 -1 (+0 / -1 )Share on Facebook
Sign In or Register to comment.