Skip to content

Commit

Permalink
Only rebuild shaders on sky rotation change if changing away from ide…
Browse files Browse the repository at this point in the history
…ntity (#5467)

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

* update based on comment

* lint

---------

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky committed Jul 13, 2023
1 parent 542956a commit cba97fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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 @@ -352,7 +350,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

0 comments on commit cba97fd

Please sign in to comment.