diff --git a/src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js b/src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js index a97d92f34f2..8f287527212 100644 --- a/src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js +++ b/src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js @@ -35,8 +35,7 @@ import decodePS from './common/frag/decode.js'; // import encodePS from './common/frag/encode.js'; // import endPS from './lit/frag/end.js'; import envAtlasPS from './common/frag/envAtlas.js'; -// import envConstPS from './common/frag/envConst.js'; -import envMultiplyPS from './common/frag/envMultiply.js'; +import envProcPS from './common/frag/envProc.js'; // import falloffInvSquaredPS from './lit/frag/falloffInvSquared.js'; // import falloffLinearPS from './lit/frag/falloffLinear.js'; // import floatUnpackingPS from './lit/frag/float-unpacking.js'; @@ -240,7 +239,7 @@ const shaderChunksWGSL = { // endPS, envAtlasPS, // envConstPS, - envMultiplyPS, + envProcPS, // falloffInvSquaredPS, // falloffLinearPS, // floatUnpackingPS, diff --git a/src/scene/shader-lib/chunks-wgsl/common/frag/envMultiply.js b/src/scene/shader-lib/chunks-wgsl/common/frag/envMultiply.js deleted file mode 100644 index e1743831265..00000000000 --- a/src/scene/shader-lib/chunks-wgsl/common/frag/envMultiply.js +++ /dev/null @@ -1,7 +0,0 @@ -export default /* wgsl */` -uniform skyboxIntensity : f32; - -fn processEnvironment(color : vec3f) -> vec3f { - return color * uniform.skyboxIntensity; -} -`; diff --git a/src/scene/shader-lib/chunks-wgsl/common/frag/envProc.js b/src/scene/shader-lib/chunks-wgsl/common/frag/envProc.js new file mode 100644 index 00000000000..ad06ae4b0cf --- /dev/null +++ b/src/scene/shader-lib/chunks-wgsl/common/frag/envProc.js @@ -0,0 +1,13 @@ +export default /* wgsl */` +#ifdef LIT_SKYBOX_INTENSITY + uniform skyboxIntensity : f32; +#endif + +fn processEnvironment(color : vec3f) -> vec3f { + #ifdef LIT_SKYBOX_INTENSITY + return color * uniform.skyboxIntensity; + #else + return color; + #endif +} +`; diff --git a/src/scene/shader-lib/chunks-wgsl/skybox/frag/skybox.js b/src/scene/shader-lib/chunks-wgsl/skybox/frag/skybox.js index 62b7e46d84f..9f8e16e02ee 100644 --- a/src/scene/shader-lib/chunks-wgsl/skybox/frag/skybox.js +++ b/src/scene/shader-lib/chunks-wgsl/skybox/frag/skybox.js @@ -1,5 +1,7 @@ export default /* wgsl */` - #include "envMultiplyPS" + #define LIT_SKYBOX_INTENSITY + + #include "envProcPS" #include "gammaPS" #include "tonemappingPS" diff --git a/src/scene/shader-lib/chunks/chunk-validation.js b/src/scene/shader-lib/chunks/chunk-validation.js index cb6a755c53c..43fb434f27d 100644 --- a/src/scene/shader-lib/chunks/chunk-validation.js +++ b/src/scene/shader-lib/chunks/chunk-validation.js @@ -124,7 +124,9 @@ const removedChunks = { outputAlphaOpaque: CHUNKAPI_2_6, outputAlphaPremul: CHUNKAPI_2_6, cubeMapProjectBoxPS: CHUNKAPI_2_6, - cubeMapProjectNonePS: CHUNKAPI_2_6 + cubeMapProjectNonePS: CHUNKAPI_2_6, + envMultiplyPS: CHUNKAPI_2_6, + envConstPS: CHUNKAPI_2_6 }; // compare two "major.minor" semantic version strings and return true if a is a smaller version than b. diff --git a/src/scene/shader-lib/chunks/chunks.js b/src/scene/shader-lib/chunks/chunks.js index 800817df86f..c99b1d5a44e 100644 --- a/src/scene/shader-lib/chunks/chunks.js +++ b/src/scene/shader-lib/chunks/chunks.js @@ -35,8 +35,7 @@ import emissivePS from './standard/frag/emissive.js'; import encodePS from './common/frag/encode.js'; import endPS from './lit/frag/end.js'; import envAtlasPS from './common/frag/envAtlas.js'; -import envConstPS from './common/frag/envConst.js'; -import envMultiplyPS from './common/frag/envMultiply.js'; +import envProcPS from './common/frag/envProc.js'; import falloffInvSquaredPS from './lit/frag/falloffInvSquared.js'; import falloffLinearPS from './lit/frag/falloffLinear.js'; import floatUnpackingPS from './lit/frag/float-unpacking.js'; @@ -239,8 +238,7 @@ const shaderChunks = { encodePS, endPS, envAtlasPS, - envConstPS, - envMultiplyPS, + envProcPS, falloffInvSquaredPS, falloffLinearPS, floatUnpackingPS, diff --git a/src/scene/shader-lib/chunks/common/frag/envConst.js b/src/scene/shader-lib/chunks/common/frag/envConst.js deleted file mode 100644 index 1a01a129b99..00000000000 --- a/src/scene/shader-lib/chunks/common/frag/envConst.js +++ /dev/null @@ -1,5 +0,0 @@ -export default /* glsl */` -vec3 processEnvironment(vec3 color) { - return color; -} -`; diff --git a/src/scene/shader-lib/chunks/common/frag/envMultiply.js b/src/scene/shader-lib/chunks/common/frag/envMultiply.js deleted file mode 100644 index 0580db2dc23..00000000000 --- a/src/scene/shader-lib/chunks/common/frag/envMultiply.js +++ /dev/null @@ -1,7 +0,0 @@ -export default /* glsl */` -uniform float skyboxIntensity; - -vec3 processEnvironment(vec3 color) { - return color * skyboxIntensity; -} -`; diff --git a/src/scene/shader-lib/chunks/common/frag/envProc.js b/src/scene/shader-lib/chunks/common/frag/envProc.js new file mode 100644 index 00000000000..b3550da79e5 --- /dev/null +++ b/src/scene/shader-lib/chunks/common/frag/envProc.js @@ -0,0 +1,13 @@ +export default /* glsl */` +#ifdef LIT_SKYBOX_INTENSITY + uniform float skyboxIntensity; +#endif + +vec3 processEnvironment(vec3 color) { + #ifdef LIT_SKYBOX_INTENSITY + return color * skyboxIntensity; + #else + return color; + #endif +} +`; diff --git a/src/scene/shader-lib/chunks/skybox/frag/skybox.js b/src/scene/shader-lib/chunks/skybox/frag/skybox.js index 0eec97b632f..b25b569dfbe 100644 --- a/src/scene/shader-lib/chunks/skybox/frag/skybox.js +++ b/src/scene/shader-lib/chunks/skybox/frag/skybox.js @@ -1,5 +1,7 @@ export default /* glsl */` - #include "envMultiplyPS" + #define LIT_SKYBOX_INTENSITY + + #include "envProcPS" #include "gammaPS" #include "tonemappingPS" diff --git a/src/scene/shader-lib/programs/lit-shader.js b/src/scene/shader-lib/programs/lit-shader.js index 4a0bbfff9df..f17f2888328 100644 --- a/src/scene/shader-lib/programs/lit-shader.js +++ b/src/scene/shader-lib/programs/lit-shader.js @@ -504,6 +504,8 @@ class LitShader { this.fDefineSet(options.twoSidedLighting, 'LIT_TWO_SIDED_LIGHTING'); this.fDefineSet(options.lightMapEnabled, 'LIT_LIGHTMAP'); this.fDefineSet(options.dirLightMapEnabled, 'LIT_DIR_LIGHTMAP'); + this.fDefineSet(options.skyboxIntensity, 'LIT_SKYBOX_INTENSITY'); + this.fDefineSet(options.clusteredLightingShadowsEnabled, 'LIT_CLUSTERED_SHADOWS'); this.fDefineSet(hasTBN, 'LIT_TBN'); this.fDefineSet(options.hasTangents, 'LIT_TANGENTS'); this.fDefineSet(options.useNormals, 'LIT_USE_NORMALS'); @@ -620,14 +622,13 @@ class LitShader { // frontend func.append(this.frontendCode); - if (this.needsNormal) { - func.append(` + func.append(` + #ifdef LIT_NEEDS_NORMAL #include "cubeMapRotatePS" #include "cubeMapProjectPS" - `); - - func.append(options.skyboxIntensity ? chunks.envMultiplyPS : chunks.envConstPS); - } + #include "envProcPS" + #endif + `); if ((this.lighting && options.useSpecular) || this.reflections) { func.append(`