Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Help with Sprite:setBlendingMode "multiply" — Gideros Forum

Help with Sprite:setBlendingMode "multiply"

piepie Member
edited July 2015 in General questions
Hi, I was experimenting with this tutorial to apply setBlendingMode on a Sprite containing a shape and not a Bitmap.

http://giderosmobile.com/forum/discussion/233/tutorial-how-to-create-a-spot-light/p1

I tried drawing a shape with SOLID black fill and with Texture.REPEAT, both in black and white. But I can't get it working :-< .
Maybe I am missing something but I am unable to understand what:
if you have some minutes to share can you please check the attachment and point me in the right direction?

Thank you

Comments

  • hgy29hgy29 Maintainer
    Hmm, to me it works as it should: you draw a moving white spot on your scene then multiply the scene by a back or white square. It renders what I would expect.

    What did you want to achieve ?
  • piepie Member
    @hgy29 I'd like to see the background "under" the black shape where the white spot overlaps it.
    Maybe I misunderstood the usage of "multiply" blending mode.. :)
    thank you
  • hgy29hgy29 Maintainer
    Accepted Answer
    Still not really sure I understood correctly, but I suppose it doesn't work because the spotlight is drawn before the 'background', while the background doesn't take up full screen.
    Original idea was:
    1°) you draw a white spotlight above a black background
    2°) the (full screen) logo was then multiplied by what was on the before it screen, making it appear where the spotlight was (white(1) * white -> white, white * black (0) -> black)

    It could have been written has:
    1°) draw anything you want in the background
    2°) draw the spotlight (with multiply) above

    but in that case the spotlight sprite must cover all screen, so that all pixels are blended.
  • piepie Member
    @hgy29 my goal was to use multiply blending mode and "spotlights" to draw a kind of "fog of war" over a tilemap. I'm doing it in the "wrong" way now, and I was looking for a better (more performing) solution: now I am checking for each tile and setting an alpha on a black layer "above the tilemap". But this was a workaround, and it's time to fix it :)

    I thought I misunderstood how "multiply" works.

    So if there is no-pixel (outside the spotlight sprite) it can't blend because it's missing the "black" pixels? (and this is why you say that the spotlight sprite must cover all screen?)

    Thank you very much :)
  • hgy29hgy29 Maintainer
    Accepted Answer
    Yes, think that way: every time gideros draws a sprite, it actually draws a series of triangles. A bitmap sprite for instance is comprised of two triangles forming a rectangle. When the GPU render those triangles, it determine the color and alpha value or each pixel of the drawn shape, then each pixel is blended with the pixel it would otherwise replace on screen.
    So blending applies only to areas where the GPU actually want to draw something.
  • piepie Member
    Allright, this makes makes sense even to me :)

    thanks
Sign In or Register to comment.