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

problem with CustomBlending #11280

Closed
4 of 13 tasks
Dark-Energy opened this issue May 4, 2017 · 10 comments
Closed
4 of 13 tasks

problem with CustomBlending #11280

Dark-Energy opened this issue May 4, 2017 · 10 comments

Comments

@Dark-Energy
Copy link

Dark-Energy commented May 4, 2017

Function setBlending in WebGLState incrorrectly process customBlending:

if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {

	if ( blending === AdditiveBlending ) { 

	} else if ( blending === SubtractiveBlending ) {

	} else if ( blending === MultiplyBlending ) {

	//need check if CustomBlending given

	} else {

		//set normalBlending every time

	}

}

if ( blending === CustomBlending ) {
Three.js version
  • Dev
  • r85
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, ...)
@WestLangley
Copy link
Collaborator

I formatted your post for clarity. Can you please make necessary corrections to your post and provide further detail?

@Dark-Energy
Copy link
Author

sorry for my poor english, well, i ment this post have enogh details. this code fragment, which need fix. when i give CustomBlending parameter, this code first set NormalBlending, then do some check:
if ( blending === CustomBlending ) {
if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst ...
{
this may either enable CustomBlending or not enable because some arbitrary conditions. Then normalBlending will be enabled anyway. In my view, need replace last "else" statement with "else if (blending !== customBlending)" in order prevent this.

@sasha240100
Copy link
Contributor

@Dark-Energy Why not using switch/case syntax?

@WestLangley
Copy link
Collaborator

In my view, need replace last "else" statement with "else if (blending !== customBlending)" in order prevent this.

@Dark-Energy So we may better understand, can you please edit your original post and show how you think the code should be written? No code fragments, please.

@Dark-Energy
Copy link
Author

how can i explain the code shoud be written with no code fragments?
i have written particle demo with customBlending and discover that my blending mode had been ignored. i began investgation and find that. I add pathed version library in my project.

There are two blocks of if's, first of them check and apply blending mode. It ended with 'else' block which enabled normalblending. State of WebGL is changed. Second if block check and apply custom modes. It checks state of srcColor & srcAlpha function changed and assign new values to local variables. And... this block may run only once, then it reckons states still unchanged. But state of blending may be changed in other places.
I patch the library, replace else in the end of first if block with 'else if'. Now my demo work fine.

@Dark-Energy
Copy link
Author

@sasha240100 this way is acceptable.

@WestLangley
Copy link
Collaborator

@mrdoob I think the OP is suggesting a one-line change in the WebGLState function setBlending():

} else if ( blending === MultiplyBlending ) {

	if ( premultipliedAlpha ) {

		gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
		gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );

	} else {

		gl.blendEquation( gl.FUNC_ADD );
		gl.blendFunc( gl.ZERO, gl.SRC_COLOR );

	}

} else if ( blending !== CustomBlending ) { // <==== PROPOSED CHANGE

	if ( premultipliedAlpha ) {

		gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
		gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );

	} else {

		gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
		gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );

	}

}

With all due respect, that change seems a bit hacky to me. I think the entire code block should not be executed if blending === CustomBlending.

@mrdoob
Copy link
Owner

mrdoob commented May 14, 2017

@WestLangley sounds hacky indeed.

@WestLangley
Copy link
Collaborator

@mrdoob I think something needs to be done. Maybe this one-line change is adequate to prevent the code block from being called when CustomBlending is used.

if ( ( blending !== CustomBlending ) && ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) ) {

@mrdoob
Copy link
Owner

mrdoob commented May 15, 2017

That looks good.

WestLangley added a commit that referenced this issue May 15, 2017
amakaroff82 pushed a commit to amakaroff82/three.js that referenced this issue May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants