Need help with blending

About Monkey 2 Forums Monkey 2 Programming Help Need help with blending

This topic contains 9 replies, has 4 voices, and was last updated by  ArtemKuchin 1 year, 7 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #10527

    ArtemKuchin
    Participant

    Please take a look at the attached file.

    image1 is a red circle

    image is  green circle

    This image was created like this:

     

     

    The problem for me is area marked 3. I don’t need any blending there.

    I need to blend only the image2 over image1 and get the yello as in area 1.

    However, in area  3 i need to get pure green same as in area 4.

    As i understand i can use some trickery with getting pixmap from canvas, processing it based on RGV values and the putting it back. But that might be too slow. Green circle moves with  mouse, need to be very responsive.

    I don’t know anything abiut shaders, but maybe they may help?

    Attachments:
    #10529

    Jesse
    Participant

    I don’t know if this will help you but the only way I can think of is to do it like this:

    [/crayon]
    #10537

    ArtemKuchin
    Participant

    alas, this is not it because if te green circle is for example 0x88 then when blended with itself  using additive blending it gets 0xff color in green channel, which is is not the original 0x88

    i miss normal bitwise OR/AND/XOR blending

    #10544

    Jesse
    Participant

    you can try drawing the circles to an image and test the speed to see if it’s fast enough for you.

    something like this:

    [/crayon]
    #10546

    Simon Armstrong
    Participant

    I suspect separating the display into two layers may be possible with rects in background and circles in frontground.

    An offscreen render surface initialized with alpha 0 could be composed of the circles and then layered on to main display may be pretty easy hack for mojo2d.

    A single overlay may add a fixed overhead to render time but open up a lot of possibilities for interesting compositing effects.

    #10590

    ArtemKuchin
    Participant

    Thank you Jesse.

     

    I ran your code and it works as needed.I tested perfomance and compared.

    Your code run at 90 fps

    My code runs at 350 fps

    If i put

    cnvs=canvas

    befor

    cnvs.Clear(New Color(0,0,0,0))

    (basically drawing again everything into main canvas instead of image)

    I get 300 fps from your code

    So, drawing into canvas attached to an image has huge perfomance penalty.

    Interesting, however, than it does not really matter how much i draw into that image canvas. If i have flush or clear

    i get stable 90 fps.

    I wonder why so much perfomance penalty and why it is pretty constant and independat of how much is drawing into it.

    #10598

    Jesse
    Participant

    If i put

    cnvs=canvas

    befor

    cnvs.Clear(New Color(0,0,0,0))

    (basically drawing again everything into main canvas instead of image)

    Doesn’t that take you back to the original problem? Might as well not use cnvs.

    it doesn’t make sense to me.

    #10603

    ArtemKuchin
    Participant

    Jesse, yes, of course when i make this change i get the original problem.

    It was only done to demonstarte the perfomance penalty. And the question why drawing into image convas is so much slower.

    #10604

    Ethernaut
    Participant

    You can try creating any images that will be updated on every frame with “TextureFlags.Dynamic”, like :

    Etc, to see if the frame rate improves on your hardware.

    #10614

    ArtemKuchin
    Participant

    Amazing!

    Windows 10, intel graphics

    before 90 fps

    after  220 fps

    Android, Samsung J5 2016

    before 30 fps

    after 120 fps

    now this can be actually used 🙂

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.