Bläddra i källkod

Merge remote-tracking branch 'upstream/main'

vaxerski 3 år sedan
förälder
incheckning
1f6cc8206f

+ 9 - 1
src/WallpaperEngine/Application/CWallpaperApplication.cpp

@@ -13,6 +13,7 @@
 
 float g_Time;
 float g_TimeLast;
+float g_Daytime;
 
 namespace WallpaperEngine::Application
 {
@@ -349,7 +350,14 @@ namespace WallpaperEngine::Application
 
     void CWallpaperApplication::renderFrame() {
 
-        float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS;
+        static float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS;
+        static time_t seconds;
+        static struct tm* timeinfo;
+
+        // update g_Daytime
+        time (&seconds);
+        timeinfo = localtime(&seconds);
+        g_Daytime = ((timeinfo->tm_hour * 60) + timeinfo->tm_min) / (24.0 * 60.0);
 
         // update audio recorder
         audioDriver->update ();

+ 5 - 0
src/WallpaperEngine/Render/Objects/CImage.cpp

@@ -263,6 +263,8 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) :
             this->getScene ()->getCamera ()->getLookAt ();
 
     this->m_modelViewProjectionCopy = glm::ortho <float> (0.0, size.x, 0.0, size.y);
+    this->m_modelMatrix = glm::ortho <float> (0.0, size.x, 0.0, size.y);
+    this->m_viewProjectionMatrix = glm::mat4 (1.0);
 }
 
 void CImage::setup ()
@@ -363,6 +365,9 @@ void CImage::setupPasses ()
         glm::mat4* projection = (first) ? &this->m_modelViewProjectionCopy : &this->m_modelViewProjectionPass;
         first = false;
 
+        pass->setModelMatrix (&this->m_modelMatrix);
+        pass->setViewProjectionMatrix (&this->m_viewProjectionMatrix);
+
         // set viewport and target texture if needed
         if (pass->getMaterial ()->getMaterial ()->hasTarget ())
         {

+ 3 - 0
src/WallpaperEngine/Render/Objects/CImage.h

@@ -74,6 +74,9 @@ namespace WallpaperEngine::Render::Objects
         glm::mat4 m_modelViewProjectionPass;
         glm::mat4 m_modelViewProjectionCopy;
 
+        glm::mat4 m_modelMatrix;
+        glm::mat4 m_viewProjectionMatrix;
+
         CFBO* m_mainFBO;
         CFBO* m_subFBO;
         CFBO* m_currentMainFBO;

+ 35 - 1
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp

@@ -21,6 +21,7 @@ using namespace WallpaperEngine::Render::Shaders::Variables;
 using namespace WallpaperEngine::Render::Objects::Effects;
 
 extern float g_Time;
+extern float g_Daytime;
 
 CPass::CPass (CMaterial* material, Core::Objects::Images::Materials::CPass* pass) :
     Helpers::CContextAware (material),
@@ -201,6 +202,9 @@ void CPass::render ()
             case Matrix4:
                 glUniformMatrix4fv (entry->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat4*> (entry->value)));
                 break;
+            case Matrix3:
+                glUniformMatrix3fv (entry->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat3*> (entry->value)));
+                break;
         }
     }
     // add reference uniforms
@@ -231,6 +235,9 @@ void CPass::render ()
             case Matrix4:
                 glUniformMatrix4fv (entry->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat4*> (*entry->value)));
                 break;
+            case Matrix3:
+                glUniformMatrix3fv (entry->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat3*> (*entry->value)));
+                break;
         }
     }
 
@@ -301,11 +308,16 @@ void CPass::setModelViewProjectionMatrix (const glm::mat4* projection)
     this->m_modelViewProjectionMatrix = projection;
 }
 
-void CPass::setModelMatrix (glm::mat4 model)
+void CPass::setModelMatrix (const glm::mat4* model)
 {
     this->m_modelMatrix = model;
 }
 
+void CPass::setViewProjectionMatrix (const glm::mat4* viewProjection)
+{
+    this->m_viewProjectionMatrix = viewProjection;
+}
+
 void CPass::setTexCoord (GLuint texcoord)
 {
     this->a_TexCoord = texcoord;
@@ -579,6 +591,9 @@ void CPass::setupUniforms ()
 
     auto projection = this->getMaterial ()->getImage ()->getScene ()->getScene ()->getOrthogonalProjection ();
 
+    // lighting variables
+    this->addUniform ("g_LightAmbientColor", this->m_material->getImage ()->getScene ()->getScene ()->getAmbientColor ());
+    this->addUniform ("g_LightSkylightColor", this->m_material->getImage ()->getScene ()->getScene ()->getSkylightColor ());
     // register variables like brightness and alpha with some default value
     this->addUniform ("g_Brightness", this->m_material->getImage ()->getImage ()->getBrightness ());
     this->addUniform ("g_UserAlpha", this->m_material->getImage ()->getImage ()->getAlpha ());
@@ -588,8 +603,12 @@ void CPass::setupUniforms ()
     this->addUniform ("g_CompositeColor", this->m_material->getImage ()->getImage ()->getColor ());
     // add some external variables
     this->addUniform ("g_Time", &g_Time);
+    this->addUniform ("g_Daytime", &g_Daytime);
     // add model-view-projection matrix
     this->addUniform ("g_ModelViewProjectionMatrix", &this->m_modelViewProjectionMatrix);
+    this->addUniform ("g_ModelMatrix", &this->m_modelMatrix);
+    this->addUniform ("g_NormalModelMatrix", glm::identity <glm::mat3> ());
+    this->addUniform ("g_ViewProjectionMatrix", &this->m_viewProjectionMatrix);
     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));
@@ -899,6 +918,21 @@ void CPass::addUniform (const std::string& name, const glm::vec4** value)
     this->addUniform (name, UniformType::Vector4, value);
 }
 
+void CPass::addUniform (const std::string& name, glm::mat3 value)
+{
+    this->addUniform (name, UniformType::Matrix3, value);
+}
+
+void CPass::addUniform (const std::string& name, const glm::mat3* value)
+{
+    this->addUniform (name, UniformType::Matrix3, value, 1);
+}
+
+void CPass::addUniform (const std::string& name, const glm::mat3** value)
+{
+    this->addUniform (name, UniformType::Matrix3, value);
+}
+
 void CPass::addUniform (const std::string& name, glm::mat4 value)
 {
     this->addUniform (name, UniformType::Matrix4, value);

+ 14 - 8
src/WallpaperEngine/Render/Objects/Effects/CPass.h

@@ -32,7 +32,8 @@ namespace WallpaperEngine::Render::Objects::Effects
         void setTexCoord (GLuint texcoord);
         void setPosition (GLuint position);
         void setModelViewProjectionMatrix (const glm::mat4* projection);
-        void setModelMatrix (glm::mat4 model);
+        void setModelMatrix (const glm::mat4* model);
+        void setViewProjectionMatrix (const glm::mat4* viewProjection);
 
         const CMaterial* getMaterial () const;
         Core::Objects::Images::Materials::CPass* getPass ();
@@ -41,12 +42,13 @@ namespace WallpaperEngine::Render::Objects::Effects
         enum UniformType
         {
             Float = 0,
-            Matrix4 = 1,
-            Integer = 2,
-            Vector2 = 3,
-            Vector3 = 4,
-            Vector4 = 5,
-            Double = 6
+            Matrix3 = 1,
+            Matrix4 = 2,
+            Integer = 3,
+            Vector2 = 4,
+            Vector3 = 5,
+            Vector4 = 6,
+            Double = 7
         };
 
         class UniformEntry
@@ -102,6 +104,7 @@ namespace WallpaperEngine::Render::Objects::Effects
         void addUniform (const std::string& name, glm::vec2 value);
         void addUniform (const std::string& name, glm::vec3 value);
         void addUniform (const std::string& name, glm::vec4 value);
+        void addUniform (const std::string& name, glm::mat3 value);
         void addUniform (const std::string& name, glm::mat4 value);
         void addUniform (const std::string& name, const int* value, int count = 1);
         void addUniform (const std::string& name, const double* value, int count = 1);
@@ -109,6 +112,7 @@ namespace WallpaperEngine::Render::Objects::Effects
         void addUniform (const std::string& name, const glm::vec2* value);
         void addUniform (const std::string& name, const glm::vec3* value);
         void addUniform (const std::string& name, const glm::vec4* value);
+        void addUniform (const std::string& name, const glm::mat3* value);
         void addUniform (const std::string& name, const glm::mat4* value);
         void addUniform (const std::string& name, const int** value);
         void addUniform (const std::string& name, const double** value);
@@ -116,6 +120,7 @@ namespace WallpaperEngine::Render::Objects::Effects
         void addUniform (const std::string& name, const glm::vec2** value);
         void addUniform (const std::string& name, const glm::vec3** value);
         void addUniform (const std::string& name, const glm::vec4** value);
+        void addUniform (const std::string& name, const glm::mat3** value);
         void addUniform (const std::string& name, const glm::mat4** value);
         template <typename T> void addUniform (const std::string& name, UniformType type, T value);
         template <typename T> void addUniform (const std::string& name, UniformType type, T* value, int count = 1);
@@ -132,7 +137,8 @@ namespace WallpaperEngine::Render::Objects::Effects
         std::map<std::string, UniformEntry*> m_uniforms;
         std::map<std::string, ReferenceUniformEntry*> m_referenceUniforms;
         const glm::mat4* m_modelViewProjectionMatrix;
-        glm::mat4 m_modelMatrix;
+        const glm::mat4* m_modelMatrix;
+        const glm::mat4* m_viewProjectionMatrix;
 
         /**
          * Contains the final map of textures to be used