From 50160e438c3eda574622922b2691d20631ceb2ed Mon Sep 17 00:00:00 2001 From: Swastik Tripathi Date: Sat, 21 Nov 2026 08:55:28 +0530 Subject: [PATCH 1/2] Fix angle getters that lost the sign of negative angles --- src/effects/DotScreenEffect.js | 3 ++- src/effects/HueSaturationEffect.js | 4 +++- src/effects/TiltShiftEffect.js | 3 ++- src/materials/TiltShiftBlurMaterial.js | 3 ++- test/effects/DotScreenEffect.js | 15 +++++++++++++++ test/effects/HueSaturationEffect.js | 15 +++++++++++++++ test/effects/TiltShiftEffect.js | 15 +++++++++++++++ test/materials/TiltShiftBlurMaterial.js | 15 +++++++++++++++ 8 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/effects/DotScreenEffect.js b/src/effects/DotScreenEffect.js index 703ef200c..a4004ddc3 100644 --- a/src/effects/DotScreenEffect.js +++ b/src/effects/DotScreenEffect.js @@ -40,7 +40,8 @@ export class DotScreenEffect extends Effect { get angle() { - return Math.acos(this.uniforms.get("angle").value.y); + const angle = this.uniforms.get("angle").value; + return Math.atan2(angle.x, angle.y); } diff --git a/src/effects/HueSaturationEffect.js b/src/effects/HueSaturationEffect.js index b0954f993..4c84ee55d 100644 --- a/src/effects/HueSaturationEffect.js +++ b/src/effects/HueSaturationEffect.js @@ -88,7 +88,9 @@ export class HueSaturationEffect extends Effect { get hue() { const hue = this.uniforms.get("hue").value; - return Math.acos((hue.x * 3.0 - 1.0) / 2.0); + const c = (hue.x * 3.0 - 1.0) / 2.0; + const s = (hue.z - hue.y) * Math.sqrt(3.0) / 2.0; + return Math.atan2(s, c); } diff --git a/src/effects/TiltShiftEffect.js b/src/effects/TiltShiftEffect.js index 748babd35..33806b936 100644 --- a/src/effects/TiltShiftEffect.js +++ b/src/effects/TiltShiftEffect.js @@ -141,7 +141,8 @@ export class TiltShiftEffect extends Effect { get rotation() { - return Math.acos(this.uniforms.get("rotation").value.x); + const rotation = this.uniforms.get("rotation").value; + return Math.atan2(rotation.y, rotation.x); } diff --git a/src/materials/TiltShiftBlurMaterial.js b/src/materials/TiltShiftBlurMaterial.js index c4acbe120..17af27bbf 100644 --- a/src/materials/TiltShiftBlurMaterial.js +++ b/src/materials/TiltShiftBlurMaterial.js @@ -95,7 +95,8 @@ export class TiltShiftBlurMaterial extends KawaseBlurMaterial { get rotation() { - return Math.acos(this.uniforms.rotation.value.x); + const rotation = this.uniforms.rotation.value; + return Math.atan2(rotation.y, rotation.x); } diff --git a/test/effects/DotScreenEffect.js b/test/effects/DotScreenEffect.js index d1a824e6a..c2856726d 100644 --- a/test/effects/DotScreenEffect.js +++ b/test/effects/DotScreenEffect.js @@ -9,3 +9,18 @@ test("can be created and destroyed", t => { t.pass(); }); + +test("returns the angle it was set to, including negative angles", t => { + + const object = new DotScreenEffect(); + + for(const value of [-2.5, -0.5, 0, 0.5, 2.5]) { + + object.angle = value; + t.true(Math.abs(object.angle - value) < 1e-6, `set ${value}, got ${object.angle}`); + + } + + object.dispose(); + +}); diff --git a/test/effects/HueSaturationEffect.js b/test/effects/HueSaturationEffect.js index cb37fb98f..a4ffb81f5 100644 --- a/test/effects/HueSaturationEffect.js +++ b/test/effects/HueSaturationEffect.js @@ -9,3 +9,18 @@ test("can be created and destroyed", t => { t.pass(); }); + +test("returns the hue it was set to, including negative angles", t => { + + const object = new HueSaturationEffect(); + + for(const value of [-2.5, -0.5, 0, 0.5, 2.5]) { + + object.hue = value; + t.true(Math.abs(object.hue - value) < 1e-6, `set ${value}, got ${object.hue}`); + + } + + object.dispose(); + +}); diff --git a/test/effects/TiltShiftEffect.js b/test/effects/TiltShiftEffect.js index 12ce62e34..7fe58c36c 100644 --- a/test/effects/TiltShiftEffect.js +++ b/test/effects/TiltShiftEffect.js @@ -9,3 +9,18 @@ test("can be created and destroyed", t => { t.pass(); }); + +test("returns the rotation it was set to, including negative angles", t => { + + const object = new TiltShiftEffect(); + + for(const value of [-2.5, -0.5, 0, 0.5, 2.5]) { + + object.rotation = value; + t.true(Math.abs(object.rotation - value) < 1e-6, `set ${value}, got ${object.rotation}`); + + } + + object.dispose(); + +}); diff --git a/test/materials/TiltShiftBlurMaterial.js b/test/materials/TiltShiftBlurMaterial.js index 27d2e8bb4..f7daa5eda 100644 --- a/test/materials/TiltShiftBlurMaterial.js +++ b/test/materials/TiltShiftBlurMaterial.js @@ -6,3 +6,18 @@ test("can be created", t => { t.truthy(new TiltShiftBlurMaterial()); }); + +test("returns the rotation it was set to, including negative angles", t => { + + const object = new TiltShiftBlurMaterial(); + + for(const value of [-2.5, -0.5, 0, 0.5, 2.5]) { + + object.rotation = value; + t.true(Math.abs(object.rotation - value) < 1e-6, `set ${value}, got ${object.rotation}`); + + } + + object.dispose(); + +}); From 4f1e396546e3ba043235ae63ca8f1b9d10e17d66 Mon Sep 17 00:00:00 2001 From: Swastik Tripathi Date: Sun, 22 Nov 2026 20:14:39 +0530 Subject: [PATCH 2/2] Use private fields for angle/rotation/hue getters --- src/effects/DotScreenEffect.js | 4 ++-- src/effects/HueSaturationEffect.js | 6 ++---- src/effects/TiltShiftEffect.js | 4 ++-- src/materials/TiltShiftBlurMaterial.js | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/effects/DotScreenEffect.js b/src/effects/DotScreenEffect.js index a4004ddc3..7dbc8b3ca 100644 --- a/src/effects/DotScreenEffect.js +++ b/src/effects/DotScreenEffect.js @@ -40,14 +40,14 @@ export class DotScreenEffect extends Effect { get angle() { - const angle = this.uniforms.get("angle").value; - return Math.atan2(angle.x, angle.y); + return this._angle; } set angle(value) { this.uniforms.get("angle").value.set(Math.sin(value), Math.cos(value)); + this._angle = value; } diff --git a/src/effects/HueSaturationEffect.js b/src/effects/HueSaturationEffect.js index 4c84ee55d..09fd1b24f 100644 --- a/src/effects/HueSaturationEffect.js +++ b/src/effects/HueSaturationEffect.js @@ -87,10 +87,7 @@ export class HueSaturationEffect extends Effect { get hue() { - const hue = this.uniforms.get("hue").value; - const c = (hue.x * 3.0 - 1.0) / 2.0; - const s = (hue.z - hue.y) * Math.sqrt(3.0) / 2.0; - return Math.atan2(s, c); + return this._hue; } @@ -103,6 +100,7 @@ export class HueSaturationEffect extends Effect { (-Math.sqrt(3.0) * s - c + 1.0) / 3.0, (Math.sqrt(3.0) * s - c + 1.0) / 3.0 ); + this._hue = value; } diff --git a/src/effects/TiltShiftEffect.js b/src/effects/TiltShiftEffect.js index 33806b936..03f58ef9b 100644 --- a/src/effects/TiltShiftEffect.js +++ b/src/effects/TiltShiftEffect.js @@ -141,8 +141,7 @@ export class TiltShiftEffect extends Effect { get rotation() { - const rotation = this.uniforms.get("rotation").value; - return Math.atan2(rotation.y, rotation.x); + return this._rotation; } @@ -150,6 +149,7 @@ export class TiltShiftEffect extends Effect { this.uniforms.get("rotation").value.set(Math.cos(value), Math.sin(value)); this.blurPass.blurMaterial.rotation = value; + this._rotation = value; } diff --git a/src/materials/TiltShiftBlurMaterial.js b/src/materials/TiltShiftBlurMaterial.js index 17af27bbf..6d772dd20 100644 --- a/src/materials/TiltShiftBlurMaterial.js +++ b/src/materials/TiltShiftBlurMaterial.js @@ -95,14 +95,14 @@ export class TiltShiftBlurMaterial extends KawaseBlurMaterial { get rotation() { - const rotation = this.uniforms.rotation.value; - return Math.atan2(rotation.y, rotation.x); + return this._rotation; } set rotation(value) { this.uniforms.rotation.value.set(Math.cos(value), Math.sin(value)); + this._rotation = value; }