Merge remote-tracking branch 'origin/deffered_rendering' into particles

This commit is contained in:
Stiffly
2014-05-30 20:04:17 +02:00
9 changed files with 119 additions and 19 deletions
+1 -1
Submodule assets updated: 20edf7934a...74035fae26
+12
View File
@@ -10,13 +10,25 @@ namespace Components
{ {
BlendMap() BlendMap()
: TextureRed("Textures/ErrorTextureRed.png") : TextureRed("Textures/ErrorTextureRed.png")
, TextureRedNormal("Textures/NeutralNormalMap.png")
, TextureRedSpecular("Textures/NeutralSpecularMap.png")
, TextureGreen("Textures/ErrorTextureGreen.png") , TextureGreen("Textures/ErrorTextureGreen.png")
, TextureGreenNormal("Textures/NeutralNormalMap.png")
, TextureGreenSpecular("Textures/NeutralSpecularMap.png")
, TextureBlue("Textures/ErrorTextureBlue.png") , TextureBlue("Textures/ErrorTextureBlue.png")
, TextureBlueNormal("Textures/NeutralNormalMap.png")
, TextureBlueSpecular("Textures/NeutralSpecularMap.png")
, TextureRepeats(100.f) { } , TextureRepeats(100.f) { }
std::string TextureRed; std::string TextureRed;
std::string TextureRedNormal;
std::string TextureRedSpecular;
std::string TextureGreen; std::string TextureGreen;
std::string TextureGreenNormal;
std::string TextureGreenSpecular;
std::string TextureBlue; std::string TextureBlue;
std::string TextureBlueNormal;
std::string TextureBlueSpecular;
float TextureRepeats; float TextureRepeats;
virtual BlendMap* Clone() const override { return new BlendMap(*this); } virtual BlendMap* Clone() const override { return new BlendMap(*this); }
+35 -8
View File
@@ -61,11 +61,24 @@ public:
auto blendmapComponent = m_World->GetComponent<Components::BlendMap>(entity); auto blendmapComponent = m_World->GetComponent<Components::BlendMap>(entity);
if (blendmapComponent) if (blendmapComponent)
{ {
auto textureRed = ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRed); BlendMapTexture RedTexture;
auto textureGreen = ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreen); RedTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRed);
auto textureBlue = ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlue); RedTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRedNormal);
RedTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRedSpecular);
BlendMapTexture GreenTexture;
GreenTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreen);
GreenTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreenNormal);
GreenTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreenSpecular);
BlendMapTexture BlueTexture;
BlueTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlue);
BlueTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlueNormal);
BlueTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlueSpecular);
float textureRepeat = blendmapComponent->TextureRepeats; float textureRepeat = blendmapComponent->TextureRepeats;
EnqueueBlendMapModel(modelAsset, textureRed, textureGreen, textureBlue, textureRepeat, modelMatrix);
EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix);
} }
else else
{ {
@@ -113,6 +126,13 @@ protected:
std::shared_ptr<World> m_World; std::shared_ptr<World> m_World;
private: private:
struct BlendMapTexture
{
GLuint Diffuse;
GLuint Normal;
GLuint Specular;
};
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera; EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
bool OnSetViewportCamera(const Events::SetViewportCamera &event) bool OnSetViewportCamera(const Events::SetViewportCamera &event)
{ {
@@ -157,7 +177,7 @@ private:
} }
} }
void EnqueueBlendMapModel(Model* model, Texture* textureRed, Texture* textureGreen, Texture* textureBlue, float textureRepeat, glm::mat4 modelMatrix) void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix)
{ {
for (auto texGroup : model->TextureGroups) for (auto texGroup : model->TextureGroups)
{ {
@@ -166,9 +186,15 @@ private:
job.DiffuseTexture = *texGroup.Texture; job.DiffuseTexture = *texGroup.Texture;
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0; job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0; job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
job.BlendMapTextureRed = (*textureRed); job.BlendMapTextureRed = textureRed.Diffuse;
job.BlendMapTextureGreen = (*textureGreen); job.BlendMapTextureRedNormal = textureRed.Normal;
job.BlendMapTextureBlue = (*textureBlue); job.BlendMapTextureRedSpecular = textureRed.Specular;
job.BlendMapTextureGreen = textureGreen.Diffuse;
job.BlendMapTextureGreenNormal = textureGreen.Normal;
job.BlendMapTextureGreenSpecular = textureGreen.Specular;
job.BlendMapTextureBlue = textureBlue.Diffuse;
job.BlendMapTextureBlueNormal = textureBlue.Normal;
job.BlendMapTextureBlueSpecular = textureBlue.Specular;
job.TextureRepeat = textureRepeat; job.TextureRepeat = textureRepeat;
job.VAO = model->VAO; job.VAO = model->VAO;
job.StartIndex = texGroup.StartIndex; job.StartIndex = texGroup.StartIndex;
@@ -188,6 +214,7 @@ private:
RenderQueue.Forward.Add(job); RenderQueue.Forward.Add(job);
} }
}; };
} }
+6 -3
View File
@@ -106,9 +106,12 @@ void GameWorld::Initialize()
auto model = AddComponent<Components::Model>(ground_middle); auto model = AddComponent<Components::Model>(ground_middle);
model->ModelFile = "Models/TerrainFiveIstles/Middle.obj"; model->ModelFile = "Models/TerrainFiveIstles/Middle.obj";
auto blendmap = AddComponent<Components::BlendMap>(ground_middle); auto blendmap = AddComponent<Components::BlendMap>(ground_middle);
blendmap->TextureRed = "Textures/Ground/Sand.png"; blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg";
blendmap->TextureGreen = "Textures/Ground/Grass.png"; blendmap->TextureBlueNormal = "Textures/Ground/SoilBeach0087_11_SNM.png";
blendmap->TextureBlue = "Textures/Ground/Rock.png"; blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg";
blendmap->TextureBlueNormal = "Textures/Ground/Grass0126_2_SNM.png";
blendmap->TextureBlue = "Textures/Ground/Cliffs2.png";
blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png";
blendmap->TextureRepeats = 30.f; blendmap->TextureRepeats = 30.f;
auto physics = AddComponent<Components::Physics>(ground_middle); auto physics = AddComponent<Components::Physics>(ground_middle);
+1 -1
View File
@@ -93,7 +93,7 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
if (Vertices.size() > 0) if (Vertices.size() > 0)
{ {
CreateTangents(); CreateTangents();
//getSimilarVertexIndex(); getSimilarVertexIndex();
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
} }
else else
+6
View File
@@ -49,8 +49,14 @@ struct ModelJob : RenderJob
struct BlendMapModelJob : ModelJob struct BlendMapModelJob : ModelJob
{ {
GLuint BlendMapTextureRed; GLuint BlendMapTextureRed;
GLuint BlendMapTextureRedNormal;
GLuint BlendMapTextureRedSpecular;
GLuint BlendMapTextureGreen; GLuint BlendMapTextureGreen;
GLuint BlendMapTextureGreenNormal;
GLuint BlendMapTextureGreenSpecular;
GLuint BlendMapTextureBlue; GLuint BlendMapTextureBlue;
GLuint BlendMapTextureBlueNormal;
GLuint BlendMapTextureBlueSpecular;
float TextureRepeat; float TextureRepeat;
}; };
+31 -1
View File
@@ -490,6 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(modelJob->Color));
glBindVertexArray(modelJob->VAO); glBindVertexArray(modelJob->VAO);
@@ -509,6 +510,23 @@ void Renderer::ForwardRendering(RenderQueue &rq)
continue; continue;
} }
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob)
{
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
continue;
}
} }
//glDepthMask (GL_TRUE); //glDepthMask (GL_TRUE);
//glDisable (GL_BLEND); //glDisable (GL_BLEND);
@@ -1142,9 +1160,21 @@ void Renderer::DrawFBOScene(RenderQueue &rq)
glActiveTexture(GL_TEXTURE4); glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRed); glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRed);
glActiveTexture(GL_TEXTURE5); glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreen); glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRedNormal);
glActiveTexture(GL_TEXTURE6); glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRedSpecular);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreen);
glActiveTexture(GL_TEXTURE8);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreenNormal);
glActiveTexture(GL_TEXTURE9);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreenSpecular);
glActiveTexture(GL_TEXTURE10);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlue); glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlue);
glActiveTexture(GL_TEXTURE11);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlueNormal);
glActiveTexture(GL_TEXTURE12);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlueSpecular);
glDrawArrays(GL_TRIANGLES, blendMapJob->StartIndex, blendMapJob->EndIndex - blendMapJob->StartIndex + 1); glDrawArrays(GL_TRIANGLES, blendMapJob->StartIndex, blendMapJob->EndIndex - blendMapJob->StartIndex + 1);
+26 -4
View File
@@ -7,8 +7,14 @@ layout (binding=3) uniform sampler2D SpecularMapTexture;
//TerrainTextures //TerrainTextures
layout (binding=4) uniform sampler2D TextureRed; layout (binding=4) uniform sampler2D TextureRed;
layout (binding=5) uniform sampler2D TextureGreen; layout (binding=5) uniform sampler2D TextureRedNormal;
layout (binding=6) uniform sampler2D TextureBlue; layout (binding=6) uniform sampler2D TextureRedSpecular;
layout (binding=7) uniform sampler2D TextureGreen;
layout (binding=8) uniform sampler2D TextureGreenNormal;
layout (binding=9) uniform sampler2D TextureGreenSpecular;
layout (binding=10) uniform sampler2D TextureBlue;
layout (binding=11) uniform sampler2D TextureBlueNormal;
layout (binding=12) uniform sampler2D TextureBlueSpecular;
uniform float TextureRepeats; //Determines how many times the textures will loop over the terrain uniform float TextureRepeats; //Determines how many times the textures will loop over the terrain
uniform vec3 SunDirection_cameraspace; uniform vec3 SunDirection_cameraspace;
@@ -61,21 +67,37 @@ void main()
vec4 BlendMap = texture(DiffuseTexture, Input.TextureCoord); vec4 BlendMap = texture(DiffuseTexture, Input.TextureCoord);
vec4 TextureRedTexel = texture(TextureRed, Input.TextureCoord * TextureRepeats); vec4 TextureRedTexel = texture(TextureRed, Input.TextureCoord * TextureRepeats);
vec4 TextureRedTexelNormal = texture(TextureRedNormal, Input.TextureCoord * TextureRepeats);
//vec4 TextureRedTexelSpecular = texture(TextureRedSpecular, Input.TextureCoord * TextureRepeats);
vec4 TextureGreenTexel = texture(TextureGreen, Input.TextureCoord * TextureRepeats); vec4 TextureGreenTexel = texture(TextureGreen, Input.TextureCoord * TextureRepeats);
vec4 TextureGreenTexelNormal = texture(TextureGreenNormal, Input.TextureCoord * TextureRepeats);
//vec4 TextureGreenTexelSpecular = texture(TextureGreenSpecular, Input.TextureCoord * TextureRepeats);
vec4 TextureBlueTexel = texture(TextureBlue, Input.TextureCoord * TextureRepeats); vec4 TextureBlueTexel = texture(TextureBlue, Input.TextureCoord * TextureRepeats);
vec4 TextureBlueTexelNormal = texture(TextureBlueNormal, Input.TextureCoord * TextureRepeats);
//vec4 TextureBlueTexelSpecular = texture(TextureBlueSpecular, Input.TextureCoord * TextureRepeats);
//Mix the Terrain-textures together //Mix the Terrain-textures together
TextureRedTexel *= BlendMap.r; TextureRedTexel *= BlendMap.r;
TextureGreenTexel = mix(TextureRedTexel, TextureGreenTexel, BlendMap.g); TextureGreenTexel = mix(TextureRedTexel, TextureGreenTexel, BlendMap.g);
vec4 finalBlendTexel = mix(TextureGreenTexel, TextureBlueTexel, BlendMap.b); vec4 finalBlendTexel = mix(TextureGreenTexel, TextureBlueTexel, BlendMap.b);
TextureRedTexelNormal *= BlendMap.r;
TextureGreenTexelNormal = mix(TextureRedTexelNormal, TextureGreenTexelNormal, BlendMap.g);
vec4 finalBlendTexelNormal = mix(TextureGreenTexelNormal, TextureBlueTexelNormal, BlendMap.b);
//TextureRedTexelSpecular *= BlendMap.r;
//TextureGreenTexelSpecular = mix(TextureRedTexelSpecular, TextureGreenTexelSpecular, BlendMap.g);
//vec4 finalBlendTexelSpecular = mix(TextureGreenTexelSpecular, TextureBlueTexelSpecular, BlendMap.b);
// G-buffer Position // G-buffer Position
frag_Position = vec4(Input.Position.xyz, 1.0); frag_Position = vec4(Input.Position.xyz, 1.0);
// G-buffer Normal // G-buffer Normal
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal); mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); frag_Normal = normalize(vec4(TBN * vec3(finalBlendTexelNormal), 0.0));
//frag_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); //frag_Diffuse = normalize(vec4(TBN * vec3(finalBlendTexelNormal), 0.0));
//frag_Normal = vec4(Input.Normal, 0.0); //frag_Normal = vec4(Input.Normal, 0.0);
// Diffuse Texture // Diffuse Texture
+1 -1
View File
@@ -16,5 +16,5 @@ void main() {
// Texture // Texture
vec4 texel = texture(texture0, Input.TextureCoord); vec4 texel = texture(texture0, Input.TextureCoord);
frag_Diffuse = texel; frag_Diffuse = texel * Color;
} }