From 8577e38f27085c2e50aff35938f8bd10d0bb5659 Mon Sep 17 00:00:00 2001 From: Federico Sosa Date: Sun, 22 Jun 2025 10:39:18 +0200 Subject: [PATCH] fix lights position when setting camera rotation --- src/renderer/webgl/pipelines/LightPipeline.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/renderer/webgl/pipelines/LightPipeline.js b/src/renderer/webgl/pipelines/LightPipeline.js index 6bd6dd141d..707a807547 100644 --- a/src/renderer/webgl/pipelines/LightPipeline.js +++ b/src/renderer/webgl/pipelines/LightPipeline.js @@ -197,9 +197,18 @@ var LightPipeline = new Class({ var lightName = 'uLights[' + i + '].'; - cameraMatrix.transformPoint(light.x, light.y, tempVec2); - - this.set2f(lightName + 'position', tempVec2.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (tempVec2.y - (camera.scrollY * light.scrollFactorY) * camera.zoom)); + if (camera.rotation !== 0) + { + // When camera is rotated, apply scroll before matrix transformation to avoid double-transformation + cameraMatrix.transformPoint(light.x - (camera.scrollX * light.scrollFactorX), light.y - (camera.scrollY * light.scrollFactorY), tempVec2); + this.set2f(lightName + 'position', tempVec2.x, height - tempVec2.y); + } + else + { + // When camera is not rotated, use original calculation (matrix transform then manual scroll/zoom) + cameraMatrix.transformPoint(light.x, light.y, tempVec2); + this.set2f(lightName + 'position', tempVec2.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (tempVec2.y - (camera.scrollY * light.scrollFactorY) * camera.zoom)); + } this.set3f(lightName + 'color', color.r, color.g, color.b); this.set1f(lightName + 'intensity', light.intensity); this.set1f(lightName + 'radius', light.radius);