瀏覽代碼

fix: Invert mouse position for effect shader code (#519)

* fix: Invert mouse position for effect shader code

* fix: Typo in previous code
Louis 5 月之前
父節點
當前提交
e0d33010d9

+ 1 - 1
src/WallpaperEngine/Render/Objects/CParticle.cpp

@@ -259,7 +259,7 @@ void CParticle::update (float dt) {
     }
 
     // Update control points with mouse position
-    const glm::vec2* mousePos = getScene ().getMousePosition ();
+    const glm::vec2* mousePos = getScene ().getMousePositionNormalized ();
     if (mousePos) {
 
 	for (auto& cp : m_controlPoints) {

+ 10 - 2
src/WallpaperEngine/Render/Wallpapers/CScene.cpp

@@ -326,7 +326,7 @@ void CScene::updateMouse (const glm::ivec4& viewport) {
     double mouseX = glm::clamp ((position.x - viewport.x) / viewport.z, 0.0, 1.0);
     // Normalize Y coordinate (OpenGL convention: 0=bottom, 1=top)
     // Particle code expects this convention: 0=bottom results in negative Y (down), 1=top results in positive Y (up)
-    double mouseY = glm::clamp ((position.y - viewport.y) / viewport.w, 0.0, 1.0);
+    double normalizedMouseY = glm::clamp ((position.y - viewport.y) / viewport.w, 0.0, 1.0);
 
     // Account for UV cropping when using fill/fit scaling modes
     // The scene may be rendered larger than viewport and cropped via UVs
@@ -334,7 +334,13 @@ void CScene::updateMouse (const glm::ivec4& viewport) {
 
     // Map mouse position from viewport space to scene UV space
     // UVs define what portion of the scene texture is visible
-    this->m_mousePosition.x = uvs.ustart + mouseX * (uvs.uend - uvs.ustart);
+    this->m_mousePositionNormalized.x = uvs.ustart + mouseX * (uvs.uend - uvs.ustart);
+    this->m_mousePositionNormalized.y = uvs.vstart + normalizedMouseY * (uvs.vend - uvs.vstart);
+
+    // Invert previous normalization of Y to match what the shader expects
+    double mouseY = 1.0 - normalizedMouseY; 
+
+    this->m_mousePosition.x = this->m_mousePositionNormalized.x;
     this->m_mousePosition.y = uvs.vstart + mouseY * (uvs.vend - uvs.vstart);
 }
 
@@ -348,6 +354,8 @@ const glm::vec2* CScene::getMousePosition () const { return &this->m_mousePositi
 
 const glm::vec2* CScene::getMousePositionLast () const { return &this->m_mousePositionLast; }
 
+const glm::vec2* CScene::getMousePositionNormalized () const { return &this->m_mousePositionNormalized; }
+
 const glm::vec2* CScene::getParallaxDisplacement () const { return &this->m_parallaxDisplacement; }
 
 const std::vector<CObject*>& CScene::getObjectsByRenderOrder () const { return this->m_objectsByRenderOrder; }

+ 2 - 0
src/WallpaperEngine/Render/Wallpapers/CScene.h

@@ -30,6 +30,7 @@ public:
 
     const glm::vec2* getMousePosition () const;
     const glm::vec2* getMousePositionLast () const;
+    const glm::vec2* getMousePositionNormalized () const;
     const glm::vec2* getParallaxDisplacement () const;
 
     [[nodiscard]] const std::vector<CObject*>& getObjectsByRenderOrder () const;
@@ -52,6 +53,7 @@ private:
     std::vector<CObject*> m_objectsByRenderOrder = {};
     glm::vec2 m_mousePosition = {};
     glm::vec2 m_mousePositionLast = {};
+    glm::vec2 m_mousePositionNormalized = {};
     glm::vec2 m_parallaxDisplacement = {};
     std::shared_ptr<const CFBO> _rt_4FrameBuffer = nullptr;
     std::shared_ptr<const CFBO> _rt_8FrameBuffer = nullptr;