Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring fo envMultiply and envConst chunks #7399

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/scene/shader-lib/chunks-wgsl/chunks-wgsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -240,7 +239,7 @@ const shaderChunksWGSL = {
// endPS,
envAtlasPS,
// envConstPS,
envMultiplyPS,
envProcPS,
// falloffInvSquaredPS,
// falloffLinearPS,
// floatUnpackingPS,
Expand Down
7 changes: 0 additions & 7 deletions src/scene/shader-lib/chunks-wgsl/common/frag/envMultiply.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/scene/shader-lib/chunks-wgsl/common/frag/envProc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default /* wgsl */`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% keen on the envProc naming. skybox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have skybox chunk that does the skybox. This is just a small chunk used by both skybox and lit-shader

#ifdef LIT_SKYBOX_INTENSITY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is worth having a shader variant just to avoid a multiply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, but this code is slightly more complicated than I want to handle during this conversion. Ideally we add skybox intensity to material as well, and unify it all.

uniform skyboxIntensity : f32;
#endif

fn processEnvironment(color : vec3f) -> vec3f {
#ifdef LIT_SKYBOX_INTENSITY
return color * uniform.skyboxIntensity;
#else
return color;
#endif
}
`;
4 changes: 3 additions & 1 deletion src/scene/shader-lib/chunks-wgsl/skybox/frag/skybox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default /* wgsl */`
#include "envMultiplyPS"
#define LIT_SKYBOX_INTENSITY

#include "envProcPS"
#include "gammaPS"
#include "tonemappingPS"

Expand Down
4 changes: 3 additions & 1 deletion src/scene/shader-lib/chunks/chunk-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions src/scene/shader-lib/chunks/chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -239,8 +238,7 @@ const shaderChunks = {
encodePS,
endPS,
envAtlasPS,
envConstPS,
envMultiplyPS,
envProcPS,
falloffInvSquaredPS,
falloffLinearPS,
floatUnpackingPS,
Expand Down
5 changes: 0 additions & 5 deletions src/scene/shader-lib/chunks/common/frag/envConst.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/scene/shader-lib/chunks/common/frag/envMultiply.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/scene/shader-lib/chunks/common/frag/envProc.js
Original file line number Diff line number Diff line change
@@ -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
}
`;
4 changes: 3 additions & 1 deletion src/scene/shader-lib/chunks/skybox/frag/skybox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default /* glsl */`
#include "envMultiplyPS"
#define LIT_SKYBOX_INTENSITY

#include "envProcPS"
#include "gammaPS"
#include "tonemappingPS"

Expand Down
13 changes: 7 additions & 6 deletions src/scene/shader-lib/programs/lit-shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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(`
Expand Down