Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there anyway to use Subtract blend mode? #5255

Closed
rkdrnf opened this issue Nov 30, 2018 · 5 comments
Closed

Is there anyway to use Subtract blend mode? #5255

rkdrnf opened this issue Nov 30, 2018 · 5 comments

Comments

@rkdrnf
Copy link

@rkdrnf rkdrnf commented Nov 30, 2018

I'm trying to create color overlay effects, except certain area on the screen.

My plan was to cover whole screen as ADD Blendmode with color of my choice,
and remove effect from certain area by applying SUBTRACT Blendmode with the same color used in ADD Blendmode.

But It seems there's no Subtract Blendmode in pixi v4.

Is there any workaround I can try?
or can I implement custom blend mode in pixi v4?

@englercj
Copy link
Member

@englercj englercj commented Nov 30, 2018

Can you not use a mask to remove the additive sprite from certain areas?

@ivanpopelyshev
Copy link
Member

@ivanpopelyshev ivanpopelyshev commented Dec 5, 2018

I think params for subtract are [gl.ONE, gl.ONE] , but functions are [gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD]

You can make custom blendmode
http://www.html5gamedevs.com/topic/31803-scratch-card-effect/?tab=comments#comment-182673

However, pixi webglstate does not change blend function:
https://github.com/pixijs/pixi.js/blob/dev/src/core/renderers/webgl/WebGLState.js#L149

Lets patch it and bring everything together: https://www.pixiplayground.com/#/edit/6c0X5xaWa2MMy6vXfIix0

TA-DA!

image

P.S. Really? I didnt notice that ticket for 5 days?

@ivanpopelyshev
Copy link
Member

@ivanpopelyshev ivanpopelyshev commented Dec 5, 2018

Though, it doesnt help with your plan, because SUBTRACT does not subtract alpha. Change second FUNC_ADD to FUNC_REVERSE_SUBTRACT and it'll work just fine.

@ivanpopelyshev
Copy link
Member

@ivanpopelyshev ivanpopelyshev commented Jan 11, 2019

Maybe that's for your case:
KNOCKOUT: [gl.ZERO, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE_MINUS_SRC_ALPHA]

@lock
Copy link

@lock lock bot commented Mar 17, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.