@@ -30,8 +30,6 @@ import {
30
30
import { MeshInstance } from '../../scene/mesh-instance.js' ;
31
31
import { LightingParams } from '../../scene/lighting/lighting-params.js' ;
32
32
import { WorldClusters } from '../../scene/lighting/world-clusters.js' ;
33
- import { shaderChunks } from '../../scene/shader-lib/chunks/chunks.js' ;
34
- import { shaderChunksLightmapper } from '../../scene/shader-lib/chunks/chunks-lightmapper.js' ;
35
33
import { Camera } from '../../scene/camera.js' ;
36
34
import { GraphNode } from '../../scene/graph-node.js' ;
37
35
import { StandardMaterial } from '../../scene/materials/standard-material.js' ;
@@ -232,41 +230,29 @@ class Lightmapper {
232
230
}
233
231
}
234
232
235
- createMaterialForPass ( device , scene , pass , addAmbient ) {
233
+ createMaterialForPass ( scene , pass , addAmbient ) {
236
234
const material = new StandardMaterial ( ) ;
237
235
material . name = `lmMaterial-pass:${ pass } -ambient:${ addAmbient } ` ;
238
236
material . chunks . APIVersion = CHUNKAPI_1_65 ;
239
237
material . setDefine ( 'UV1LAYOUT' , '' ) ; // draw into UV1 texture space
238
+ material . setDefine ( 'LIT_LIGHTMAP_BAKING' , '' ) ;
240
239
241
240
if ( pass === PASS_COLOR ) {
242
- let bakeLmEndChunk = shaderChunksLightmapper . bakeLmEndPS ; // encode to RGBM
241
+ material . setDefine ( 'LIT_LIGHTMAP_BAKING_COLOR' , '' ) ;
243
242
if ( addAmbient ) {
244
- // diffuse light stores accumulated AO, apply contrast and brightness to it
245
- // and multiply ambient light color by the AO
246
- bakeLmEndChunk = `
247
- dDiffuseLight = ((dDiffuseLight - 0.5) * max(${ scene . ambientBakeOcclusionContrast . toFixed ( 1 ) } + 1.0, 0.0)) + 0.5;
248
- dDiffuseLight += vec3(${ scene . ambientBakeOcclusionBrightness . toFixed ( 1 ) } );
249
- dDiffuseLight = saturate(dDiffuseLight);
250
- dDiffuseLight *= dAmbientLight;
251
- ${ bakeLmEndChunk }
252
- ` ;
243
+ material . setDefine ( 'LIT_LIGHTMAP_BAKING_ADD_AMBIENT' , '' ) ;
253
244
} else {
254
245
material . ambient = new Color ( 0 , 0 , 0 ) ; // don't bake ambient
255
246
}
256
- material . chunks . basePS = shaderChunks . basePS + ( this . bakeHDR ? '' : '\n#define LIGHTMAP_RGBM\n' ) ;
257
- material . chunks . endPS = bakeLmEndChunk ;
247
+
248
+ if ( ! this . bakeHDR ) material . setDefine ( 'LIGHTMAP_RGBM' , '' ) ;
249
+
258
250
material . lightMap = this . blackTex ;
259
251
} else {
260
- material . chunks . basePS = `
261
- #define STD_LIGHTMAP_DIR
262
- ${ shaderChunks . basePS }
263
- uniform float bakeDir;
264
- ` ;
265
- material . chunks . endPS = shaderChunksLightmapper . bakeDirLmEndPS ;
252
+ material . setDefine ( 'LIT_LIGHTMAP_BAKING_DIR' , '' ) ;
253
+ material . setDefine ( 'STD_LIGHTMAP_DIR' , '' ) ;
266
254
}
267
255
268
- // avoid writing unrelated things to alpha
269
- material . chunks . outputAlphaPS = '\n' ;
270
256
material . cull = CULLFACE_NONE ;
271
257
material . forceUv1 = true ; // provide data to xformUv1
272
258
material . update ( ) ;
@@ -277,13 +263,13 @@ class Lightmapper {
277
263
createMaterials ( device , scene , passCount ) {
278
264
for ( let pass = 0 ; pass < passCount ; pass ++ ) {
279
265
if ( ! this . passMaterials [ pass ] ) {
280
- this . passMaterials [ pass ] = this . createMaterialForPass ( device , scene , pass , false ) ;
266
+ this . passMaterials [ pass ] = this . createMaterialForPass ( scene , pass , false ) ;
281
267
}
282
268
}
283
269
284
270
// material used on last render of ambient light to multiply accumulated AO in lightmap by ambient light
285
271
if ( ! this . ambientAOMaterial ) {
286
- this . ambientAOMaterial = this . createMaterialForPass ( device , scene , 0 , true ) ;
272
+ this . ambientAOMaterial = this . createMaterialForPass ( scene , 0 , true ) ;
287
273
this . ambientAOMaterial . onUpdateShader = function ( options ) {
288
274
// mark LM as without ambient, to add it
289
275
options . litOptions . lightMapWithoutAmbient = true ;
@@ -694,6 +680,10 @@ class Lightmapper {
694
680
695
681
// apply scene settings
696
682
this . renderer . setSceneConstants ( ) ;
683
+
684
+ // uniforms
685
+ this . device . scope . resolve ( 'ambientBakeOcclusionContrast' ) . setValue ( this . scene . ambientBakeOcclusionContrast ) ;
686
+ this . device . scope . resolve ( 'ambientBakeOcclusionBrightness' ) . setValue ( this . scene . ambientBakeOcclusionBrightness ) ;
697
687
}
698
688
699
689
restoreScene ( ) {
0 commit comments