-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
Premultiplied alpha on materials #8245
Conversation
@@ -491,6 +491,8 @@ THREE.WebGLProgram = ( function () { | |||
parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '', | |||
parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '', | |||
|
|||
parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add parameters.premultipliedAlpha = material.premultipliedAlpha
to WebGLPrograms.js
too.
As an alternative API, consider what I said in #5810 (comment):
That way, all you have to do in javascript is set: material.blending = THREE.PremultipyAlphaBlending; The new property The new _gl.blendEquation( _gl.FUNC_ADD );
_gl.blendFunc( _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA ); In the shader, you would add this, instead: #ifdef PREMULTIPLIED_ALPHA_BLENDING
gl_FragColor.rgb *= gl_FragColor.a;
#endif |
I've fixed a few bugs with the implementation, switch from the boolean material.premultipledAlpha to material.blend = THREE.PremultipledAlphaBlending and then I have added an example: http://ci.threejs.org/api/pullrequests/8245/examples/webgl_materials_transparency.html |
@@ -0,0 +1,6 @@ | |||
#ifdef PREMULTIPLIED_ALPHA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef PREMULTIPLIED_ALPHA_BLENDING
gl_FragColor.rgb *= gl_FragColor.a;
#endif
We do not want this to be confused with renderer.premultipliedAlpha
.
48a46a9
to
7009dbf
Compare
@WestLangley thank you for the valuable feedback. :) You are right that I should make those changes. One issue though is that I have already built another PR (#8250) on top of this one and it included other refactors. Given that this feedback is about internals, and not about public interfaces, could we merge this and possibly the other PR (inline tonemapping) and then I can make these non-interface refactoring changes? |
@bhouston Sure. Merge and fix later. |
Premultiplied alpha on materials
Thanks guys! |
One thing though.... Is there a way to make this the default? In the previous approach ( With the new |
Well you could set Material.blending = THREE.PremultipliedAlphaBlending in Material.js? |
We could also rename THREE.PremultipliedAlphaBlending to be THREE.PremultipledAlphaNormalBlending, which suggests this is the normal mode. It is a bit long through. We can then have other THREE.PremultipledAlphaAddBlending, etc. |
I think that should do. However, what happens if the user wants |
Discussion continued in #8255 |
Using premultiplied alpha on materials leads to better results for areas where there are specular highlights on transparency when using RGBA8 buffers. This change should be perfectly backwards compatible, but allows for easy usage of premultiplied alpha when desired.
This was discussed here: #5810 Clara.io has been running for more than year with premultiplied alpha to great results. I'd like to get this option into ThreeJS proper, at least as an option that people can use.