Jump to content

Is it possible to subtract a graphics shape from another shape?


Recommended Posts


I am new here and to pixi.js and game development in general and I wanted to know if it is it possible to subtract a graphics shape from another shape using pixi.js?


I know it is possible using canvas' "globalCompositeOperation" with "destination-out" or "source-out" like is demonstrated here:



but I wanted to know if it is supported by webgl as well and if there's an already built method in pixi.js for it.


if such a method does not exist yet, what would be the best way to implement it?


thank you for your time.

Link to comment
Share on other sites

  • 7 months later...

you can add this to the webgl blendmodes:

        PIXI.blendModesWebGL[SOURCE_OUT]      = [gl.ONE_MINUS_DST_ALPHA, gl.ZERO];        PIXI.blendModesWebGL[SOURCE_IN]       = [gl.DST_ALPHA,           gl.ZERO];        PIXI.blendModesWebGL[DESTINATION_OUT] = [gl.ZERO,                gl.ONE_MINUS_SRC_ALPHA];        PIXI.blendModesWebGL[DESTINATION_IN]  = [gl.ZERO,                gl.SRC_ALPHA];

And then this to the BLEND_MODES const:


Now you should be able to set the blendMode of objects with these compositing modes in webGL :)



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...