Skip to content

Commit

Permalink
Merge pull request #457 from tsherif/pre-mult-alpha
Browse files Browse the repository at this point in the history
Alpha pre-multiplied in fragment shader for proper compositing.
  • Loading branch information
xeolabs committed Mar 16, 2016
2 parents 21f8249 + 6b267a7 commit 668f3fa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/display/chunks/flagsChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SceneJS_ChunkFactory.createChunkType({
// Entering a transparency bin

gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
frameCtx.blendEnabled = true;

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/core/display/chunks/regionMapChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SceneJS_ChunkFactory.createChunkType({
// Entering a transparency bin

gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
frameCtx.blendEnabled = true;

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/core/display/chunks/renderTargetChunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SceneJS_ChunkFactory.createChunkType({
// Enable blending for non-depth targets
if (frameCtx.blendEnabled) {
gl.enable(gl.BLEND);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/display/programSourceFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,10 @@ var SceneJS_ProgramSourceFactory = new (function () {
add("fragColor.rgb *= mix(SCENEJS_uFragmentFresnelEdgeColor.rgb, SCENEJS_uFragmentFresnelCenterColor.rgb, fragmentFresnel);");
}

if (!depthTargeting) {
add("fragColor.rgb *= fragColor.a;");
}

add("gl_FragColor = fragColor;");

add("}");
Expand Down

0 comments on commit 668f3fa

Please sign in to comment.