From afe43c5f444e0672644ac0abd47ba1244d05282b Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 21 Jan 2016 14:53:47 +0100 Subject: [PATCH] Shader will now handle Glowmaps. However the load code is not there yet. --- assets | 2 +- include/Engine/Rendering/DrawFinalPass.h | 2 ++ resources/Shaders/ForwardPlus.frag.glsl | 32 ++++++++++--------- .../Rendering/DrawColorCorrectionPass.cpp | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 13 ++++++-- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/assets b/assets index 6ffb46e1..cf2ac2a5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 6ffb46e155c8f013241cd1507098c94900ec2448 +Subproject commit cf2ac2a570b0f2f50907bbbd59d00c59edb53443 diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 407ad58c..e4c714ef 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -29,6 +29,8 @@ private: void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const; Texture* m_WhiteTexture; + Texture* m_BlackTexture; + Texture* TEMP_glowTestTexture; const IRenderer* m_Renderer; const LightCullingPass* m_LightCullingPass; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index a3f998b8..421f130c 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -5,7 +5,8 @@ uniform mat4 V; uniform mat4 P; uniform vec4 Color; uniform vec2 ScreenDimensions; -uniform sampler2D texture0; +layout (binding = 0) uniform sampler2D DiffuseTexture; +layout (binding = 1) uniform sampler2D GlowMap; #define TILE_SIZE 16 @@ -100,7 +101,8 @@ LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensi void main() { - vec4 texel = texture2D(texture0, Input.TextureCoordinate); + vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); + vec4 glowTexel = texture2D(GlowMap, Input.TextureCoordinate); vec4 position = V * M * vec4(Input.Position, 1.0); vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); vec4 viewVec = normalize(-position); @@ -121,32 +123,32 @@ void main() int l = int(LightIndex[i]); LightSource light = LightSources.List[l]; - LightResult result; + LightResult light_result; //These if statements should be removed. if(light.Type == 1) { // point - result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); + light_result = CalcPointLightSource(V * light.Position, light.Radius, light.Color, light.Intensity, viewVec, position, normal, light.Falloff); } else if (light.Type == 2) { //Directional - result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); + light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); } - totalLighting.Diffuse += result.Diffuse; - totalLighting.Specular += result.Specular; + totalLighting.Diffuse += light_result.Diffuse; + totalLighting.Specular += light_result.Specular; } //sceneColor += Input.DiffuseColor; - vec4 fragment = Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; + vec4 color_result = Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * diffuseTexel * Color; //bloomColor = vec4(0.3, 0.8, 0.6, 1.0); - sceneColor = vec4(fragment.xyz, 1.0); - //These if statements should be removed. - - if(fragment.x > 1 || fragment.y > 1 || fragment.z > 1) { - bloomColor = vec4(fragment.xyz, 1.0); + sceneColor = vec4(color_result.xyz, 1.0); + //These if statements should be removed if they are slow. + color_result += glowTexel; + if(color_result.x > 1 || color_result.y > 1 || color_result.z > 1) { + bloomColor = vec4(color_result.xyz, 1.0); } else { bloomColor = vec4(0.0, 0.0, 0.0, 1.0); } - //sceneColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; + //sceneColor += Input.DiffuseColor * (totalLighting.Diffuse) * diffuseTexel * Color; //sceneColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1); - //sceneColor = texel * Input.DiffuseColor * Color; + //sceneColor = diffuseTexel * Input.DiffuseColor * Color; //sceneColor += vec4(currentTile/3600.f, 0, 0, 1); //Tiled Debug Code diff --git a/src/Engine/Rendering/DrawColorCorrectionPass.cpp b/src/Engine/Rendering/DrawColorCorrectionPass.cpp index debbcab0..72bcce2a 100644 --- a/src/Engine/Rendering/DrawColorCorrectionPass.cpp +++ b/src/Engine/Rendering/DrawColorCorrectionPass.cpp @@ -5,7 +5,7 @@ DrawColorCorrectionPass::DrawColorCorrectionPass(IRenderer* renderer) m_Renderer = renderer; m_ScreenQuad = ResourceManager::Load("Models/Core/ScreenQuad.obj"); - m_Exposure = 2; //TODO: Renderer: Fixa så att denna går att ändra på genom komponent eller setting. + m_Exposure = 1; //TODO: Renderer: Fixa så att denna går att ändra på genom komponent eller setting. InitializeShaderPrograms(); } diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 5a9f706e..a31beee6 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -12,6 +12,8 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling void DrawFinalPass::InitializeTextures() { m_WhiteTexture = ResourceManager::Load("Textures/Core/Blank.png"); + m_BlackTexture = ResourceManager::Load("Textures/Core/Black.png"); + TEMP_glowTestTexture = ResourceManager::Load("Textures/Core/UnitRaptor_glow.png"); } void DrawFinalPass::InitializeFrameBuffers() @@ -65,13 +67,20 @@ void DrawFinalPass::Draw(RenderScene& scene) glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); + glActiveTexture(GL_TEXTURE0); if(modelJob->DiffuseTexture != nullptr) { - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); } else { - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); + + /*if(modelJob->GlowMap != nullptr) { + glBindTexture(GL_TEXTURE_2D, modelJob->GlowMap->m_Texture); + } else { + glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture); + }*/ glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);