@@ -1098,7 +1098,7 @@ class RenderWebGL extends EventEmitter {
10981098 if ( hasMask ?
10991099 maskMatches ( Drawable . sampleColor4b ( point , drawable , color , effectMask ) , mask3b ) :
11001100 drawable . isTouching ( point ) ) {
1101- RenderWebGL . sampleColor3b ( point , candidates , color ) ;
1101+ this . sampleColor4b ( point , candidates , color ) ;
11021102 if ( debugCanvasContext ) {
11031103 debugCanvasContext . fillStyle = `rgb(${ color [ 0 ] } ,${ color [ 1 ] } ,${ color [ 2 ] } )` ;
11041104 debugCanvasContext . fillRect ( x - bounds . left , bounds . bottom - y , 1 , 1 ) ;
@@ -2299,9 +2299,13 @@ class RenderWebGL extends EventEmitter {
22992299 * @param {Uint8ClampedArray } dst The color3b space to store the answer in.
23002300 * @return {Uint8ClampedArray } The dst vector with everything blended down.
23012301 */
2302- static sampleColor3b ( vec , drawables , dst ) {
2303- dst = dst || new Uint8ClampedArray ( 3 ) ;
2304- dst . fill ( 0 ) ;
2302+ sampleColor4b ( vec , drawables , dst ) {
2303+ dst = dst || new Uint8ClampedArray ( 4 ) ;
2304+ dst [ 0 ] = 0 ;
2305+ dst [ 1 ] = 0 ;
2306+ dst [ 2 ] = 0 ;
2307+ // dst[3] is set at the end
2308+
23052309 let blendAlpha = 1 ;
23062310 for ( let index = 0 ; blendAlpha !== 0 && index < drawables . length ; index ++ ) {
23072311 /*
@@ -2317,11 +2321,13 @@ class RenderWebGL extends EventEmitter {
23172321 dst [ 2 ] += __blendColor [ 2 ] * blendAlpha ;
23182322 blendAlpha *= ( 1 - ( __blendColor [ 3 ] / 255 ) ) ;
23192323 }
2320- // Backdrop could be transparent, so we need to go to the "clear color" of the
2321- // draw scene (white) as a fallback if everything was alpha
2322- dst [ 0 ] += blendAlpha * 255 ;
2323- dst [ 1 ] += blendAlpha * 255 ;
2324- dst [ 2 ] += blendAlpha * 255 ;
2324+ // Backdrop could be transparent, so we need to go to the background color of the
2325+ // draw scene as a fallback if drawables are transparent.
2326+ dst [ 0 ] += 255 * this . _backgroundColor4f [ 0 ] * blendAlpha ;
2327+ dst [ 1 ] += 255 * this . _backgroundColor4f [ 1 ] * blendAlpha ;
2328+ dst [ 2 ] += 255 * this . _backgroundColor4f [ 2 ] * blendAlpha ;
2329+ blendAlpha *= 1 - this . _backgroundColor4f [ 3 ] ;
2330+ dst [ 3 ] = 255 * ( 1 - blendAlpha ) ;
23252331 return dst ;
23262332 }
23272333
0 commit comments