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

Only rebuild shaders on sky rotation change if changing away from identity #5467

Merged
merged 4 commits into from
Jul 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/scene/materials/standard-material-options-builder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Quat } from '../../core/math/quat.js';

import {
PIXELFORMAT_DXT5, PIXELFORMAT_RGBA8, TEXTURETYPE_SWIZZLEGGGR
} from '../../platform/graphics/constants.js';
Expand Down Expand Up @@ -350,7 +348,7 @@ class StandardMaterialOptionsBuilder {

// TODO: add a test for if non skybox cubemaps have rotation (when this is supported) - for now assume no non-skybox cubemap rotation
options.litOptions.skyboxIntensity = usingSceneEnv && (scene.skyboxIntensity !== 1 || scene.physicalUnits);
options.litOptions.useCubeMapRotation = usingSceneEnv && scene.skyboxRotation && !scene.skyboxRotation.equals(Quat.IDENTITY);
options.litOptions.useCubeMapRotation = usingSceneEnv && scene._skyboxRotationShaderInclude;
}

_updateLightOptions(options, scene, stdMat, objDefs, sortedLights, staticLightList) {
Expand Down
13 changes: 11 additions & 2 deletions src/scene/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class Scene extends EventHandler {
this._skyboxLuminance = 0;
this._skyboxMip = 0;

this._skyboxRotationShaderInclude = false;
this._skyboxRotation = new Quat();
this._skyboxRotationMat3 = new Mat3();
this._skyboxRotationMat4 = new Mat4();
Expand Down Expand Up @@ -626,14 +627,22 @@ class Scene extends EventHandler {
*/
set skyboxRotation(value) {
if (!this._skyboxRotation.equals(value)) {

const isIdentity = value.equals(Quat.IDENTITY);
this._skyboxRotation.copy(value);
if (value.equals(Quat.IDENTITY)) {

if (isIdentity) {
this._skyboxRotationMat3.setIdentity();
} else {
this._skyboxRotationMat4.setTRS(Vec3.ZERO, value, Vec3.ONE);
this._skyboxRotationMat4.invertTo3x3(this._skyboxRotationMat3);
}
this._resetSky();

// only reset sky / rebuild scene shaders if rotation changed away from identity for the first time
if (!this._skyboxRotationShaderInclude && !isIdentity) {
this._skyboxRotationShaderInclude = true;
this._resetSky();
}
}
}

Expand Down