Skip to content

Commit 9e15c01

Browse files
ecivicmrdoob
authored andcommitted
Update SoftwareRenderer.js
THREE.SoftwareRenderer alpha flag implementation.
1 parent 6400f2c commit 9e15c01

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

examples/js/renderers/SoftwareRenderer.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ THREE.SoftwareRenderer = function ( parameters ) {
1818
var context = canvas.getContext( '2d', {
1919
alpha: parameters.alpha === true
2020
} );
21+
22+
var alpha = parameters.alpha;
2123

2224
var shaders = {};
2325
var textures = {};
@@ -105,7 +107,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
105107
canvas.width = canvasWidth;
106108
canvas.height = canvasHeight;
107109

108-
context.fillStyle = clearColor.getStyle();
110+
context.fillStyle = alpha ? : "rgba(0, 0, 0, 0)" : clearColor.getStyle();
109111
context.fillRect( 0, 0, canvasWidth, canvasHeight );
110112

111113
imagedata = context.getImageData( 0, 0, canvasWidth, canvasHeight );
@@ -336,7 +338,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
336338
canvas.width = canvasWidth;
337339
canvas.height = canvasHeight;
338340

339-
context.fillStyle = clearColor.getStyle();
341+
context.fillStyle = alpha ? "rgba(0, 0, 0, 0)" : clearColor.getStyle();
340342
context.fillRect( 0, 0, canvasWidth, canvasHeight );
341343

342344
imagedata = context.getImageData( 0, 0, canvasWidth, canvasHeight );
@@ -372,11 +374,11 @@ THREE.SoftwareRenderer = function ( parameters ) {
372374
data[ i ] = clearColor.r * 255 | 0;
373375
data[ i + 1 ] = clearColor.g * 255 | 0;
374376
data[ i + 2 ] = clearColor.b * 255 | 0;
375-
data[ i + 3 ] = 255;
377+
data[ i + 3 ] = alpha ? : 0 : 255;
376378

377379
}
378380

379-
context.fillStyle = clearColor.getStyle();
381+
context.fillStyle = alpha ? "rgba(0, 0, 0, 0)" : clearColor.getStyle();
380382
context.fillRect( 0, 0, canvasWidth, canvasHeight );
381383

382384
}
@@ -1478,7 +1480,7 @@ THREE.SoftwareRenderer = function ( parameters ) {
14781480
data[ poffset ++ ] = clearColor.r * 255 | 0;
14791481
data[ poffset ++ ] = clearColor.g * 255 | 0;
14801482
data[ poffset ++ ] = clearColor.b * 255 | 0;
1481-
data[ poffset ++ ] = 255;
1483+
data[ poffset ++ ] = alpha ? : 0 : 255;
14821484

14831485
}
14841486

0 commit comments

Comments
 (0)