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

Premultiplied alpha on materials #8245

Merged
merged 8 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ THREE.Material = function () {

this.alphaTest = 0;

this.premultipliedAlpha = false;

this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer

this.visible = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifdef PREMULTIPLIED_ALPHA
Copy link
Collaborator

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.


// Get get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment not required, now.

gl_FragColor.rgb *= gl_FragColor.a;

#endif
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/linedashed_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ void main() {
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, diffuseColor.a ) );

#include <fog_fragment>
#include <premultiplied_alpha_fragment>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider premultiplied_alpha_blending_fragment.


}
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ void main() {
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, diffuseColor.a ) );

#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ void main() {
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, diffuseColor.a ) );

#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/meshphong_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ void main() {
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, diffuseColor.a ) );

#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/meshstandard_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ void main() {
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, diffuseColor.a ) );

#include <fog_fragment>
#include <premultiplied_alpha_fragment>

}
1 change: 1 addition & 0 deletions src/renderers/shaders/ShaderLib/points_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ void main() {
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, diffuseColor.a ) );

#include <fog_fragment>
#include <premultiply_alpha_fragment>

}
2 changes: 2 additions & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ THREE.WebGLProgram = ( function () {
parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',

parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
Copy link
Owner

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.


parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',

Expand Down
3 changes: 2 additions & 1 deletion utils/build/includes/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl",
"src/renderers/shaders/ShaderChunk/color_vertex.glsl",
"src/renderers/shaders/ShaderChunk/common.glsl",
"src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl",
"src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl",
"src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl",
"src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl",
"src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl",
Expand Down Expand Up @@ -171,6 +171,7 @@
"src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl",
"src/renderers/shaders/ShaderChunk/normal_fragment.glsl",
"src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl",
"src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl",
"src/renderers/shaders/ShaderChunk/project_vertex.glsl",
"src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl",
"src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl",
Expand Down