@@ -261,6 +261,29 @@ THREE.WebGLRenderer = function ( parameters ) {
261
261
262
262
//
263
263
264
+ var backgroundCamera = new THREE . OrthographicCamera ( - 1 , 1 , 1 , - 1 , 0 , 1 ) ;
265
+ var backgroundCamera2 = new THREE . PerspectiveCamera ( ) ;
266
+ var backgroundPlaneMesh = new THREE . Mesh (
267
+ new THREE . PlaneBufferGeometry ( 2 , 2 ) ,
268
+ new THREE . MeshBasicMaterial ( { depthTest : false , depthWrite : false } )
269
+ ) ;
270
+ var backgroundBoxShader = THREE . ShaderLib [ 'cube' ] ;
271
+ var backgroundBoxMesh = new THREE . Mesh (
272
+ new THREE . BoxBufferGeometry ( 5 , 5 , 5 ) ,
273
+ new THREE . ShaderMaterial ( {
274
+ uniforms : backgroundBoxShader . uniforms ,
275
+ vertexShader : backgroundBoxShader . vertexShader ,
276
+ fragmentShader : backgroundBoxShader . fragmentShader ,
277
+ depthTest : false ,
278
+ depthWrite : false ,
279
+ side : THREE . BackSide
280
+ } )
281
+ ) ;
282
+ objects . update ( backgroundPlaneMesh ) ;
283
+ objects . update ( backgroundBoxMesh ) ;
284
+
285
+ //
286
+
264
287
function getTargetPixelRatio ( ) {
265
288
266
289
return _currentRenderTarget === null ? _pixelRatio : 1 ;
@@ -1137,7 +1160,46 @@ THREE.WebGLRenderer = function ( parameters ) {
1137
1160
1138
1161
this . setRenderTarget ( renderTarget ) ;
1139
1162
1140
- if ( this . autoClear || forceClear ) {
1163
+ //
1164
+
1165
+ var needsClear = this . autoClear || forceClear ;
1166
+ var background = scene . background ;
1167
+
1168
+ if ( background === null ) {
1169
+
1170
+ glClearColor ( _clearColor . r , _clearColor . g , _clearColor . b , _clearAlpha ) ;
1171
+
1172
+ } else if ( background instanceof THREE . CubeTexture ) {
1173
+
1174
+ backgroundCamera2 . projectionMatrix = camera . projectionMatrix ;
1175
+
1176
+ backgroundCamera2 . matrixWorld . extractRotation ( camera . matrixWorld ) ;
1177
+ backgroundCamera2 . matrixWorldInverse . getInverse ( backgroundCamera2 . matrixWorld ) ;
1178
+
1179
+ backgroundBoxMesh . material . uniforms [ "tCube" ] . value = background ;
1180
+ backgroundBoxMesh . modelViewMatrix . multiplyMatrices ( backgroundCamera2 . matrixWorldInverse , backgroundBoxMesh . matrixWorld ) ;
1181
+
1182
+ _this . renderBufferDirect ( backgroundCamera2 , null , backgroundBoxMesh . geometry , backgroundBoxMesh . material , backgroundBoxMesh , null ) ;
1183
+
1184
+ needsClear = false ;
1185
+
1186
+ } else if ( background instanceof THREE . Texture ) {
1187
+
1188
+ backgroundPlaneMesh . material . map = background ;
1189
+
1190
+ _this . renderBufferDirect ( backgroundCamera , null , backgroundPlaneMesh . geometry , backgroundPlaneMesh . material , backgroundPlaneMesh , null ) ;
1191
+
1192
+ needsClear = false ;
1193
+
1194
+ } else if ( background instanceof THREE . Color ) {
1195
+
1196
+ glClearColor ( background . r , background . g , background . b , 1 ) ;
1197
+
1198
+ needsClear = true ;
1199
+
1200
+ }
1201
+
1202
+ if ( needsClear ) {
1141
1203
1142
1204
this . clear ( this . autoClearColor , this . autoClearDepth , this . autoClearStencil ) ;
1143
1205
0 commit comments