diff --git a/include/Engine/Rendering/DrawColorCorrectionPass.h b/include/Engine/Rendering/DrawColorCorrectionPass.h index f507b53c..fcde73d7 100644 --- a/include/Engine/Rendering/DrawColorCorrectionPass.h +++ b/include/Engine/Rendering/DrawColorCorrectionPass.h @@ -17,15 +17,13 @@ public: void InitializeFrameBuffers(); void InitializeShaderPrograms(); - void Draw(GLuint sceneTexture, GLuint bloomTexture); + void Draw(GLuint sceneTexture, GLuint bloomTexture, GLfloat gamma, GLfloat exposure); private: const IRenderer* m_Renderer; ShaderProgram* m_ColorCorrectionProgram; Model* m_ScreenQuad; - GLfloat m_Exposure = 1; - GLfloat m_Gamma = 2.2; }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 57371146..af9d928e 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -26,6 +26,7 @@ struct RenderScene std::list> DirectionalLightJobs; Rectangle Viewport; bool ClearDepth = false; + glm::vec4 AmbientColor; void Clear() { @@ -40,6 +41,9 @@ struct RenderScene struct RenderFrame { public: + //TODO: Getters + GLfloat Gamma = 2.2f; + GLfloat Exposure = 1.f; void Add(RenderScene &scene) { diff --git a/resources/Schema/Entities/EditorTestWorld.xml b/resources/Schema/Entities/EditorTestWorld.xml index b7baea28..de65f736 100755 --- a/resources/Schema/Entities/EditorTestWorld.xml +++ b/resources/Schema/Entities/EditorTestWorld.xml @@ -18,7 +18,7 @@ - + @@ -43,7 +43,7 @@ - + @@ -85,7 +85,7 @@ Run - + 1 @@ -101,7 +101,7 @@ Walk - + 1 @@ -163,7 +163,7 @@ - + @@ -227,7 +227,7 @@ - + @@ -259,7 +259,7 @@ - + @@ -299,6 +299,13 @@ + + + + + + + diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 16dca034..d9a2f7d5 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -7,6 +7,7 @@ uniform vec4 Color; uniform vec4 DiffuseColor; uniform vec2 ScreenDimensions; uniform vec4 FillColor; +uniform vec4 AmbientColor; uniform float FillPercentage; layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 1) uniform sampler2D NormalMapTexture; @@ -60,8 +61,6 @@ in VertexData{ out vec4 sceneColor; out vec4 bloomColor; -vec4 scene_ambient = vec4(0.3,0.3,0.3,1); - struct LightResult { vec4 Diffuse; vec4 Specular; @@ -128,7 +127,7 @@ void main() tilePos.y = int(gl_FragCoord.y/TILE_SIZE); LightResult totalLighting; - totalLighting.Diffuse = scene_ambient; + totalLighting.Diffuse = AmbientColor; int currentTile = int(floor(gl_FragCoord.x/TILE_SIZE) + (floor(gl_FragCoord.y/TILE_SIZE) * int(ScreenDimensions.x/TILE_SIZE))); int start = int(LightGrids.Data[currentTile].Start); diff --git a/src/Engine/Rendering/DrawColorCorrectionPass.cpp b/src/Engine/Rendering/DrawColorCorrectionPass.cpp index 9b9e2236..95de26e2 100644 --- a/src/Engine/Rendering/DrawColorCorrectionPass.cpp +++ b/src/Engine/Rendering/DrawColorCorrectionPass.cpp @@ -20,7 +20,7 @@ void DrawColorCorrectionPass::InitializeShaderPrograms() m_ColorCorrectionProgram->Link(); } -void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture) +void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture, GLfloat gamma, GLfloat exposure) { //glBindFramebuffer(GL_FRAMEBUFFER, 0); GLERROR("DrawScreenQuadPass::Draw: Pre"); @@ -28,8 +28,8 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture) DrawScreenQuadPassState state = DrawScreenQuadPassState(); m_ColorCorrectionProgram->Bind(); glClear(GL_COLOR_BUFFER_BIT); - glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Exposure"), m_Exposure); - glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Gamma"), m_Gamma); + glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Exposure"), exposure); + glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Gamma"), gamma); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, sceneTexture); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 48ea4144..89538c9a 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -141,18 +141,22 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glBindVertexArray(explosionEffectJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer); glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int))); + GLERROR("DrawFinalPass::Model: 1"); } else { auto modelJob = std::dynamic_pointer_cast(job); if (modelJob) { //bind forward program m_ForwardPlusProgram->Bind(); + GLERROR("DrawFinalPass::Model: 2"); //bind uniforms BindModelUniforms(forwardHandle, modelJob, scene); + GLERROR("DrawFinalPass::Model: 3"); //bind textures BindModelTextures(modelJob); + GLERROR("DrawFinalPass::Model: 4"); if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) { @@ -161,6 +165,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); } } + GLERROR("DrawFinalPass::Model: 5"); //draw glBindVertexArray(modelJob->Model->VAO); @@ -175,6 +180,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list>& void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) { + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, GL_FALSE, glm::value_ptr(scene.AmbientColor)); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); @@ -196,8 +202,10 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr& job, RenderScene& scene) { + glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor)); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix)); @@ -205,6 +213,7 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrDiffuseColor)); glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(job->FillColor)); glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage); + } diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 98373a61..b51ab7f8 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -240,20 +240,17 @@ void RenderSystem::Update(double dt) m_Camera->SetOrientation(Transform::AbsoluteOrientation(m_CurrentCamera)); } - RenderScene scene; scene.Camera = m_Camera; scene.Viewport = Rectangle(1280, 720); - //auto cSceneLight = m_Renderer->m_World->GetComponents("SceneLight"); - //if (cSceneLight != nullptr) { - // m_Gamma = (double)(*cSceneLight->begin())["Gamma"]; - // m_Exposure = (double)(*cSceneLight->begin())["Exposure"]; - //} + auto cSceneLight = m_World->GetComponents("SceneLight"); + if (cSceneLight != nullptr) { + m_RenderFrame->Gamma = (double)(*cSceneLight->begin())["Gamma"]; + m_RenderFrame->Exposure = (double)(*cSceneLight->begin())["Exposure"]; + scene.AmbientColor = (glm::vec4)(*cSceneLight->begin())["AmbientColor"]; + } - //scene.ambient - //scene.gamma - //scene.exponent fillModels(scene.OpaqueObjects, scene.TransparentObjects); fillPointLights(scene.PointLightJobs, m_World); fillDirectionalLights(scene.DirectionalLightJobs, m_World); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 55cd8b03..0ec593df 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -120,8 +120,8 @@ void Renderer::Draw(RenderFrame& frame) } m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture()); - if(m_DebugTextureToDraw == 0) { - m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture()); + if (m_DebugTextureToDraw == 0) { + m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), frame.Gamma, frame.Exposure); } if (m_DebugTextureToDraw == 1) { m_DrawScreenQuadPass->Draw(m_DrawFinalPass->SceneTexture());