Skip to content

Commit

Permalink
Fix un-premultiply when alpha is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Dec 8, 2016
1 parent 512b9a6 commit b172977
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,17 @@ define([
' gltf_blend_main(); \n';

// Un-premultiply the alpha so that blending is correct.

// Avoid divide-by-zero. The code below is equivalent to:
// if (gl_FragColor.a > 0.0)
// {
// gl_FragColor.rgb /= gl_FragColor.a;
// }

if (premultipliedAlpha) {
shader += ' gl_FragColor.rgb /= gl_FragColor.a; \n';
shader +=
' float alpha = 1.0 - ceil(gl_FragColor.a) + gl_FragColor.a; \n' +
' gl_FragColor.rgb /= alpha; \n';
}

shader +=
Expand Down

0 comments on commit b172977

Please sign in to comment.