diff --git a/resources/Shaders/FillDepthBuffer.vert.glsl b/resources/Shaders/FillDepthBuffer.vert.glsl index ff849790..e8f6838d 100644 --- a/resources/Shaders/FillDepthBuffer.vert.glsl +++ b/resources/Shaders/FillDepthBuffer.vert.glsl @@ -1,8 +1,6 @@ #version 430 -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; +uniform mat4 PVM; layout(location = 0) in vec3 Position; layout(location = 5) in vec4 BoneIndices; @@ -15,7 +13,7 @@ out VertexData{ void main() { - gl_Position = P * V * M * vec4(Position, 1.0); + gl_Position = PVM * vec4(Position, 1.0); Output.Position = Position; } \ No newline at end of file diff --git a/resources/Shaders/FillDepthBufferSkinned.vert.glsl b/resources/Shaders/FillDepthBufferSkinned.vert.glsl index ce2a142d..a1ad5c14 100644 --- a/resources/Shaders/FillDepthBufferSkinned.vert.glsl +++ b/resources/Shaders/FillDepthBufferSkinned.vert.glsl @@ -1,8 +1,6 @@ #version 430 -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; +uniform mat4 PVM; uniform mat4 Bones[100]; @@ -27,7 +25,7 @@ void main() + BoneWeights[3] * Bones[int(BoneIndices[3])]; } - gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); + gl_Position = PVM*boneTransform * vec4(Position, 1.0); Output.Position = vec3(0.0); } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 8f0f7deb..9de1026d 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -2,6 +2,7 @@ #define MIN_AMBIENT_LIGHT 0.3 +uniform mat4 VM; uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -11,7 +12,7 @@ uniform vec2 ScreenDimensions; uniform vec4 FillColor; uniform vec4 AmbientColor; uniform float FillPercentage; -uniform float GlowIntensity = 10; +uniform float GlowIntensity; uniform vec3 CameraPosition; uniform int SSAOQuality; @@ -131,7 +132,7 @@ void main() vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat); vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat); vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat); - vec4 position = V * M * vec4(Input.Position, 1.0); + vec4 position = VM * vec4(Input.Position, 1.0); vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture); normal = normalize(normal); //vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 26686222..ce251c00 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -1,5 +1,6 @@ #version 430 - +uniform mat4 PVM; +uniform mat4 TIM; uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -22,8 +23,8 @@ out VertexData{ void main() { - gl_Position = P*V*M * vec4(Position, 1.0); - mat4 TIM = transpose(inverse(M)); + gl_Position = PVM * vec4(Position, 1.0); + //mat4 TIM = transpose(inverse(M)); Output.Position = Position; Output.TextureCoordinate = TextureCoords; Output.Normal = vec3(TIM * vec4(Normal, 0.0)); diff --git a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl index 5995facb..6fcbf881 100644 --- a/resources/Shaders/ForwardPlusShieldCheck.frag.glsl +++ b/resources/Shaders/ForwardPlusShieldCheck.frag.glsl @@ -2,6 +2,7 @@ #define MIN_AMBIENT_LIGHT 0.3 +uniform mat4 VM; uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -11,7 +12,7 @@ uniform vec2 ScreenDimensions; uniform vec4 FillColor; uniform vec4 AmbientColor; uniform float FillPercentage; -uniform float GlowIntensity = 10; +uniform float GlowIntensity; uniform vec3 CameraPosition; uniform int SSAOQuality; @@ -138,7 +139,7 @@ void main() vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate * DiffuseUVRepeat); vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat); vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat); - vec4 position = V * M * vec4(Input.Position, 1.0); + vec4 position = VM * vec4(Input.Position, 1.0); vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture); normal = normalize(normal); //vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); diff --git a/resources/Shaders/ForwardPlusSkinned.vert.glsl b/resources/Shaders/ForwardPlusSkinned.vert.glsl index 5fd55a8c..0d959caa 100644 --- a/resources/Shaders/ForwardPlusSkinned.vert.glsl +++ b/resources/Shaders/ForwardPlusSkinned.vert.glsl @@ -1,5 +1,7 @@ #version 430 +uniform mat4 PVM; +uniform mat4 TIM; uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -34,7 +36,7 @@ void main() + BoneWeights[3] * Bones[int(BoneIndices[3])]; } - gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); + gl_Position = PVM*boneTransform * vec4(Position, 1.0); Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; Output.TextureCoordinate = TextureCoords; diff --git a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl index c67a9c99..e0c73e70 100644 --- a/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMapRGB.frag.glsl @@ -2,6 +2,7 @@ #define MIN_AMBIENT_LIGHT 0.3 +uniform mat4 VM; uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -189,7 +190,7 @@ void main() GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3); vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3, SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3); - vec4 position = V * M * vec4(Input.Position, 1.0); + vec4 position = VM * vec4(Input.Position, 1.0); //vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture); vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3, NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3); diff --git a/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl b/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl index d61726fe..a26d85f5 100644 --- a/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl +++ b/resources/Shaders/ForwardPlusSplatMapRGBShieldCheck.frag.glsl @@ -2,6 +2,7 @@ #define MIN_AMBIENT_LIGHT 0.3 +uniform mat4 VM; uniform mat4 M; uniform mat4 V; uniform mat4 P; @@ -190,7 +191,7 @@ void main() GlowUVRepeat1, GlowUVRepeat2, GlowUVRepeat3); vec4 specularTexel = CalcBlendedTexel(splatTexel, SpecularMapTexture1, SpecularMapTexture2, SpecularMapTexture3, SpecularUVRepeat1, SpecularUVRepeat2, SpecularUVRepeat3); - vec4 position = V * M * vec4(Input.Position, 1.0); + vec4 position = VM * vec4(Input.Position, 1.0); //vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture); vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3, NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3); diff --git a/resources/Shaders/Picking.vert.glsl b/resources/Shaders/Picking.vert.glsl index f888cd16..a10121cf 100644 --- a/resources/Shaders/Picking.vert.glsl +++ b/resources/Shaders/Picking.vert.glsl @@ -1,8 +1,6 @@ #version 430 - -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; +#include "StandarUniform.glsl" +layout(location = PVM_UNIFORM_LOCATION) uniform mat4 PVM; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -16,6 +14,6 @@ out VertexData{ void main() { - gl_Position = P*V*M * vec4(Position, 1.0); + gl_Position = PVM * vec4(Position, 1.0); Output.Position = Position, 1.0; } \ No newline at end of file diff --git a/resources/Shaders/PickingSkinned.vert.glsl b/resources/Shaders/PickingSkinned.vert.glsl index 205a8fdd..98a5b394 100644 --- a/resources/Shaders/PickingSkinned.vert.glsl +++ b/resources/Shaders/PickingSkinned.vert.glsl @@ -1,8 +1,6 @@ #version 430 - -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; +#include "StandarUniform.glsl" +layout(location = PVM_UNIFORM_LOCATION) uniform mat4 PVM; uniform mat4 Bones[100]; layout(location = 0) in vec3 Position; @@ -27,6 +25,6 @@ void main() + BoneWeights[3] * Bones[int(BoneIndices[3])]; } - gl_Position = P*V*M*boneTransform * vec4(Position, 1.0); + gl_Position = PVM*boneTransform * vec4(Position, 1.0); Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; } \ No newline at end of file diff --git a/resources/Shaders/Sprite.frag.glsl b/resources/Shaders/Sprite.frag.glsl index 754be6ac..1416a9e9 100644 --- a/resources/Shaders/Sprite.frag.glsl +++ b/resources/Shaders/Sprite.frag.glsl @@ -3,8 +3,6 @@ uniform vec4 Color; uniform vec4 FillColor; uniform float FillPercentage; -uniform mat4 M; -uniform mat4 V; uniform mat4 P; layout (binding = 1) uniform sampler2D DiffuseTexture; diff --git a/resources/Shaders/Sprite.vert.glsl b/resources/Shaders/Sprite.vert.glsl index c09d745b..82c4c9bb 100644 --- a/resources/Shaders/Sprite.vert.glsl +++ b/resources/Shaders/Sprite.vert.glsl @@ -1,8 +1,6 @@ #version 430 -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; +uniform mat4 PVM; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -17,7 +15,7 @@ out VertexData{ void main() { - gl_Position = P * V * M * vec4(Position, 1.0); + gl_Position = PVM* vec4(Position, 1.0); Output.Position = Position; Output.TextureCoordinate = TextureCoords; diff --git a/resources/Shaders/StandarUniform.glsl b/resources/Shaders/StandarUniform.glsl new file mode 100644 index 00000000..9fc4b6f8 --- /dev/null +++ b/resources/Shaders/StandarUniform.glsl @@ -0,0 +1,55 @@ +//----- SHADER DEFINES ----- +#define MAX_BONES 100 +#define MIN_AMBIENT_LIGHT 0.3 + +//----- UNIFORM LOCATION ----- +#define PVM_UNIFORM_LOCATION 100 +#define VM_UNIFORM_LOCATION 101 +#define VP_UNIFORM_LOCATION 102 +#define TIM_UNIFORM_LOCATION 103 +#define M_UNIFORM_LOCATION 104 +#define V_UNIFORM_LOCATION 105 +#define P_UNIFORM_LOCATION 106 + +#define BONES_LOCATION 200 + +#define AMBIENT_COLOR_UNIFORM_LOCATION 300 +#define COLOR_UNIFORM_LOCATION 301 +#define DIFFUSE_COLOR_UNIFORM_LOCATION 302 +#define SCREEN_DIMENSIONS_UNIFORM_LOCATION 303 +#define FILL_COLOR_UNIFORM_LOCATION 304 +#define FILL_PERCENTAGE_UNIFORM_LOCATION 305 +#define GLOW_INTENSITY_UNIFORM_LOCATION 306 +#define CAMERA_POSITION_UNIFORM_LOCATION 306 +#define SSAO_QUALITY_UNIFORM_LOCATION 308 + +#define LOCAL_UNIFORM_LOCATION1; + +//----- TEXTURE LOCATION ----- +#define SSAO_TEXTURE_LOCATION 0 +#define SHADOW_TEXTURE_LOCATION 1 +#define LOCAL_TEXTURE_LOCATION1 2 +#define LOCAL_TEXTURE_LOCATION2 3 +#define LOCAL_TEXTURE_LOCATION3 4 +#define LOCAL_TEXTURE_LOCATION4 5 +#define LOCAL_TEXTURE_LOCATION5 6 +#define LOCAL_TEXTURE_LOCATION6 7 +#define LOCAL_TEXTURE_LOCATION7 8 +#define LOCAL_TEXTURE_LOCATION8 9 +#define LOCAL_TEXTURE_LOCATION9 10 +#define LOCAL_TEXTURE_LOCATION10 11 +#define LOCAL_TEXTURE_LOCATION11 12 +#define LOCAL_TEXTURE_LOCATION12 13 +#define LOCAL_TEXTURE_LOCATION13 14 +#define LOCAL_TEXTURE_LOCATION14 15 +#define LOCAL_TEXTURE_LOCATION15 16 +#define LOCAL_TEXTURE_LOCATION16 17 +#define LOCAL_TEXTURE_LOCATION17 18 +#define LOCAL_TEXTURE_LOCATION18 19 +#define LOCAL_TEXTURE_LOCATION19 20 +#define LOCAL_TEXTURE_LOCATION20 21 +#define LOCAL_TEXTURE_LOCATION21 22 +#define LOCAL_TEXTURE_LOCATION22 23 +#define LOCAL_TEXTURE_LOCATION23 24 +#define LOCAL_TEXTURE_LOCATION24 25 +#define LOCAL_TEXTURE_LOCATION25 26 diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 1bd0b82b..b364688a 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -961,9 +961,8 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::listModel->IsSkinned()) { m_FillDepthStencilBufferSkinnedProgram->Bind(); GLuint shaderHandle = m_FillDepthStencilBufferSkinnedProgram->GetHandle(); - 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())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix)); + GLERROR("Bind PVM uniform"); std::vector frameBones; if (modelJob->BlendTree != nullptr) { @@ -976,9 +975,8 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::listBind(); GLuint shaderHandle = m_FillDepthStencilBufferProgram->GetHandle(); - 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())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix)); + GLERROR("Bind PVM uniform"); } @@ -1008,8 +1006,8 @@ void DrawFinalPass::DrawSprites(std::list>&jobs, Rend if(spriteJob->Depth == 0) { jobState.Disable(GL_DEPTH_TEST); } - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix)); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position())); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); @@ -1049,6 +1047,12 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrProjectionMatrix())); GLERROR("Bind 4 uniform"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * job->Matrix)); + GLERROR("Bind PVM uniform"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "VM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix() * job->Matrix)); + GLERROR("Bind VM uniform"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "TIM"), 1, GL_FALSE, glm::value_ptr(glm::transpose(glm::inverse(job->Matrix)))); + GLERROR("Bind TIM uniform"); glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); GLERROR("Bind 5 uniform"); @@ -1101,6 +1105,12 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptrProjectionMatrix())); GLERROR("Bind 4 uniform"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * job->Matrix)); + GLERROR("Bind PVM uniform"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "VM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix() * job->Matrix)); + GLERROR("Bind VM uniform"); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "TIM"), 1, GL_FALSE, glm::value_ptr(glm::transpose(glm::inverse(job->Matrix)))); + GLERROR("Bind TIM uniform"); GLint Location_ScreenDimensions = glGetUniformLocation(shaderHandle, "ScreenDimensions"); glUniform2f(Location_ScreenDimensions, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index f21e3f94..3f97e375 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -63,7 +63,6 @@ void PickingPass::Draw(RenderScene& scene) GLuint shaderHandle = m_PickingProgram->GetHandle(); GLuint shaderSkinnedHandle = m_PickingSkinnedProgram->GetHandle(); m_PickingProgram->Bind(); - if (scene.ClearDepth) { //glClear(GL_DEPTH_BUFFER_BIT); state->Disable(GL_DEPTH_TEST); @@ -100,9 +99,7 @@ void PickingPass::Draw(RenderScene& scene) if (modelJob->Model->IsSkinned()) { m_PickingSkinnedProgram->Bind(); - glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + glUniformMatrix4fv(100, 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix)); glUniform2fv(glGetUniformLocation(shaderSkinnedHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); std::vector frameBones; @@ -116,9 +113,7 @@ void PickingPass::Draw(RenderScene& scene) } else { m_PickingProgram->Bind(); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - 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())); + glUniformMatrix4fv(100, 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix)); glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); }