@@ -8,13 +8,16 @@ import { Mesh } from '../../objects/Mesh.js';
8
8
import { ShaderLib } from '../shaders/ShaderLib.js' ;
9
9
import { cloneUniforms , getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js' ;
10
10
11
+ import * as backgroundColor from '../shaders/ShaderLib/backgroundColor.glsl.js' ;
12
+
11
13
const _rgb = { r : 0 , b : 0 , g : 0 } ;
12
14
13
15
function WebGLBackground ( renderer , cubemaps , cubeuvmaps , state , objects , alpha , premultipliedAlpha ) {
14
16
15
17
const clearColor = new Color ( 0x000000 ) ;
16
18
let clearAlpha = alpha === true ? 0 : 1 ;
17
19
20
+ let colorMesh ;
18
21
let planeMesh ;
19
22
let boxMesh ;
20
23
@@ -24,7 +27,6 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
24
27
25
28
function render ( renderList , scene ) {
26
29
27
- let forceClear = false ;
28
30
let background = scene . isScene === true ? scene . background : null ;
29
31
30
32
if ( background && background . isTexture ) {
@@ -38,11 +40,6 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
38
40
39
41
setClear ( clearColor , clearAlpha ) ;
40
42
41
- } else if ( background && background . isColor ) {
42
-
43
- setClear ( background , 1 ) ;
44
- forceClear = true ;
45
-
46
43
}
47
44
48
45
const environmentBlendMode = renderer . xr . getEnvironmentBlendMode ( ) ;
@@ -57,7 +54,7 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
57
54
58
55
}
59
56
60
- if ( renderer . autoClear || forceClear ) {
57
+ if ( renderer . autoClear ) {
61
58
62
59
renderer . clear ( renderer . autoClearColor , renderer . autoClearDepth , renderer . autoClearStencil ) ;
63
60
@@ -192,6 +189,39 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
192
189
// push to the pre-sorted opaque render list
193
190
renderList . unshift ( planeMesh , planeMesh . geometry , planeMesh . material , 0 , 0 , null ) ;
194
191
192
+ } else if ( background && background . isColor ) {
193
+
194
+ if ( colorMesh === undefined ) {
195
+
196
+ colorMesh = new Mesh (
197
+ new PlaneGeometry ( 2 , 2 ) ,
198
+ new ShaderMaterial ( {
199
+ name : 'BackgroundMaterial' ,
200
+ uniforms : {
201
+ color : { value : /*@__PURE__ */ new Color ( ) }
202
+ } ,
203
+ vertexShader : backgroundColor . vertex ,
204
+ fragmentShader : backgroundColor . fragment ,
205
+ side : FrontSide ,
206
+ depthTest : false ,
207
+ depthWrite : false ,
208
+ fog : false
209
+ } )
210
+ ) ;
211
+
212
+ colorMesh . geometry . deleteAttribute ( 'normal' ) ;
213
+ colorMesh . geometry . deleteAttribute ( 'uv' ) ;
214
+
215
+ objects . update ( colorMesh ) ;
216
+
217
+ }
218
+
219
+ colorMesh . material . uniforms . color . value . copy ( background ) . multiplyScalar ( scene . backgroundIntensity ) ;
220
+ colorMesh . layers . enableAll ( ) ;
221
+
222
+ // push to the pre-sorted opaque render list
223
+ renderList . unshift ( colorMesh , colorMesh . geometry , colorMesh . material , 0 , 0 , null ) ;
224
+
195
225
}
196
226
197
227
}
0 commit comments