Merge remote-tracking branch 'origin/master' into Animations

This commit is contained in:
viktorljung
2016-02-11 23:48:30 +01:00
88 changed files with 7946 additions and 736 deletions
+72 -13
View File
@@ -13,10 +13,11 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
void DrawFinalPass::InitializeTextures()
{
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
m_BlackTexture = ResourceManager::Load<Texture>("Textures/Core/Black.png");
m_NeutralNormalTexture = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
m_GreyTexture = ResourceManager::Load<Texture>("Textures/Core/Grey.png");
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
m_NeutralNormalTexture = CommonFunctions::LoadTexture("Textures/Core/NeutralNormalMap.png", false);
m_GreyTexture = CommonFunctions::LoadTexture("Textures/Core/Grey.png", false);
m_ErrorTexture = CommonFunctions::LoadTexture("Textures/Core/ErrorTexture.png", false);
}
void DrawFinalPass::InitializeFrameBuffers()
@@ -79,9 +80,17 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ExplosionEffectProgram->Link();
GLERROR("Creating explosion program");
m_SpriteProgram = ResourceManager::Load<ShaderProgram>("#SpriteProgram");
m_SpriteProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Sprite.vert.glsl")));
m_SpriteProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Sprite.frag.glsl")));
m_SpriteProgram->Compile();
m_SpriteProgram->BindFragDataLocation(0, "sceneColor");
m_SpriteProgram->BindFragDataLocation(1, "bloomColor");
m_SpriteProgram->Link();
GLERROR("Creating sprite program");
m_ForwardPlusSplatMapProgram = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapProgram");
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMap.frag.glsl")));
m_ForwardPlusSplatMapProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMapRGB.frag.glsl")));
m_ForwardPlusSplatMapProgram->Compile();
m_ForwardPlusSplatMapProgram->BindFragDataLocation(0, "sceneColor");
m_ForwardPlusSplatMapProgram->BindFragDataLocation(1, "bloomColor");
@@ -91,7 +100,7 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ExplosionEffectSplatMapProgram = ResourceManager::Load<ShaderProgram>("#ExplosionEffectSplatMapProgram");
m_ExplosionEffectSplatMapProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
m_ExplosionEffectSplatMapProgram->AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/ExplosionEffect.geom.glsl")));
m_ExplosionEffectSplatMapProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMap.frag.glsl")));
m_ExplosionEffectSplatMapProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMapRGB.frag.glsl")));
m_ExplosionEffectSplatMapProgram->Compile();
m_ExplosionEffectSplatMapProgram->BindFragDataLocation(0, "sceneColor");
m_ExplosionEffectSplatMapProgram->BindFragDataLocation(1, "bloomColor");
@@ -119,7 +128,7 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ExplosionEffectSplatMapSkinnedProgram = ResourceManager::Load<ShaderProgram>("#ExplosionEffectSplatMapSkinnedProgram");
m_ExplosionEffectSplatMapSkinnedProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlusSkinned.vert.glsl")));
m_ExplosionEffectSplatMapSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMap.frag.glsl")));
m_ExplosionEffectSplatMapSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMapRGB.frag.glsl")));
m_ExplosionEffectSplatMapSkinnedProgram->Compile();
m_ExplosionEffectSplatMapSkinnedProgram->BindFragDataLocation(0, "sceneColor");
m_ExplosionEffectSplatMapSkinnedProgram->BindFragDataLocation(1, "bloomColor");
@@ -128,7 +137,7 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ForwardPlusSplatMapSkinnedProgram = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapSkinnedProgram");
m_ForwardPlusSplatMapSkinnedProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlusSkinned.vert.glsl")));
m_ForwardPlusSplatMapSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMap.frag.glsl")));
m_ForwardPlusSplatMapSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlusSplatMapRGB.frag.glsl")));
m_ForwardPlusSplatMapSkinnedProgram->Compile();
m_ForwardPlusSplatMapSkinnedProgram->BindFragDataLocation(0, "sceneColor");
m_ForwardPlusSplatMapSkinnedProgram->BindFragDataLocation(1, "bloomColor");
@@ -184,6 +193,8 @@ void DrawFinalPass::Draw(RenderScene& scene)
GLERROR("OpaqueObjects");
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
//DrawStencilState* stencilState = new DrawStencilState(m_FinalPassFrameBuffer.GetHandle());
//Draw shields to stencil pass
@@ -312,7 +323,6 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO());
for (auto &job : jobs) {
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
if (explosionEffectJob) {
@@ -636,6 +646,55 @@ void DrawFinalPass::DrawToDepthBuffer(std::list<std::shared_ptr<RenderJob>>& job
}
void DrawFinalPass::DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, RenderScene& scene)
{
m_SpriteProgram->Bind();
GLuint shaderHandle = m_SpriteProgram->GetHandle();
for(auto& job : jobs) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
RenderState jobState;
if (spriteJob) {
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()));
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);
glActiveTexture(GL_TEXTURE0);
if (spriteJob->DiffuseTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, spriteJob->DiffuseTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_ErrorTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1);
if (spriteJob->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, spriteJob->IncandescenceTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
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)));
}
}
// m_SpriteProgram->Unbind();
}
void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<ExplosionEffectJob>& job, RenderScene& scene)
{
GLERROR("Bind 1 uniform");
@@ -891,7 +950,7 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptr<Model
//Bind 5 diffuse textures
std::string UniformName = "DiffuseUVRepeat";
for (unsigned int i = 0; i < 5; i++) {
for (unsigned int i = 0; i < 3; i++) {
glActiveTexture(texturePosition);
if (job->DiffuseTexture.size() > i && job->DiffuseTexture[i]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[i]->Texture->m_Texture);
@@ -905,7 +964,7 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptr<Model
//Bind 5 Normal textures
UniformName = "NormalUVRepeat";
for (unsigned int i = 0; i < 5; i++) {
for (unsigned int i = 0; i < 3; i++) {
glActiveTexture(texturePosition);
if (job->NormalTexture.size() > i && job->NormalTexture[i]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[i]->Texture->m_Texture);
@@ -919,7 +978,7 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptr<Model
//Bind 5 Specular textures
UniformName = "SpecularUVRepeat";
for (unsigned int i = 0; i < 5; i++) {
for (unsigned int i = 0; i < 3; i++) {
glActiveTexture(texturePosition);
if (job->SpecularTexture.size() > i && job->SpecularTexture[i]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[i]->Texture->m_Texture);
@@ -933,7 +992,7 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptr<Model
//Bind 5 Incandescence textures
UniformName = "GlowUVRepeat";
for (unsigned int i = 0; i < 5; i++) {
for (unsigned int i = 0; i < 3; i++) {
glActiveTexture(texturePosition);
if (job->IncandescenceTexture.size() > i && job->IncandescenceTexture[i]->Texture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[i]->Texture->m_Texture);