Added g_PointerPositionLast

Improved delay calculation for parallax (should prevent backgrounds from flickering with big delays)
Fixed g_TexelSize having the wrong value and g_TexelSizeHalf not being defined

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2023-02-01 18:40:38 +01:00
parent e1fe215398
commit 4dc3a4bc01
4 changed files with 21 additions and 5 deletions

View File

@ -23,6 +23,7 @@
#include "WallpaperEngine/Assets/CPackageLoadException.h"
float g_Time;
float g_TimeLast;
bool g_KeepRunning = true;
int g_AudioVolume = 15;
@ -84,7 +85,7 @@ int validatePath(const char* path, std::string& final)
char finalPath [PATH_MAX];
char* pointer = realpath (path, finalPath);
if (finalPath == nullptr)
if (pointer == nullptr)
return errno;
// ensure the path points to a folder
@ -631,6 +632,8 @@ int main (int argc, char* argv[])
glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
// set the default viewport
context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
// keep track of the previous frame's time
g_TimeLast = g_Time;
// calculate the current time value
g_Time = (float) glfwGetTime ();
// get the start time of the frame

View File

@ -6,6 +6,9 @@
#include "CScene.h"
extern float g_Time;
extern float g_TimeLast;
using namespace WallpaperEngine;
using namespace WallpaperEngine::Render;
@ -239,10 +242,9 @@ void CScene::renderFrame (glm::ivec4 viewport)
{
float influence = this->getScene ()->getCameraParallaxMouseInfluence ();
float amount = this->getScene ()->getCameraParallaxAmount ();
float delay = this->getScene ()->getCameraParallaxDelay ();
float delay = glm::min ((float) this->getScene ()->getCameraParallaxDelay (), g_Time - g_TimeLast);
this->m_parallaxDisplacement.x = glm::mix (this->m_parallaxDisplacement.x, (this->m_mousePosition.x * amount) * influence, delay);
this->m_parallaxDisplacement.y = glm::mix (this->m_parallaxDisplacement.y, (this->m_mousePosition.y * amount) * influence, delay);
this->m_parallaxDisplacement = glm::mix (this->m_parallaxDisplacement, (this->m_mousePosition * amount) * influence, delay);
}
// use the scene's framebuffer by default
@ -262,6 +264,10 @@ void CScene::updateMouse (glm::ivec4 viewport)
CMouseInput* mouse = this->getContext ()->getMouse ();
// TODO: PROPERLY TRANSLATE THESE TO WHAT'S VISIBLE ON SCREEN (FOR BACKGROUNDS THAT DO NOT EXACTLY FIT ON SCREEN)
// rollover the position to the last
this->m_mousePositionLast = this->m_mousePosition;
// calculate the current position of the mouse
this->m_mousePosition.x = glm::clamp ((mouse->position.x - viewport.x) / viewport.z, 0.0, 1.0);
this->m_mousePosition.y = glm::clamp ((mouse->position.y - viewport.y) / viewport.w, 0.0, 1.0);
@ -278,6 +284,10 @@ glm::vec2* CScene::getMousePosition ()
return &this->m_mousePosition;
}
glm::vec2* CScene::getMousePositionLast ()
{
return &this->m_mousePositionLast;
}
glm::vec2* CScene::getParallaxDisplacement ()
{

View File

@ -22,6 +22,7 @@ namespace WallpaperEngine::Render
Core::CScene* getScene ();
glm::vec2* getMousePosition ();
glm::vec2* getMousePositionLast ();
glm::vec2* getParallaxDisplacement ();
protected:
@ -40,6 +41,7 @@ namespace WallpaperEngine::Render
std::map<int, CObject*> m_objects;
std::vector<CObject*> m_objectsByRenderOrder;
glm::vec2 m_mousePosition;
glm::vec2 m_mousePositionLast;
glm::vec2 m_parallaxDisplacement;
CFBO* _rt_4FrameBuffer;
CFBO* _rt_8FrameBuffer;

View File

@ -628,10 +628,11 @@ void CPass::setupUniforms ()
// add model-view-projection matrix
this->addUniform ("g_ModelViewProjectionMatrix", &this->m_modelViewProjectionMatrix);
this->addUniform ("g_PointerPosition", this->m_material->getImage ()->getScene ()->getMousePosition ());
this->addUniform ("g_PointerPositionLast", this->m_material->getImage ()->getScene ()->getMousePositionLast ());
this->addUniform ("g_EffectTextureProjectionMatrix", glm::mat4(1.0));
this->addUniform ("g_EffectTextureProjectionMatrixInverse", glm::mat4(1.0));
this->addUniform ("g_TexelSize", glm::vec2 (1.0 / projection->getWidth (), 1.0 / projection->getHeight ()));
this->addUniform ("g_TexelSize", glm::vec2 (0.5 / projection->getWidth (), 0.5 / projection->getHeight ()));
this->addUniform ("g_TexelSizeHalf", glm::vec2 (0.5 / projection->getWidth (), 0.5 / projection->getHeight ()));
}
void CPass::addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value)