Skip to content

Commit

Permalink
Set THREE.ColorManagement.legacyMode to false when using color manage…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
mrxz committed Jan 10, 2023
1 parent 775c764 commit ef06aaf
Show file tree
Hide file tree
Showing 16 changed files with 5 additions and 46 deletions.
4 changes: 0 additions & 4 deletions dist/aframe-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -15830,13 +15830,11 @@ module.exports.Component = registerComponent('light', {
case 'color':
{
light.color.set(value);
rendererSystem.applyColorCorrection(light.color);
break;
}
case 'groundColor':
{
light.groundColor.set(value);
rendererSystem.applyColorCorrection(light.groundColor);
break;
}
case 'angle':
Expand Down Expand Up @@ -16014,12 +16012,10 @@ module.exports.Component = registerComponent('light', {
getLight: function (data) {
var angle = data.angle;
var color = new THREE.Color(data.color);
this.rendererSystem.applyColorCorrection(color);
color = color.getHex();
var decay = data.decay;
var distance = data.distance;
var groundColor = new THREE.Color(data.groundColor);
this.rendererSystem.applyColorCorrection(groundColor);
groundColor = groundColor.getHex();
var intensity = data.intensity;
var type = data.type;
Expand Down
1 change: 0 additions & 1 deletion src/components/generic-tracked-controller-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ module.exports.Component = registerComponent('generic-tracked-controller-control
this.controllerPresent = false;
this.wasControllerConnected = false;
this.lastControllerCheck = 0;
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.bindMethods();

// generic-tracked-controller-controls has the lowest precedence.
Expand Down
1 change: 0 additions & 1 deletion src/components/hp-mixed-reality-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ module.exports.Component = registerComponent('hp-mixed-reality-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self, self.data.hand); };
this.onButtonTouchStart = function (evt) { onButtonEvent(evt.detail.id, 'touchstart', self, self.data.hand); };
this.previousButtonValues = {};
this.rendererSystem = this.el.sceneEl.systems.renderer;

this.bindMethods();
},
Expand Down
6 changes: 0 additions & 6 deletions src/components/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module.exports.Component = registerComponent('light', {
var el = this.el;
this.light = null;
this.defaultTarget = null;
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.system.registerLight(el);
},

Expand All @@ -67,7 +66,6 @@ module.exports.Component = registerComponent('light', {
var data = this.data;
var diffData = diff(data, oldData);
var light = this.light;
var rendererSystem = this.rendererSystem;
var self = this;

// Existing light.
Expand All @@ -80,13 +78,11 @@ module.exports.Component = registerComponent('light', {
switch (key) {
case 'color': {
light.color.set(value);
rendererSystem.applyColorCorrection(light.color);
break;
}

case 'groundColor': {
light.groundColor.set(value);
rendererSystem.applyColorCorrection(light.groundColor);
break;
}

Expand Down Expand Up @@ -281,12 +277,10 @@ module.exports.Component = registerComponent('light', {
getLight: function (data) {
var angle = data.angle;
var color = new THREE.Color(data.color);
this.rendererSystem.applyColorCorrection(color);
color = color.getHex();
var decay = data.decay;
var distance = data.distance;
var groundColor = new THREE.Color(data.groundColor);
this.rendererSystem.applyColorCorrection(groundColor);
groundColor = groundColor.getHex();
var intensity = data.intensity;
var type = data.type;
Expand Down
3 changes: 0 additions & 3 deletions src/components/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports.Component = registerComponent('line', {
var data = this.data;
var geometry;
var material;
this.rendererSystem = this.el.sceneEl.systems.renderer;
material = this.material = new THREE.LineBasicMaterial({
color: data.color,
opacity: data.opacity,
Expand All @@ -26,7 +25,6 @@ module.exports.Component = registerComponent('line', {
geometry = this.geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(2 * 3), 3));

this.rendererSystem.applyColorCorrection(material.color);
this.line = new THREE.Line(geometry, material);
this.el.setObject3D(this.attrName, this.line);
},
Expand Down Expand Up @@ -59,7 +57,6 @@ module.exports.Component = registerComponent('line', {
}

material.color.setStyle(data.color);
this.rendererSystem.applyColorCorrection(material.color);
material.opacity = data.opacity;
material.transparent = data.opacity < 1;
material.visible = data.visible;
Expand Down
1 change: 0 additions & 1 deletion src/components/magicleap-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ module.exports.Component = registerComponent('magicleap-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); };
this.onButtonTouchStart = function (evt) { onButtonEvent(evt.detail.id, 'touchstart', self); };
this.previousButtonValues = {};
this.rendererSystem = this.el.sceneEl.systems.renderer;

this.bindMethods();
},
Expand Down
2 changes: 0 additions & 2 deletions src/components/obj-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ module.exports.Component = registerComponent('obj-model', {
self.model.traverse(function (object) {
if (object.isMesh) {
var material = object.material;
if (material.color) rendererSystem.applyColorCorrection(material.color);
if (material.map) rendererSystem.applyColorCorrection(material.map);
if (material.emissive) rendererSystem.applyColorCorrection(material.emissive);
if (material.emissiveMap) rendererSystem.applyColorCorrection(material.emissiveMap);
}
});
Expand Down
2 changes: 0 additions & 2 deletions src/components/oculus-go-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ module.exports.Component = registerComponent('oculus-go-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); };
this.controllerPresent = false;
this.lastControllerCheck = 0;
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.bindMethods();
},

Expand Down Expand Up @@ -197,6 +196,5 @@ module.exports.Component = registerComponent('oculus-go-controls', {
}
button = buttonMeshes[buttonName];
button.material.color.set(color);
this.rendererSystem.applyColorCorrection(button.material.color);
}
});
2 changes: 0 additions & 2 deletions src/components/oculus-touch-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
this.controllerPresent = false;
this.lastControllerCheck = 0;
this.previousButtonValues = {};
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.bindMethods();
this.triggerEuler = new THREE.Euler();
},
Expand Down Expand Up @@ -498,7 +497,6 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
if (buttonMeshes && buttonMeshes[buttonName]) {
button = buttonMeshes[buttonName];
button.material.color.set(color);
this.rendererSystem.applyColorCorrection(button.material.color);
}
}
});
Expand Down
1 change: 0 additions & 1 deletion src/components/valve-index-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module.exports.Component = registerComponent('valve-index-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); };
this.onButtonTouchStart = function (evt) { onButtonEvent(evt.detail.id, 'touchstart', self); };
this.previousButtonValues = {};
this.rendererSystem = this.el.sceneEl.systems.renderer;

this.bindMethods();
},
Expand Down
5 changes: 0 additions & 5 deletions src/components/vive-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ module.exports.Component = registerComponent('vive-controls', {
this.onButtonTouchEnd = function (evt) { onButtonEvent(evt.detail.id, 'touchend', self); };
this.onButtonTouchStart = function (evt) { onButtonEvent(evt.detail.id, 'touchstart', self); };
this.previousButtonValues = {};
this.rendererSystem = this.el.sceneEl.systems.renderer;

this.bindMethods();
},
Expand Down Expand Up @@ -241,19 +240,15 @@ module.exports.Component = registerComponent('vive-controls', {

setButtonColor: function (buttonName, color) {
var buttonMeshes = this.buttonMeshes;
var rendererSystem = this.rendererSystem;

if (!buttonMeshes) { return; }

// Need to do both left and right sides for grip.
if (buttonName === 'grip') {
buttonMeshes.grip.left.material.color.set(color);
buttonMeshes.grip.right.material.color.set(color);
rendererSystem.applyColorCorrection(buttonMeshes.grip.left.material.color);
rendererSystem.applyColorCorrection(buttonMeshes.grip.right.material.color);
return;
}
buttonMeshes[buttonName].material.color.set(color);
rendererSystem.applyColorCorrection(buttonMeshes[buttonName].material.color);
}
});
3 changes: 0 additions & 3 deletions src/shaders/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ module.exports.Shader = registerShader('flat', {
* Adds a reference from the scene to this entity as the camera.
*/
init: function (data) {
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.materialData = {color: new THREE.Color()};
this.textureSrc = null;
getMaterialData(data, this.materialData);
this.rendererSystem.applyColorCorrection(this.materialData.color);
this.material = new THREE.MeshBasicMaterial(this.materialData);
},

Expand All @@ -45,7 +43,6 @@ module.exports.Shader = registerShader('flat', {
updateMaterial: function (data) {
var key;
getMaterialData(data, this.materialData);
this.rendererSystem.applyColorCorrection(this.materialData.color);
for (key in this.materialData) {
this.material[key] = this.materialData[key];
}
Expand Down
3 changes: 0 additions & 3 deletions src/shaders/phong.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ module.exports.Shader = registerShader('phong', {
* Adds a reference from the scene to this entity as the camera.
*/
init: function (data) {
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.materialData = { color: new THREE.Color(), specular: new THREE.Color(), emissive: new THREE.Color() };
this.textureSrc = null;
getMaterialData(data, this.materialData);
this.rendererSystem.applyColorCorrection(this.materialData.color);
this.material = new THREE.MeshPhongMaterial(this.materialData);
utils.material.updateMap(this, data);
},
Expand All @@ -79,7 +77,6 @@ module.exports.Shader = registerShader('phong', {
updateMaterial: function (data) {
var key;
getMaterialData(data, this.materialData);
this.rendererSystem.applyColorCorrection(this.materialData.color);
for (key in this.materialData) {
this.material[key] = this.materialData[key];
}
Expand Down
1 change: 0 additions & 1 deletion src/shaders/shadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports.Shader = registerShader('shadow', {
* Adds a reference from the scene to this entity as the camera.
*/
init: function (data) {
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.material = new THREE.ShadowMaterial();
},

Expand Down
5 changes: 0 additions & 5 deletions src/shaders/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ module.exports.Shader = registerShader('standard', {
* Adds a reference from the scene to this entity as the camera.
*/
init: function (data) {
this.rendererSystem = this.el.sceneEl.systems.renderer;
this.materialData = {color: new THREE.Color(), emissive: new THREE.Color()};
getMaterialData(data, this.materialData);
this.rendererSystem.applyColorCorrection(this.materialData.color);
this.rendererSystem.applyColorCorrection(this.materialData.emissive);
this.material = new THREE.MeshStandardMaterial(this.materialData);
},

Expand All @@ -90,8 +87,6 @@ module.exports.Shader = registerShader('standard', {
var key;
var material = this.material;
getMaterialData(data, this.materialData);
this.rendererSystem.applyColorCorrection(this.materialData.color);
this.rendererSystem.applyColorCorrection(this.materialData.emissive);
for (key in this.materialData) {
material[key] = this.materialData[key];
}
Expand Down
11 changes: 5 additions & 6 deletions src/systems/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports.System = registerSystem('renderer', {

if (data.colorManagement || data.gammaOutput) {
renderer.outputEncoding = THREE.sRGBEncoding;
THREE.ColorManagement.legacyMode = false;
if (data.gammaOutput) {
warn('Property `gammaOutput` is deprecated. Use `renderer="colorManagement: true;"` instead.');
}
Expand All @@ -62,13 +63,11 @@ module.exports.System = registerSystem('renderer', {
renderer.xr.setFoveation(data.foveationLevel);
},

applyColorCorrection: function (colorOrTexture) {
if (!this.data.colorManagement || !colorOrTexture) {
applyColorCorrection: function (texture) {
if (!this.data.colorManagement || !texture) {
return;
} else if (colorOrTexture.isColor) {
colorOrTexture.convertSRGBToLinear();
} else if (colorOrTexture.isTexture) {
colorOrTexture.encoding = THREE.sRGBEncoding;
} else if (texture.isTexture) {
texture.encoding = THREE.sRGBEncoding;
}
}
});

0 comments on commit ef06aaf

Please sign in to comment.