Merge pull request #190 from teamfisk/RendererBugFixes

Renderer bug fixes
This commit is contained in:
Tobias Dahl
2016-03-09 18:01:02 +01:00
30 changed files with 502 additions and 200 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ public:
void GenerateCubeMapTexture();
//GLuint CubeMapTexture() const { return m_CubeMapTexture; }
GLuint m_CubeMapTexture = -1;
GLuint m_CubeMapTexture = 0;
private:
IRenderer* m_Renderer;
+1 -1
View File
@@ -13,7 +13,7 @@ class DrawBloomPass
{
public:
DrawBloomPass(IRenderer* renderer, ConfigFile* config);
~DrawBloomPass() { }
~DrawBloomPass();
void InitializeTextures();
void InitializeFrameBuffers();
void InitializeShaderPrograms();
+6 -6
View File
@@ -17,7 +17,7 @@ class DrawFinalPass
{
public:
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass);
~DrawFinalPass() { }
~DrawFinalPass();
void InitializeTextures();
void InitializeFrameBuffers();
void InitializeShaderPrograms();
@@ -57,11 +57,11 @@ private:
FrameBuffer m_FinalPassFrameBuffer;
FrameBuffer m_ShieldDepthFrameBuffer;
GLuint m_BloomTexture;
GLuint m_SceneTexture;
GLuint m_DepthBuffer;
GLuint m_ShieldBuffer;
GLuint m_CubeMapTexture;
GLuint m_BloomTexture = 0;
GLuint m_SceneTexture = 0;
GLuint m_DepthBuffer = 0;
GLuint m_ShieldBuffer = 0;
GLuint m_CubeMapTexture = 0;
GLuint m_FullBlurredTexture;
GLuint m_CombinedTexture; //This can be removed for less memory usage, just set m_sceneTexture to the return from m_BlurHUDPass.CombineTextures
+4 -2
View File
@@ -111,7 +111,7 @@ struct ModelJob : RenderJob
Color = modelComponent["Color"];
GlowIntensity = ((double)modelComponent["GlowIntensity"]);
Entity = modelComponent.EntityID;
glm::vec3 abspos = Transform::AbsolutePosition(world, modelComponent.EntityID);
glm::vec3 abspos = glm::vec3(matrix[3][0], matrix[3][1], matrix[3][2]);
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
Depth = worldpos.z;
World = world;
@@ -164,7 +164,9 @@ struct ModelJob : RenderJob
bool IsShielded;
void CalculateHash() override
{
Hash = ShaderID << 20 + ModelID << 10 + TextureID;
Hash = TextureID;
Hash += ModelID << 10;
Hash += ShaderID << 20;
}
};
+2 -2
View File
@@ -52,8 +52,8 @@ private:
std::unordered_map<glm::ivec2, PickingInfo> m_PickingColorsToEntity;
GLuint m_PickingTexture;
GLuint m_DepthBuffer;
GLuint m_PickingTexture = 0;
GLuint m_DepthBuffer = 0;
FrameBuffer m_PickingBuffer;
+5 -6
View File
@@ -16,16 +16,15 @@ struct RenderJob
public:
float Depth;
bool operator<(const RenderJob& rhs)
{
return this->Hash < rhs.Hash;
}
protected:
uint64_t Hash;
virtual void CalculateHash() = 0;
bool operator<(const RenderJob& rhs)
{
return this->Hash < rhs.Hash;
}
};
#endif
+1
View File
@@ -37,6 +37,7 @@ public:
: m_EventBroker(eventBroker)
, m_Config(config)
{ }
~Renderer();
virtual void Initialize() override;
virtual void Update(double dt) override;
+1 -1
View File
@@ -14,7 +14,7 @@ class SSAOPass
{
public:
SSAOPass(IRenderer* renderer, ConfigFile* config);
~SSAOPass() { };
~SSAOPass();
void ChangeQuality(int quality);
+2
View File
@@ -21,6 +21,8 @@ public:
std::string GetFileName() const;
GLuint GetHandle() const;
bool IsCompiled() const;
static std::string ReadFile(std::string fileName);
private:
protected:
GLenum m_ShaderType;
std::string m_FileName;
+2 -4
View File
@@ -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;
}
@@ -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);
}
+4 -2
View File
@@ -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));
@@ -182,6 +183,7 @@ void main()
color_result += FillColor;
}
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//sceneColor = CommonUniforms.testColour;
//sceneColor = vec4(reflectionColor.xyz, 1);
color_result.xyz += glowTexel.xyz*GlowIntensity;
+4 -3
View File
@@ -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));
@@ -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));
@@ -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;
@@ -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);
@@ -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);
+2 -5
View File
@@ -1,8 +1,5 @@
#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;
@@ -16,6 +13,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;
}
+2 -5
View File
@@ -1,8 +1,5 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 PVM;
uniform mat4 Bones[100];
layout(location = 0) in vec3 Position;
@@ -27,6 +24,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;
}
-2
View File
@@ -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;
+2 -4
View File
@@ -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;
@@ -0,0 +1,6 @@
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
{
mat3 TBN = mat3(tangent, bitangent, normal);
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
return vec4(TBN * normalize(NormalMap), 0.0);
}
+5
View File
@@ -9,6 +9,11 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config)
ChangeQuality(m_Config->Get<int>("GLOW.Quality", 2));
}
DrawBloomPass::~DrawBloomPass() {
CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz);
CommonFunctions::DeleteTexture(&m_GaussianTexture_vert);
}
void DrawBloomPass::InitializeTextures()
{
m_BlackTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/Black.png");
+341 -106
View File
@@ -12,6 +12,14 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
InitializeFrameBuffers();
}
DrawFinalPass::~DrawFinalPass(){
CommonFunctions::DeleteTexture(&m_BloomTexture);
CommonFunctions::DeleteTexture(&m_SceneTexture);
CommonFunctions::DeleteTexture(&m_DepthBuffer);
CommonFunctions::DeleteTexture(&m_ShieldBuffer);
CommonFunctions::DeleteTexture(&m_CubeMapTexture);
}
void DrawFinalPass::InitializeTextures()
{
m_WhiteTexture = CommonFunctions::TryLoadResource<Texture, false>("Textures/Core/White.png");
@@ -351,6 +359,8 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
GLuint explosionSkinnedHandle = m_ExplosionEffectSkinnedProgram->GetHandle();
GLuint explosionSplatMapSkinnedHandle = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle();
GLuint forwardSplatMapSkinnedHandle = m_ForwardPlusSplatMapSkinnedProgram->GetHandle();
GLuint lastShader = 0;
unsigned int lastModel = 0;
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
@@ -367,9 +377,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SingleTextures:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSkinned program");
if (lastShader != m_ExplosionEffectSkinnedProgram->GetHandle()) {
m_ExplosionEffectSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinned program");
glUniform1i(glGetUniformLocation(explosionSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -389,8 +407,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
else {
m_ExplosionEffectProgram->Bind();
GLERROR("Bind ExplosionEffect program");
if (lastShader != m_ExplosionEffectProgram->GetHandle()) {
m_ExplosionEffectProgram->Bind();
lastShader = m_ExplosionEffectProgram->GetHandle();
GLERROR("Bind ExplosionEffect program");
glUniform1i(glGetUniformLocation(explosionHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffect Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionHandle, explosionEffectJob, scene);
//bind textures
@@ -404,8 +431,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SplatMapping:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
if (lastShader != m_ExplosionEffectSplatMapSkinnedProgram->GetHandle()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
glUniform1i(glGetUniformLocation(explosionSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMapSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -421,9 +457,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
else {
m_ExplosionEffectSplatMapProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMap program");
//bind uniforms
if (lastShader != m_ExplosionEffectSplatMapProgram->GetHandle()) {
m_ExplosionEffectSplatMapProgram->Bind();
lastShader = m_ExplosionEffectSplatMapProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene);
//bind textures
@@ -436,8 +480,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glDisable(GL_CULL_FACE);
//draw
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
if (lastModel != explosionEffectJob->ModelID) {
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
lastModel = explosionEffectJob->ModelID;
}
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
glEnable(GL_CULL_FACE);
GLERROR("explosion effect end");
@@ -451,8 +498,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SingleTextures:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSkinnedProgram->Bind();
GLERROR("Bind ForwardPlusSkinnedProgram");
if (lastShader != m_ForwardPlusSkinnedProgram->GetHandle()) {
m_ForwardPlusSkinnedProgram->Bind();
lastShader = m_ForwardPlusSkinnedProgram->GetHandle();
GLERROR("Bind ForwardPlusSkinnedProgram program");
glUniform1i(glGetUniformLocation(forwardSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusSkinnedProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSkinnedHandle, modelJob, scene);
//bind textures
@@ -470,8 +526,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ForwardPlusProgram->Bind();
GLERROR("Bind ForwardPlusProgram");
if (lastShader != m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
lastShader = m_ForwardPlusProgram->GetHandle();
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
//bind textures
@@ -485,8 +550,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
case RawModel::MaterialType::SplatMapping:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapSkinnedProgram->GetHandle()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
lastShader = m_ForwardPlusSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind SkinnedSplatMapProgram program");
glUniform1i(glGetUniformLocation(forwardSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SkinnedSplatMapProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene);
//bind textures
@@ -502,8 +576,17 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
else {
m_ForwardPlusSplatMapProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapProgram->GetHandle()) {
m_ForwardPlusSplatMapProgram->Bind();
lastShader = m_ForwardPlusSplatMapProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapHandle, modelJob, scene);
//bind textures
@@ -514,8 +597,11 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
}
}
//draw
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
if (GLERROR("models end")) {
continue;
@@ -544,6 +630,8 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
GLuint explosionSkinnedShieldCheckHandle = m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle();
GLuint explosionSplatMapSkinnedShieldCheckHandle = m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle();
GLuint forwardSplatMapSkinnedShieldCheckHandle = m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle();
GLuint lastShader = 0;
unsigned int lastModel = 0;
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
@@ -564,9 +652,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSkinnedShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffectSkinned program");
if (lastShader != m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle()) {
m_ExplosionEffectSkinnedShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinned program");
glUniform1i(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSkinnedShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -585,8 +681,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ExplosionEffectShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffect program");
if (lastShader != m_ExplosionEffectShieldCheckProgram->GetHandle()) {
m_ExplosionEffectShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffect program");
glUniform1i(glGetUniformLocation(explosionShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffect Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -601,8 +706,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
if (lastShader != m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle()) {
m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectSplatMapSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
glUniform1i(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMapSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapSkinnedShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -619,9 +733,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ExplosionEffectSplatMapShieldCheckProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMap program");
//bind uniforms
if (lastShader != m_ExplosionEffectSplatMapShieldCheckProgram->GetHandle()) {
m_ExplosionEffectSplatMapShieldCheckProgram->Bind();
lastShader = m_ExplosionEffectSplatMapShieldCheckProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapShieldCheckHandle, explosionEffectJob, scene);
//bind textures
@@ -637,9 +759,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSkinned program");
if (lastShader != m_ExplosionEffectSkinnedProgram->GetHandle()) {
m_ExplosionEffectSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinned program");
glUniform1i(glGetUniformLocation(explosionSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinned Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -657,8 +787,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glUniformMatrix4fv(glGetUniformLocation(explosionSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ExplosionEffectProgram->Bind();
GLERROR("Bind ExplosionEffect program");
if (lastShader != m_ExplosionEffectProgram->GetHandle()) {
m_ExplosionEffectProgram->Bind();
lastShader = m_ExplosionEffectProgram->GetHandle();
GLERROR("Bind ExplosionEffect program");
glUniform1i(glGetUniformLocation(explosionHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffect Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionHandle, explosionEffectJob, scene);
//bind textures
@@ -672,8 +811,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (explosionEffectJob->Model->IsSkinned()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMapSkinned program");
if (lastShader != m_ExplosionEffectSplatMapSkinnedProgram->GetHandle()) {
m_ExplosionEffectSplatMapSkinnedProgram->Bind();
lastShader = m_ExplosionEffectSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind ExplosionEffectSkinnedSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSkinnedSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapSkinnedHandle, explosionEffectJob, scene);
//bind textures
@@ -689,9 +837,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ExplosionEffectSplatMapProgram->Bind();
GLERROR("Bind ExplosionEffectSplatMap program");
//bind uniforms
if (lastShader != m_ExplosionEffectSplatMapProgram->GetHandle()) {
m_ExplosionEffectSplatMapProgram->Bind();
lastShader = m_ExplosionEffectSplatMapProgram->GetHandle();
GLERROR("Bind ExplosionEffectSplatMap program");
glUniform1i(glGetUniformLocation(explosionSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(explosionSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(explosionSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(explosionSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ExplosionEffectSplatMap Uniforms");
}
//bind uniforms
BindExplosionUniforms(explosionSplatMapHandle, explosionEffectJob, scene);
//bind textures
@@ -705,8 +861,11 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glDisable(GL_CULL_FACE);
//draw
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
if (lastModel != explosionEffectJob->ModelID) {
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
lastModel = explosionEffectJob->ModelID;
}
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
glEnable(GL_CULL_FACE);
GLERROR("explosion effect end");
@@ -721,8 +880,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSkinnedShieldCheckProgram->Bind();
GLERROR("Bind ForwardPlusSkinnedProgram");
if (lastShader != m_ForwardPlusSkinnedShieldCheckProgram->GetHandle()) {
m_ForwardPlusSkinnedShieldCheckProgram->Bind();
lastShader = m_ForwardPlusSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ForwardPlusSkinnedProgram program");
glUniform1i(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusSkinnedProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSkinnedShieldCheckHandle, modelJob, scene);
//bind textures
@@ -741,8 +909,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ForwardPlusShieldCheckProgram->Bind();
GLERROR("Bind ForwardPlusProgram");
if (lastShader != m_ForwardPlusShieldCheckProgram->GetHandle()) {
m_ForwardPlusShieldCheckProgram->Bind();
lastShader = m_ForwardPlusShieldCheckProgram->GetHandle();
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardShieldCheckHandle, modelJob, scene);
//bind textures
@@ -756,8 +933,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle()) {
m_ForwardPlusSplatMapSkinnedShieldCheckProgram->Bind();
lastShader = m_ForwardPlusSplatMapSkinnedShieldCheckProgram->GetHandle();
GLERROR("Bind ForwardPlusProgramSplatMapSkinned program");
glUniform1i(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgramSplatMapSkinned Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapSkinnedShieldCheckHandle, modelJob, scene);
//bind textures
@@ -773,8 +959,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedShieldCheckHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ForwardPlusSplatMapShieldCheckProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapShieldCheckProgram->GetHandle()) {
m_ForwardPlusSplatMapShieldCheckProgram->Bind();
lastShader = m_ForwardPlusSplatMapShieldCheckProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatShieldCheckHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatShieldCheckHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatShieldCheckHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatShieldCheckHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatShieldCheckHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatShieldCheckHandle, modelJob, scene);
//bind textures
@@ -790,8 +985,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SingleTextures:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSkinnedProgram->Bind();
GLERROR("Bind ForwardPlusSkinnedProgram");
if (lastShader != m_ForwardPlusSkinnedProgram->GetHandle()) {
m_ForwardPlusSkinnedProgram->Bind();
lastShader = m_ForwardPlusSkinnedProgram->GetHandle();
GLERROR("Bind ForwardPlusSkinnedProgram program");
glUniform1i(glGetUniformLocation(forwardSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusSkinnedProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSkinnedHandle, modelJob, scene);
//bind textures
@@ -810,8 +1014,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
else {
m_ForwardPlusProgram->Bind();
GLERROR("Bind ForwardPlusProgram");
if (lastShader != m_ForwardPlusProgram->GetHandle()) {
m_ForwardPlusProgram->Bind();
lastShader = m_ForwardPlusProgram->GetHandle();
GLERROR("Bind ForwardPlusProgram program");
glUniform1i(glGetUniformLocation(forwardHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind ForwardPlusProgram Uniforms");
}
//bind uniforms
BindModelUniforms(forwardHandle, modelJob, scene);
//bind textures
@@ -825,8 +1038,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
case RawModel::MaterialType::SplatMapping:
{
if (modelJob->Model->IsSkinned()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapSkinnedProgram->GetHandle()) {
m_ForwardPlusSplatMapSkinnedProgram->Bind();
lastShader = m_ForwardPlusSplatMapSkinnedProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatMapSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapSkinnedHandle, modelJob, scene);
//bind textures
@@ -842,8 +1064,17 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
else {
m_ForwardPlusSplatMapProgram->Bind();
GLERROR("Bind SplatMap program");
if (lastShader != m_ForwardPlusSplatMapProgram->GetHandle()) {
m_ForwardPlusSplatMapProgram->Bind();
lastShader = m_ForwardPlusSplatMapProgram->GetHandle();
GLERROR("Bind SplatMap program");
glUniform1i(glGetUniformLocation(forwardSplatMapHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(forwardSplatMapHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(forwardSplatMapHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(forwardSplatMapHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind SplatMap Uniforms");
}
//bind uniforms
BindModelUniforms(forwardSplatMapHandle, modelJob, scene);
//bind textures
@@ -855,8 +1086,11 @@ void DrawFinalPass::DrawModelRenderQueuesWithShieldCheck(std::list<std::shared_p
}
}
//draw
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
if (GLERROR("models end")) {
continue;
@@ -961,17 +1195,26 @@ void DrawFinalPass::DrawShieldedModelRenderQueue(std::list<std::shared_ptr<Rende
void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob>>& jobs, RenderScene& scene)
{
GLuint shaderSkinnedHandle = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
GLuint shaderHandle = m_FillDepthStencilBufferProgram->GetHandle();
GLuint lastShader = 0;
for (auto &job : jobs) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if(modelJob->Model->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));
if (lastShader != m_FillDepthStencilBufferSkinnedProgram->GetHandle()) {
m_FillDepthStencilBufferSkinnedProgram->Bind();
lastShader = m_FillDepthStencilBufferSkinnedProgram->GetHandle();
glUniform1i(glGetUniformLocation(shaderSkinnedHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
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()));
glUniform2f(glGetUniformLocation(shaderSkinnedHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(shaderSkinnedHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind Uniforms 1");
}
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
GLERROR("Bind PVM uniform");
std::vector<glm::mat4> frameBones;
if (modelJob->BlendTree != nullptr) {
@@ -982,11 +1225,19 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else {
m_FillDepthStencilBufferProgram->Bind();
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));
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
m_FillDepthStencilBufferProgram->Bind();
lastShader = m_FillDepthStencilBufferProgram->GetHandle();
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
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->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind Uniforms 2");
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * modelJob->Matrix));
GLERROR("Bind PVM uniform");
}
@@ -1008,6 +1259,9 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
GLuint shaderHandle = m_SpriteProgram->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position()));
for(auto& job : jobs) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
RenderState jobState;
@@ -1016,10 +1270,7 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&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, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform3fv(glGetUniformLocation(shaderHandle, "CameraPos"), 1, glm::value_ptr(scene.Camera->Position()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(spriteJob->FillColor));
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), spriteJob->FillPercentage);
@@ -1049,17 +1300,14 @@ void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, Rend
void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene)
{
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
GLERROR("Bind 1 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(job->Matrix));
GLERROR("Bind 2 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
GLERROR("Bind 3 uniform");
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
GLERROR("Bind 4 uniform");
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("Bind 5 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");
glUniform3fv(glGetUniformLocation(shaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(job->ExplosionOrigin));
GLERROR("Bind 6 uniform");
@@ -1090,29 +1338,21 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
GLERROR("Bind 18 uniform");
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), job->FillPercentage);
GLERROR("Bind 19 uniform");
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind 20 uniform");
glUniform1f(glGetUniformLocation(shaderHandle, "GlowIntensity"), job->GlowIntensity);
GLERROR("END");
}
void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<ModelJob>& job, RenderScene& scene)
{
glUniform1i(glGetUniformLocation(shaderHandle, "SSAOQuality"), m_SSAOPass->TextureQuality());
GLERROR("Bind 1 uniform");
GLint Location_M = glGetUniformLocation(shaderHandle, "M");
glUniformMatrix4fv(Location_M, 1, GL_FALSE, glm::value_ptr(job->Matrix));
GLERROR("Bind 2 uniform");
GLint Location_V = glGetUniformLocation(shaderHandle, "V");
glUniformMatrix4fv(Location_V, 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
GLERROR("Bind 3 uniform");
GLint Location_P = glGetUniformLocation(shaderHandle, "P");
glUniformMatrix4fv(Location_P, 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
GLERROR("Bind 4 uniform");
GLint Location_ScreenDimensions = glGetUniformLocation(shaderHandle, "ScreenDimensions");
glUniform2f(Location_ScreenDimensions, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
GLERROR("Bind 5 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_FillPercentage = glGetUniformLocation(shaderHandle, "FillPercentage");
glUniform1f(Location_FillPercentage, job->FillPercentage);
@@ -1125,11 +1365,6 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<Model
GLERROR("Bind 8 uniform");
GLint Location_Color = glGetUniformLocation(shaderHandle, "Color");
glUniform4fv(Location_Color, 1, glm::value_ptr(job->Color));
GLERROR("Bind 9 uniform");
GLint Location_AmbientColor = glGetUniformLocation(shaderHandle, "AmbientColor");
glUniform4fv(Location_AmbientColor, 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind 10 uniform");
GLint Location_GlowIntensity = glGetUniformLocation(shaderHandle, "GlowIntensity");
glUniform1f(Location_GlowIntensity, job->GlowIntensity);
+38 -28
View File
@@ -12,7 +12,8 @@ PickingPass::PickingPass(IRenderer* renderer, EventBroker* eb)
PickingPass::~PickingPass()
{
CommonFunctions::DeleteTexture(&m_PickingTexture);
CommonFunctions::DeleteTexture(&m_DepthBuffer);
}
@@ -61,8 +62,9 @@ void PickingPass::Draw(RenderScene& scene)
//TODO: Render: Add code for more jobs than modeljobs.
GLuint shaderHandle = m_PickingProgram->GetHandle();
GLuint shaderSkinnedHandle = m_PickingSkinnedProgram->GetHandle();
GLuint lastShader = 0;
unsigned int lastModel = 0;
m_PickingProgram->Bind();
if (scene.ClearDepth) {
//glClear(GL_DEPTH_BUFFER_BIT);
state->Disable(GL_DEPTH_TEST);
@@ -98,10 +100,11 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
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()));
if (lastShader != m_PickingSkinnedProgram->GetHandle()) {
m_PickingSkinnedProgram->Bind();
lastShader = m_PickingSkinnedProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "PVM"), 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<glm::mat4> frameBones;
@@ -114,15 +117,19 @@ 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()));
if (lastShader != m_PickingProgram->GetHandle()) {
m_PickingProgram->Bind();
lastShader = m_PickingProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 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])));
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
}
}
@@ -208,10 +215,11 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
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()));
if (lastShader != m_PickingSkinnedProgram->GetHandle()) {
m_PickingSkinnedProgram->Bind();
lastShader = m_PickingSkinnedProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 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<glm::mat4> frameBones;
@@ -224,19 +232,24 @@ void PickingPass::Draw(RenderScene& scene)
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} 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()));
if (lastShader != m_PickingProgram->GetHandle()) {
m_PickingProgram->Bind();
lastShader = m_PickingProgram->GetHandle();
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 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])));
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
if (lastModel != modelJob->ModelID) {
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
lastModel = modelJob->ModelID;
}
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
}
}
m_PickingProgram->Bind();
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob->Pickable) {
@@ -271,14 +284,11 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
m_PickingProgram->Bind();
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, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "PVM"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix() * scene.Camera->ViewMatrix() * spriteJob->Matrix));
glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex * sizeof(unsigned int)));
}
}
+1 -1
View File
@@ -449,7 +449,7 @@ void RenderSystem::Update(double dt)
fillModels(scene.Jobs);
fillPointLights(scene.Jobs.PointLight, m_World);
//TODO: Make sure all objects needed are also sorted.
scene.Jobs.OpaqueObjects.sort();
scene.Jobs.OpaqueObjects.sort([](auto& a, auto& b) {return *a < *b; });
fillSprites(scene.Jobs.SpriteJob, m_World);
fillDirectionalLights(scene.Jobs.DirectionalLight, m_World);
fillText(scene.Jobs.Text, m_World);
+13
View File
@@ -2,6 +2,19 @@
std::unordered_map<GLFWwindow*, Renderer*> Renderer::m_WindowToRenderer;
Renderer::~Renderer() {
delete m_PickingPass;
delete m_LightCullingPass;
delete m_ImGuiRenderPass;
delete m_DrawFinalPass;
delete m_DrawScreenQuadPass;
delete m_DrawBloomPass;
delete m_DrawColorCorrectionPass;
delete m_SSAOPass;
delete m_CubeMapPass;
delete m_TextPass;
}
void Renderer::Initialize()
{
m_SSAO_Quality = m_Config->Get<int>("SSAO.Quality", 0);
+7
View File
@@ -10,6 +10,13 @@ SSAOPass::SSAOPass(IRenderer* renderer, ConfigFile* config)
}
SSAOPass::~SSAOPass() {
CommonFunctions::DeleteTexture(&m_SSAOTexture);
CommonFunctions::DeleteTexture(&m_SSAOViewSpaceZTexture);
CommonFunctions::DeleteTexture(&m_Gaussian_horiz);
CommonFunctions::DeleteTexture(&m_Gaussian_vert);
}
void SSAOPass::ChangeQuality(int quality)
{
if (m_Quality == quality) {
+39 -11
View File
@@ -4,22 +4,32 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
{
LOG_INFO("Compiling shader \"%s\"", fileName.c_str());
std::string shaderFile;
std::ifstream in(fileName, std::ios::in);
if (!in) {
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
return 0;
}
in.seekg(0, std::ios::end);
shaderFile.resize((int)in.tellg());
in.seekg(0, std::ios::beg);
in.read(&shaderFile[0], shaderFile.size());
in.close();
std::string shaderFile = ReadFile(fileName);
GLuint shader = glCreateShader(shaderType);
if (GLERROR("glCreateShader"))
return 0;
std::size_t startPos = 0;
std::size_t SEofNewFile[2];
std::string key = "#include";
while((startPos = shaderFile.find(key, startPos)) != std::string::npos)
{
SEofNewFile[0] = shaderFile.find('"', startPos+key.length())+1;
SEofNewFile[1] = shaderFile.find('"', SEofNewFile[0]);
if (SEofNewFile[0] == std::string::npos || SEofNewFile[1] == std::string::npos)
return 0;
std::string replacementFileName = shaderFile.substr(SEofNewFile[0], SEofNewFile[1] - SEofNewFile[0]);
std::string replacementString = ReadFile(replacementFileName);
size_t firstof = replacementString.find_first_of((char)0);
replacementString.erase(firstof, replacementString.size() - firstof);
if (replacementString.length() <= 0)
return 0;
shaderFile.replace(startPos, SEofNewFile[1]+2 - startPos, replacementString + "\n");
startPos += replacementString.length(); //This might not be wanted.
}
const GLchar* shaderFiles = shaderFile.c_str();
const GLint length = static_cast<GLint>(shaderFile.length());
glShaderSource(shader, 1, &shaderFiles, &length);
@@ -46,6 +56,24 @@ GLuint Shader::CompileShader(GLenum shaderType, std::string fileName)
return shader;
}
std::string Shader::ReadFile(std::string fileName)
{
std::string shaderFile;
std::ifstream in(fileName, std::ios::in);
if (!in) {
LOG_ERROR("Error: Failed to open shader file \"%s\"", fileName.c_str());
return "";
}
in.seekg(0, std::ios::end);
shaderFile.resize((int)in.tellg());
in.seekg(0, std::ios::beg);
in.read(&shaderFile[0], shaderFile.size());
in.close();
return shaderFile;
}
Shader::Shader(GLenum shaderType, std::string fileName) : m_ShaderType(shaderType), m_FileName(fileName)
{
m_ShaderHandle = 0;
+1 -1
View File
@@ -37,7 +37,7 @@ ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer*
glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata);
GLERROR("glReadPixels(pdata) Error");
PickDataBuffer->Unbind();
GLERROR("Unbind Error");
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
GLERROR("glBindFramebuffer(DepthBuffer) Error");
float depthData;