From 3467315aef38864dcd14cfc38cfbacce7cdd1fea Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Fri, 8 Jan 2016 16:42:59 +0100 Subject: [PATCH 1/9] Lots of things done --- include/Engine/Rendering/DrawScenePass.h | 6 ++ include/Engine/Rendering/RenderQueue.h | 11 +++ include/Engine/Rendering/RenderQueueFactory.h | 2 + include/Engine/Rendering/Renderer.h | 2 + resources/Schema/Components.xsd | 1 + resources/Schema/Components/CoolDeathAnim.xml | 5 + resources/Schema/Components/CoolDeathAnim.xsd | 24 +++++ resources/Schema/Entities/Test.xml | 7 +- resources/Schema/Types/Entity.xsd | 1 + resources/Shaders/CoolDeathAnim.frag.glsl | 22 +++++ resources/Shaders/CoolDeathAnim.geom.glsl | 98 +++++++++++++++++++ resources/Shaders/CoolDeathAnim.vert.glsl | 34 +++++++ src/Engine/Rendering/DrawScenePass.cpp | 60 ++++++++++-- src/Engine/Rendering/RenderQueueFactory.cpp | 52 +++++++--- src/Engine/Rendering/Renderer.cpp | 9 ++ 15 files changed, 312 insertions(+), 22 deletions(-) create mode 100644 resources/Schema/Components/CoolDeathAnim.xml create mode 100644 resources/Schema/Components/CoolDeathAnim.xsd create mode 100644 resources/Shaders/CoolDeathAnim.frag.glsl create mode 100644 resources/Shaders/CoolDeathAnim.geom.glsl create mode 100644 resources/Shaders/CoolDeathAnim.vert.glsl diff --git a/include/Engine/Rendering/DrawScenePass.h b/include/Engine/Rendering/DrawScenePass.h index 782c5a49..5e79ae0f 100644 --- a/include/Engine/Rendering/DrawScenePass.h +++ b/include/Engine/Rendering/DrawScenePass.h @@ -31,6 +31,12 @@ private: ShaderProgram* m_BasicForwardProgram; + ShaderProgram* m_CoolDeathAnimProgram; + + glm::vec3 Origin; + GLfloat TimeDeath = 0.f; + GLfloat EndDeath = 0.f; + }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 2942c743..af368b10 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -63,6 +63,17 @@ struct ModelJob : RenderJob } }; +// Cool Death Animation +struct CoolDeathAnimationJob : ModelJob +{ + glm::vec3 OriginPos; + float TimeSinceDeath = 0.f; + float EndOfDeath = 15.0f; + +}; + + + struct SpriteJob : RenderJob { unsigned int ShaderID = 0; diff --git a/include/Engine/Rendering/RenderQueueFactory.h b/include/Engine/Rendering/RenderQueueFactory.h index be2c55ca..e1a3507a 100644 --- a/include/Engine/Rendering/RenderQueueFactory.h +++ b/include/Engine/Rendering/RenderQueueFactory.h @@ -25,6 +25,8 @@ private: void FillModels(World* world, RenderQueue* renderQueue); void FillLights(World* world, RenderQueue* renderQueue); + void FillCoolDeathAnim(World* world, RenderQueue* renderQueue); + glm::mat4 ModelMatrix(World* world, EntityID entity); }; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index b4aae346..476ac9f9 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -119,6 +119,8 @@ private: ShaderProgram* m_CalculateFrustumProgram; ShaderProgram* m_LightCullProgram; + ShaderProgram* m_CoolDeathAnimProgram; + }; #endif \ No newline at end of file diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index fd04fd39..f95937ee 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -8,4 +8,5 @@ + \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xml b/resources/Schema/Components/CoolDeathAnim.xml new file mode 100644 index 00000000..36cdef98 --- /dev/null +++ b/resources/Schema/Components/CoolDeathAnim.xml @@ -0,0 +1,5 @@ + + + 0 + 15 + \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xsd b/resources/Schema/Components/CoolDeathAnim.xsd new file mode 100644 index 00000000..768be77a --- /dev/null +++ b/resources/Schema/Components/CoolDeathAnim.xsd @@ -0,0 +1,24 @@ + + + + + + + + A component that trigger the death effect + + + + + The position in which to spawn the component + + + Time since death + + + How long the death animation should be + + + + + \ No newline at end of file diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 528c7e95..329b511d 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -66,12 +66,17 @@ - + Models/Core/UnitRaptor.obj + + + 0 + 15 + diff --git a/resources/Schema/Types/Entity.xsd b/resources/Schema/Types/Entity.xsd index 92f7dc31..b321d7da 100644 --- a/resources/Schema/Types/Entity.xsd +++ b/resources/Schema/Types/Entity.xsd @@ -15,6 +15,7 @@ + diff --git a/resources/Shaders/CoolDeathAnim.frag.glsl b/resources/Shaders/CoolDeathAnim.frag.glsl new file mode 100644 index 00000000..aa13a18f --- /dev/null +++ b/resources/Shaders/CoolDeathAnim.frag.glsl @@ -0,0 +1,22 @@ +#version 430 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; +uniform vec4 Color; + +uniform sampler2D texture0; + +in vec3 Normal; +in vec3 Position; +in vec2 TextureCoordinate; +in vec4 DiffuseColor; + +out vec4 fragmentColor; + + +void main() +{ + vec4 texel = texture2D(texture0, TextureCoordinate); + fragmentColor = texel * DiffuseColor * Color; +} \ No newline at end of file diff --git a/resources/Shaders/CoolDeathAnim.geom.glsl b/resources/Shaders/CoolDeathAnim.geom.glsl new file mode 100644 index 00000000..3bf80a7f --- /dev/null +++ b/resources/Shaders/CoolDeathAnim.geom.glsl @@ -0,0 +1,98 @@ +#version 430 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; +uniform vec3 OriginPos; +uniform float TimeSinceDeath; +uniform float EndOfDeath; + +in VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; + vec4 DiffuseColor; +}Input[]; + +out vec3 Normal; +out vec3 Position; +out vec2 TextureCoordinate; +out vec4 DiffuseColor; + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +void main() +{ + // surface vectors for triangle + //vec3 v1 = Input[1].Position - Input[0].Position; + //vec3 v2 = Input[2].Position - Input[0].Position; + + //vec3 v3 = Input[1].Position - OriginPos; + //v3 = normalize(v3); + + // surface normal + //vec3 normal = cross(v1, v2); + //normal = normalize(normal); + + // calculate middle of a vectors + vec3 v1 = Input[1].Position - Input[0].Position; + vec3 v2 = Input[2].Position - Input[0].Position; + vec3 v3 = Input[2].Position - (v1 / 2); + vec3 v4 = Input[1].Position - (v2 / 2); + + // + //vec3 oriToTri = Input[1].Position - OriginPos; + //v5 = normalize(v3); + + + // calculate intersection + // normalize direction + vec3 dir1 = normalize(v1); + vec3 dir2 = normalize(v2); + + vec3 vecA = Input[2].Position - Input[1].Position; //o2 - o1 + vec3 vecB = cross(dir1, dir2); + + mat3 matrisA = mat3(vecA, dir2, vecB); + mat3 matrisB = mat3(vecA, dir1, vecB); + + float lengthA = length(cross(dir1, dir2)); + lengthA = lengthA * lengthA; + + float s = determinant(matrisA) / lengthA; + float t = determinant(matrisB) / lengthA; + + // center position of triangle + vec3 centerPosS = Input[1].Position + (s * dir1); + //vec3 centerPosT = Input[2].Position + (t * dir2); + + + // center position of triangle to origin + vec3 oriToCenterTri = normalize(centerPosS - OriginPos); + + for(int i = 0; i < gl_in.length(); i++) + { + vec4 screenPos = gl_in[i].gl_Position; + + if (distance(OriginPos, Input[0].Position) <= TimeSinceDeath) + { + vec4 changedPos = M * vec4(Input[i].Position + (oriToCenterTri * TimeSinceDeath), 1.0); //objectspace + changedPos = vec4(changedPos.x, changedPos.y - pow(TimeSinceDeath, 2), changedPos.z, changedPos.w); //objectspace + screenPos = P*V * changedPos; //sceenspace + } + // Explosion from origin + + + + Normal = Input[i].Normal; + Position = Input[i].Position; + TextureCoordinate = Input[i].TextureCoordinate; + DiffuseColor = vec4(Input[i].DiffuseColor.rg, Input[i].DiffuseColor.b + TimeSinceDeath, Input[i].DiffuseColor.a); + + gl_Position = screenPos; + //gl_Position = gl_in[i].gl_Position; + EmitVertex(); + } + +} \ No newline at end of file diff --git a/resources/Shaders/CoolDeathAnim.vert.glsl b/resources/Shaders/CoolDeathAnim.vert.glsl new file mode 100644 index 00000000..20ab9051 --- /dev/null +++ b/resources/Shaders/CoolDeathAnim.vert.glsl @@ -0,0 +1,34 @@ +#version 430 + +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; + +layout(location = 0) in vec3 Position; +layout(location = 1) in vec3 Normal; +layout(location = 2) in vec3 Tangent; +layout(location = 3) in vec3 BiTangent; +layout(location = 4) in vec2 TextureCoords; +layout(location = 5) in vec4 DiffuseVertexColor; +layout(location = 6) in vec4 SpecularVertexColor; +layout(location = 7) in vec4 BoneIndices1; +layout(location = 8) in vec4 BoneIndices2; +layout(location = 9) in vec4 BoneWeights1; +layout(location = 10) in vec4 BoneWeights2; + +out VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; + vec4 DiffuseColor; +}Output; + +void main() +{ + gl_Position = P*V*M * vec4(Position, 1.0); + + Output.Position = Position; + Output.TextureCoordinate = TextureCoords; + Output.Normal = Normal; + Output.DiffuseColor = DiffuseVertexColor; +} \ No newline at end of file diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index 559a0f58..5e48e8f8 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -16,18 +16,32 @@ void DrawScenePass::InitializeShaderPrograms() { //Gör så att shaders är en resource, tex som texture classen. Konstruktorn måste vara privat. m_BasicForwardProgram = ResourceManager::Load("#BasicForwardProgram"); - m_BasicForwardProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/BasicForward.vert.glsl"))); m_BasicForwardProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/BasicForward.frag.glsl"))); m_BasicForwardProgram->Compile(); m_BasicForwardProgram->Link(); - + m_CoolDeathAnimProgram = ResourceManager::Load("#CoolDeathAnimProgram"); + m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/CoolDeathAnim.vert.glsl"))); + m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/CoolDeathAnim.geom.glsl"))); + m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/CoolDeathAnim.frag.glsl"))); + m_CoolDeathAnimProgram->Compile(); + m_CoolDeathAnimProgram->Link(); + } void DrawScenePass::Draw(RenderQueueCollection& rq) { - //glBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (TimeDeath > 2.f) { + TimeDeath = 0.f; + } + + Origin = glm::vec3(0.f, 0.0f, 0.f); + TimeDeath = TimeDeath + 0.01f; + EndDeath = EndDeath + 0.05f; + + glBindFramebuffer(GL_FRAMEBUFFER, 0); GLERROR("Renderer::Draw PickingPass"); DrawScenePassState state; @@ -35,17 +49,47 @@ void DrawScenePass::Draw(RenderQueueCollection& rq) //TODO: Render: Add code for more jobs than modeljobs. for (auto &job : rq.Forward) { + auto coolDeathAnimationJob = std::dynamic_pointer_cast(job); + if (coolDeathAnimationJob) { + GLuint ShaderHandle = m_CoolDeathAnimProgram->GetHandle(); //--- + //--- + m_CoolDeathAnimProgram->Bind(); + //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(coolDeathAnimationJob->ModelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); + glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color)); + glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(Origin)); + glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), TimeDeath); + glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), EndDeath); + + //TODO: Renderer: bättre textur felhantering samt fler texturer stöd + if (coolDeathAnimationJob->DiffuseTexture != nullptr) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, coolDeathAnimationJob->DiffuseTexture->m_Texture); + } else { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } + glBindVertexArray(coolDeathAnimationJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, coolDeathAnimationJob->Model->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, coolDeathAnimationJob->EndIndex - coolDeathAnimationJob->StartIndex + 1, GL_UNSIGNED_INT, 0, coolDeathAnimationJob->StartIndex); + continue; + } + auto modelJob = std::dynamic_pointer_cast(job); if (modelJob) { - GLuint ShaderHandle = m_BasicForwardProgram->GetHandle(); - + GLuint ShaderHandle = m_BasicForwardProgram->GetHandle(); //--- + GLERROR("1"); + //--- m_BasicForwardProgram->Bind(); + GLERROR("2.1"); //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); - + GLERROR("2"); //TODO: Renderer: bättre textur felhantering samt fler texturer stöd if (modelJob->DiffuseTexture != nullptr) { glActiveTexture(GL_TEXTURE0); @@ -54,11 +98,11 @@ void DrawScenePass::Draw(RenderQueueCollection& rq) glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } - + GLERROR("3"); glBindVertexArray(modelJob->Model->VAO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); - + GLERROR("4"); continue; } } diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index 8d5bb420..53c8c6d9 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -90,21 +90,47 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) } for (auto texGroup : model->TextureGroups) { - ModelJob job; - job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; - job.DiffuseTexture = texGroup.Texture.get(); - job.NormalTexture = texGroup.NormalMap.get(); - job.SpecularTexture = texGroup.SpecularMap.get(); - job.Model = model; - job.StartIndex = texGroup.StartIndex; - job.EndIndex = texGroup.EndIndex; - job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID); - job.Color = color; + auto deathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim"); + if (!deathComp) { + ModelJob job; - //TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this - job.Entity = modelC.EntityID; + job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; + job.DiffuseTexture = texGroup.Texture.get(); + job.NormalTexture = texGroup.NormalMap.get(); + job.SpecularTexture = texGroup.SpecularMap.get(); + job.Model = model; + job.StartIndex = texGroup.StartIndex; + job.EndIndex = texGroup.EndIndex; + job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID); + job.Color = color; - renderQueue->Add(job); + //TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this + job.Entity = modelC.EntityID; + + renderQueue->Add(job); + } + else { + CoolDeathAnimationJob job; + + job.TimeSinceDeath = 1.f; + job.EndOfDeath = 15.f; + job.OriginPos = glm::vec3(1000.f, 2.f, 0.f); + + job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; + job.DiffuseTexture = texGroup.Texture.get(); + job.NormalTexture = texGroup.NormalMap.get(); + job.SpecularTexture = texGroup.SpecularMap.get(); + job.Model = model; + job.StartIndex = texGroup.StartIndex; + job.EndIndex = texGroup.EndIndex; + job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID); + job.Color = color; + + //TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this + job.Entity = modelC.EntityID; + + renderQueue->Add(job); + } } } } diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index 21ff6c5a..e96d3df3 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -76,6 +76,15 @@ void Renderer::InitializeShaders() m_DrawScreenQuadProgram->Compile(); m_DrawScreenQuadProgram->Link(); + m_CoolDeathAnimProgram = ResourceManager::Load("#CoolDeathAnimProgram"); + //m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/CoolDeathAnim.vert.glsl"))); + //m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/CoolDeathAnim.geom.glsl"))); + //m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/CoolDeathAnim.frag.glsl"))); + //m_CoolDeathAnimProgram->Compile(); + //m_CoolDeathAnimProgram->Link(); + + + //m_CalculateFrustumProgram = ResourceManager::Load("#CalculateFrustumProgram"); //m_CalculateFrustumProgram.AddShader(std::shared_ptr(new ComputeShader("Shaders/GridFrustum.comp.glsl"))); //m_CalculateFrustumProgram.Compile(); From 0630885d9201f9755b7acc5a717292ce44d7f911 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Mon, 11 Jan 2016 19:59:45 +0100 Subject: [PATCH 2/9] Many more things done --- include/Engine/Common.h | 1 + include/Engine/Rendering/DrawScenePass.h | 5 -- include/Engine/Rendering/RenderQueue.h | 15 +++-- include/Game/CoolDeathAnimationSystem.h | 20 +++++++ include/Game/Game.h | 1 + resources/Schema/Components/CoolDeathAnim.xml | 8 ++- resources/Schema/Components/CoolDeathAnim.xsd | 18 ++++++ resources/Schema/Entities/Test.xml | 8 ++- resources/Shaders/CoolDeathAnim.frag.glsl | 3 +- resources/Shaders/CoolDeathAnim.geom.glsl | 57 ++++++++++++++++--- src/Engine/Rendering/DrawScenePass.cpp | 24 ++++---- src/Engine/Rendering/RenderQueueFactory.cpp | 29 ++++++++-- src/Game/Game.cpp | 1 + 13 files changed, 153 insertions(+), 37 deletions(-) create mode 100644 include/Game/CoolDeathAnimationSystem.h diff --git a/include/Engine/Common.h b/include/Engine/Common.h index ebdc90d0..4453cec5 100644 --- a/include/Engine/Common.h +++ b/include/Engine/Common.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "Core/Util/Logging.h" #include "Core/Util/IfDebug.h" \ No newline at end of file diff --git a/include/Engine/Rendering/DrawScenePass.h b/include/Engine/Rendering/DrawScenePass.h index 5e79ae0f..516759f2 100644 --- a/include/Engine/Rendering/DrawScenePass.h +++ b/include/Engine/Rendering/DrawScenePass.h @@ -32,11 +32,6 @@ private: ShaderProgram* m_BasicForwardProgram; ShaderProgram* m_CoolDeathAnimProgram; - - glm::vec3 Origin; - GLfloat TimeDeath = 0.f; - GLfloat EndDeath = 0.f; - }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index af368b10..8c6195f9 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -67,13 +67,18 @@ struct ModelJob : RenderJob struct CoolDeathAnimationJob : ModelJob { glm::vec3 OriginPos; - float TimeSinceDeath = 0.f; - float EndOfDeath = 15.0f; - + double TimeSinceDeath = 0.f; + double EndOfDeath = 2.f; + bool Gravity = true; + double GravityForce = 1.f; // Speed + double ObjectRadius = 2.f; // TODO: Change this for object radius when it's available + glm::vec4 EndColor; + bool UseRandomness = false; + std::array RandomNumbers; + float RandomnessScalar = 1.f; + float Acceleration = 0.f; }; - - struct SpriteJob : RenderJob { unsigned int ShaderID = 0; diff --git a/include/Game/CoolDeathAnimationSystem.h b/include/Game/CoolDeathAnimationSystem.h new file mode 100644 index 00000000..09d7b9e3 --- /dev/null +++ b/include/Game/CoolDeathAnimationSystem.h @@ -0,0 +1,20 @@ +#include "Common.h" +#include "Core/System.h" + +class CoolDeathAnimationSystem : public PureSystem +{ +public: + CoolDeathAnimationSystem(EventBroker* eventBroker) + : PureSystem(eventBroker, "CoolDeathAnim") + { } + + virtual void UpdateComponent(World* world, ComponentWrapper& object, double dt) override + { + ComponentWrapper& Component = world->GetComponent(object.EntityID, "CoolDeathAnim"); + + if ((double)Component["TimeSinceDeath"] > (double)Component["EndOfDeath"]) { + (double)Component["TimeSinceDeath"] = 0.f; + } + (double&)Component["TimeSinceDeath"] += dt; + } +}; \ No newline at end of file diff --git a/include/Game/Game.h b/include/Game/Game.h index 33dc88a6..900b7aec 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -16,6 +16,7 @@ #include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" #include "RaptorCopterSystem.h" +#include "CoolDeathAnimationSystem.h" #include "PlayerSystem.h" #include "Editor/EditorSystem.h" diff --git a/resources/Schema/Components/CoolDeathAnim.xml b/resources/Schema/Components/CoolDeathAnim.xml index 36cdef98..069da9eb 100644 --- a/resources/Schema/Components/CoolDeathAnim.xml +++ b/resources/Schema/Components/CoolDeathAnim.xml @@ -1,5 +1,11 @@ 0 - 15 + 2 + 1 + 1 + 2 + + 0 + 1 \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xsd b/resources/Schema/Components/CoolDeathAnim.xsd index 768be77a..726d1ba6 100644 --- a/resources/Schema/Components/CoolDeathAnim.xsd +++ b/resources/Schema/Components/CoolDeathAnim.xsd @@ -18,6 +18,24 @@ How long the death animation should be + + Enable/disable gravity + + + The force of the gravity + + + Object radius (TO BE REMOVED AND AUTOMATED) + + + The tint the polys end with + + + Add some randomness to the explosion + + + Alter the power of the randomness + diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 329b511d..1e73420a 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -75,7 +75,13 @@ 0 - 15 + 2 + 1 + 1 + 2 + + 0 + 1 diff --git a/resources/Shaders/CoolDeathAnim.frag.glsl b/resources/Shaders/CoolDeathAnim.frag.glsl index aa13a18f..9108aa81 100644 --- a/resources/Shaders/CoolDeathAnim.frag.glsl +++ b/resources/Shaders/CoolDeathAnim.frag.glsl @@ -11,6 +11,7 @@ in vec3 Normal; in vec3 Position; in vec2 TextureCoordinate; in vec4 DiffuseColor; +in vec4 ExplosionColor; out vec4 fragmentColor; @@ -18,5 +19,5 @@ out vec4 fragmentColor; void main() { vec4 texel = texture2D(texture0, TextureCoordinate); - fragmentColor = texel * DiffuseColor * Color; + fragmentColor = texel * DiffuseColor * Color + ExplosionColor; } \ No newline at end of file diff --git a/resources/Shaders/CoolDeathAnim.geom.glsl b/resources/Shaders/CoolDeathAnim.geom.glsl index 3bf80a7f..460776c1 100644 --- a/resources/Shaders/CoolDeathAnim.geom.glsl +++ b/resources/Shaders/CoolDeathAnim.geom.glsl @@ -6,6 +6,13 @@ uniform mat4 P; uniform vec3 OriginPos; uniform float TimeSinceDeath; uniform float EndOfDeath; +uniform bool Gravity; +uniform float GravityForce; +uniform float ObjectRadius; +uniform vec4 EndColor; +uniform bool UseRandomness; +uniform float RandomNumbers[10]; +uniform float RandomnessScalar; in VertexData{ vec3 Position; @@ -18,6 +25,7 @@ out vec3 Normal; out vec3 Position; out vec2 TextureCoordinate; out vec4 DiffuseColor; +out vec4 ExplosionColor; layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; @@ -71,24 +79,59 @@ void main() // center position of triangle to origin vec3 oriToCenterTri = normalize(centerPosS - OriginPos); + float dist = distance(OriginPos, centerPosS); + + // The distance a polygon will travel under one second. + float travelUnitS = EndOfDeath / ObjectRadius; + + // The distance a polygon will travel under the current frame. + float travelUnitF = TimeSinceDeath * travelUnitS; + + float randomness = 0.0f; + int randomIndex = int(mod(gl_PrimitiveIDIn, 10)); + + // Explosion from origin for(int i = 0; i < gl_in.length(); i++) { + //gl_in.gl_PrimitiveIDIn; + + if (UseRandomness == true) + { + switch (randomIndex) + { + case 0: randomness = RandomNumbers[0]; break; + case 1: randomness = RandomNumbers[1]; break; + case 2: randomness = RandomNumbers[2]; break; + case 3: randomness = RandomNumbers[3]; break; + case 4: randomness = RandomNumbers[4]; break; + case 5: randomness = RandomNumbers[5]; break; + case 6: randomness = RandomNumbers[6]; break; + case 7: randomness = RandomNumbers[7]; break; + case 8: randomness = RandomNumbers[8]; break; + case 9: randomness = RandomNumbers[9]; break; + } + } + + float fullRandomness = dist + (randomness * RandomnessScalar); + vec4 screenPos = gl_in[i].gl_Position; - if (distance(OriginPos, Input[0].Position) <= TimeSinceDeath) + //if (dist + fullRandomness <= travelUnitF) + if (fullRandomness <= travelUnitF) { - vec4 changedPos = M * vec4(Input[i].Position + (oriToCenterTri * TimeSinceDeath), 1.0); //objectspace - changedPos = vec4(changedPos.x, changedPos.y - pow(TimeSinceDeath, 2), changedPos.z, changedPos.w); //objectspace + vec4 changedPos = M * vec4(Input[i].Position + (oriToCenterTri * travelUnitF) - (oriToCenterTri * fullRandomness), 1.0); //objectspace + if (Gravity == true) + { + changedPos.y = changedPos.y - pow((travelUnitF - fullRandomness) * GravityForce, 2); + } screenPos = P*V * changedPos; //sceenspace } - // Explosion from origin - - Normal = Input[i].Normal; Position = Input[i].Position; TextureCoordinate = Input[i].TextureCoordinate; - DiffuseColor = vec4(Input[i].DiffuseColor.rg, Input[i].DiffuseColor.b + TimeSinceDeath, Input[i].DiffuseColor.a); + DiffuseColor = Input[i].DiffuseColor; + ExplosionColor = EndColor * travelUnitF; gl_Position = screenPos; //gl_Position = gl_in[i].gl_Position; diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index 5e48e8f8..454c1338 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -33,14 +33,6 @@ void DrawScenePass::InitializeShaderPrograms() void DrawScenePass::Draw(RenderQueueCollection& rq) { - if (TimeDeath > 2.f) { - TimeDeath = 0.f; - } - - Origin = glm::vec3(0.f, 0.0f, 0.f); - TimeDeath = TimeDeath + 0.01f; - EndDeath = EndDeath + 0.05f; - glBindFramebuffer(GL_FRAMEBUFFER, 0); GLERROR("Renderer::Draw PickingPass"); @@ -52,16 +44,24 @@ void DrawScenePass::Draw(RenderQueueCollection& rq) auto coolDeathAnimationJob = std::dynamic_pointer_cast(job); if (coolDeathAnimationJob) { GLuint ShaderHandle = m_CoolDeathAnimProgram->GetHandle(); //--- - //--- + m_CoolDeathAnimProgram->Bind(); //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(coolDeathAnimationJob->ModelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color)); - glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(Origin)); - glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), TimeDeath); - glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), EndDeath); + glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(coolDeathAnimationJob->OriginPos)); + glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), coolDeathAnimationJob->TimeSinceDeath); + glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), coolDeathAnimationJob->EndOfDeath); + glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), coolDeathAnimationJob->Gravity); + glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), coolDeathAnimationJob->GravityForce); + glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), coolDeathAnimationJob->ObjectRadius); + glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(coolDeathAnimationJob->EndColor)); + glUniform1i(glGetUniformLocation(ShaderHandle, "UseRandomness"), coolDeathAnimationJob->UseRandomness); + glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 10, coolDeathAnimationJob->RandomNumbers.data()); + glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), coolDeathAnimationJob->RandomnessScalar); + //TODO: Renderer: bättre textur felhantering samt fler texturer stöd if (coolDeathAnimationJob->DiffuseTexture != nullptr) { diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index 53c8c6d9..f9a8630d 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -90,8 +90,8 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) } for (auto texGroup : model->TextureGroups) { - auto deathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim"); - if (!deathComp) { + bool hasDeathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim"); + if (!hasDeathComp) { ModelJob job; job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; @@ -112,9 +112,28 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) else { CoolDeathAnimationJob job; - job.TimeSinceDeath = 1.f; - job.EndOfDeath = 15.f; - job.OriginPos = glm::vec3(1000.f, 2.f, 0.f); + auto deathComp = world->GetComponent(modelC.EntityID, "CoolDeathAnim"); + + job.OriginPos = (glm::vec3)deathComp["OriginPos"]; + job.TimeSinceDeath = (double)deathComp["TimeSinceDeath"]; + job.EndOfDeath = (double)deathComp["EndOfDeath"]; + job.Gravity = (bool)deathComp["Gravity"]; + job.GravityForce = (double)deathComp["GravityForce"]; + job.ObjectRadius = (double)deathComp["ObjectRadius"]; + job.EndColor = (glm::vec4)deathComp["EndColor"]; + job.UseRandomness = (bool)deathComp["UseRandomness"]; + job.RandomnessScalar = (double)deathComp["RandomnessScalar"]; + job.RandomNumbers = { + 0.3257552917701f, + 0.07601508315467f, + 0.57408909014151f, + 0.0f, + 0.8618231368539f, + 0.074957156588769f, + 0.39413607511396f, + 0.54579346698979f, + 0.83222648353885f, + 0.83635707285086f }; job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; job.DiffuseTexture = texGroup.Texture.get(); diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index f1582d5d..fdc22db2 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -57,6 +57,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(m_Renderer); m_SystemPipeline->AddSystem(); m_SystemPipeline->AddSystem(); + m_SystemPipeline->AddSystem(); // Invoke network if (m_Config->Get("Networking.StartNetwork", false)) { From 00eeed2e202b3b2199256ee90acb927208f043bf Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Tue, 12 Jan 2016 16:16:42 +0100 Subject: [PATCH 3/9] Broken stuff, refactoring --- include/Engine/Rendering/RenderQueue.h | 15 +- include/Game/CoolDeathAnimationSystem.h | 2 +- resources/Schema/Components/CoolDeathAnim.xml | 10 +- resources/Schema/Components/CoolDeathAnim.xsd | 22 +- resources/Schema/Entities/Test.xml | 10 +- resources/Shaders/CoolDeathAnim.geom.glsl | 235 ++++++++++++------ src/Engine/Rendering/DrawScenePass.cpp | 14 +- src/Engine/Rendering/RenderQueueFactory.cpp | 22 +- 8 files changed, 229 insertions(+), 101 deletions(-) diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 8c6195f9..942edf07 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -66,17 +66,20 @@ struct ModelJob : RenderJob // Cool Death Animation struct CoolDeathAnimationJob : ModelJob { - glm::vec3 OriginPos; - double TimeSinceDeath = 0.f; - double EndOfDeath = 2.f; + glm::vec3 ExplosionOrigin; + double TimeSinceDeath = 0.f; //Seconds + double ExplosionDuration = 2.f; bool Gravity = true; double GravityForce = 1.f; // Speed double ObjectRadius = 2.f; // TODO: Change this for object radius when it's available glm::vec4 EndColor; - bool UseRandomness = false; - std::array RandomNumbers; + bool Randomness = false; + std::array RandomNumbers; float RandomnessScalar = 1.f; - float Acceleration = 0.f; + glm::vec2 Acceleration; + bool ColorPerPolygon = false; + bool ReverseAnimation = false; + bool Wireframe = false; }; struct SpriteJob : RenderJob diff --git a/include/Game/CoolDeathAnimationSystem.h b/include/Game/CoolDeathAnimationSystem.h index 09d7b9e3..adbdd067 100644 --- a/include/Game/CoolDeathAnimationSystem.h +++ b/include/Game/CoolDeathAnimationSystem.h @@ -12,7 +12,7 @@ public: { ComponentWrapper& Component = world->GetComponent(object.EntityID, "CoolDeathAnim"); - if ((double)Component["TimeSinceDeath"] > (double)Component["EndOfDeath"]) { + if ((double)Component["TimeSinceDeath"] > (double)Component["ExplosionDuration"]) { (double)Component["TimeSinceDeath"] = 0.f; } (double&)Component["TimeSinceDeath"] += dt; diff --git a/resources/Schema/Components/CoolDeathAnim.xml b/resources/Schema/Components/CoolDeathAnim.xml index 069da9eb..b0df7b73 100644 --- a/resources/Schema/Components/CoolDeathAnim.xml +++ b/resources/Schema/Components/CoolDeathAnim.xml @@ -1,11 +1,15 @@ - + 0 - 2 + 2 1 1 2 - 0 + 0 1 + + 0 + 0 + 0 \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xsd b/resources/Schema/Components/CoolDeathAnim.xsd index 726d1ba6..a44c9acc 100644 --- a/resources/Schema/Components/CoolDeathAnim.xsd +++ b/resources/Schema/Components/CoolDeathAnim.xsd @@ -9,14 +9,14 @@ - + The position in which to spawn the component - Time since death + Seconds since death - - How long the death animation should be + + How many seconds the death animation should be Enable/disable gravity @@ -30,12 +30,24 @@ The tint the polys end with - + Add some randomness to the explosion Alter the power of the randomness + + The accelaration factors (start/end) + + + Change the color per polygon + + + Implosions are cooler + + + Enable/disable wireframe + diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 1e73420a..85f31b82 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -73,15 +73,19 @@ - + 0 - 2 + 2 1 1 2 - 0 + 0 1 + + 0 + 0 + 0 diff --git a/resources/Shaders/CoolDeathAnim.geom.glsl b/resources/Shaders/CoolDeathAnim.geom.glsl index 460776c1..b2d346c8 100644 --- a/resources/Shaders/CoolDeathAnim.geom.glsl +++ b/resources/Shaders/CoolDeathAnim.geom.glsl @@ -3,16 +3,20 @@ uniform mat4 M; uniform mat4 V; uniform mat4 P; -uniform vec3 OriginPos; +uniform vec3 ExplosionOrigin; uniform float TimeSinceDeath; -uniform float EndOfDeath; +uniform float ExplosionDuration; uniform bool Gravity; uniform float GravityForce; uniform float ObjectRadius; uniform vec4 EndColor; -uniform bool UseRandomness; -uniform float RandomNumbers[10]; +uniform bool Randomness; +uniform float RandomNumbers[20]; uniform float RandomnessScalar; +uniform vec2 Accelaration; +uniform bool ColorPerPolygon; +uniform bool ReverseAnimation; +uniform bool Wireframe; in VertexData{ vec3 Position; @@ -30,31 +34,45 @@ out vec4 ExplosionColor; layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; +float GetRandomNumber(int polygon_index) +{ + int randomIndex = int(mod(polygon_index, 20)); + + switch (randomIndex) + { + case 0: return RandomNumbers[0]; + case 1: return RandomNumbers[1]; + case 2: return RandomNumbers[2]; + case 3: return RandomNumbers[3]; + case 4: return RandomNumbers[4]; + case 5: return RandomNumbers[5]; + case 6: return RandomNumbers[6]; + case 7: return RandomNumbers[7]; + case 8: return RandomNumbers[8]; + case 9: return RandomNumbers[9]; + case 10: return RandomNumbers[10]; + case 11: return RandomNumbers[11]; + case 12: return RandomNumbers[12]; + case 13: return RandomNumbers[13]; + case 14: return RandomNumbers[14]; + case 15: return RandomNumbers[15]; + case 16: return RandomNumbers[16]; + case 17: return RandomNumbers[17]; + case 18: return RandomNumbers[18]; + case 19: return RandomNumbers[19]; + } +} + void main() { - // surface vectors for triangle - //vec3 v1 = Input[1].Position - Input[0].Position; - //vec3 v2 = Input[2].Position - Input[0].Position; - - //vec3 v3 = Input[1].Position - OriginPos; - //v3 = normalize(v3); - - // surface normal - //vec3 normal = cross(v1, v2); - //normal = normalize(normal); - - // calculate middle of a vectors + // calculate middle of vectors vec3 v1 = Input[1].Position - Input[0].Position; vec3 v2 = Input[2].Position - Input[0].Position; vec3 v3 = Input[2].Position - (v1 / 2); vec3 v4 = Input[1].Position - (v2 / 2); - // - //vec3 oriToTri = Input[1].Position - OriginPos; - //v5 = normalize(v3); - - // calculate intersection + // normalize direction vec3 dir1 = normalize(v1); vec3 dir2 = normalize(v2); @@ -63,79 +81,146 @@ void main() vec3 vecB = cross(dir1, dir2); mat3 matrisA = mat3(vecA, dir2, vecB); - mat3 matrisB = mat3(vecA, dir1, vecB); float lengthA = length(cross(dir1, dir2)); lengthA = lengthA * lengthA; float s = determinant(matrisA) / lengthA; - float t = determinant(matrisB) / lengthA; // center position of triangle - vec3 centerPosS = Input[1].Position + (s * dir1); - //vec3 centerPosT = Input[2].Position + (t * dir2); + vec3 centerOfTriangle = Input[1].Position + (s * dir1); + + // center position of triangle to origin vector + vec3 origin2TriangleCenterVector = normalize(centerOfTriangle - ExplosionOrigin); + + // time percentage until end of explosion + float timePercetage = TimeSinceDeath / ExplosionDuration; + + float currentAccelaration = mix(Accelaration.x, Accelaration.y, timePercetage); + + //float TimeSinceDeath2; + + //if (ReverseAnimation == true) + //{ + // TimeSinceDeath2 = pow(TimeSinceDeath, -1); + //} + //else + //{ + // TimeSinceDeath2 = TimeSinceDeath; + //} + + float origin2TriangleCenterDistance = distance(ExplosionOrigin, centerOfTriangle); - // center position of triangle to origin - vec3 oriToCenterTri = normalize(centerPosS - OriginPos); - float dist = distance(OriginPos, centerPosS); + + + + + // The distance a polygon will travel under one second. - float travelUnitS = EndOfDeath / ObjectRadius; + float travelUnitS = ExplosionDuration / ObjectRadius; // The distance a polygon will travel under the current frame. float travelUnitF = TimeSinceDeath * travelUnitS; - float randomness = 0.0f; - int randomIndex = int(mod(gl_PrimitiveIDIn, 10)); - // Explosion from origin - for(int i = 0; i < gl_in.length(); i++) - { - //gl_in.gl_PrimitiveIDIn; + + - if (UseRandomness == true) - { - switch (randomIndex) - { - case 0: randomness = RandomNumbers[0]; break; - case 1: randomness = RandomNumbers[1]; break; - case 2: randomness = RandomNumbers[2]; break; - case 3: randomness = RandomNumbers[3]; break; - case 4: randomness = RandomNumbers[4]; break; - case 5: randomness = RandomNumbers[5]; break; - case 6: randomness = RandomNumbers[6]; break; - case 7: randomness = RandomNumbers[7]; break; - case 8: randomness = RandomNumbers[8]; break; - case 9: randomness = RandomNumbers[9]; break; - } - } - - float fullRandomness = dist + (randomness * RandomnessScalar); - - vec4 screenPos = gl_in[i].gl_Position; - - //if (dist + fullRandomness <= travelUnitF) - if (fullRandomness <= travelUnitF) - { - vec4 changedPos = M * vec4(Input[i].Position + (oriToCenterTri * travelUnitF) - (oriToCenterTri * fullRandomness), 1.0); //objectspace - if (Gravity == true) - { - changedPos.y = changedPos.y - pow((travelUnitF - fullRandomness) * GravityForce, 2); - } - screenPos = P*V * changedPos; //sceenspace - } - Normal = Input[i].Normal; - Position = Input[i].Position; - TextureCoordinate = Input[i].TextureCoordinate; - DiffuseColor = Input[i].DiffuseColor; - ExplosionColor = EndColor * travelUnitF; - - gl_Position = screenPos; - //gl_Position = gl_in[i].gl_Position; - EmitVertex(); + + + + + + + float randomNumber = 0.0; + + if (Randomness == true) + { + randomNumber = GetRandomNumber(gl_PrimitiveIDIn); } + float fullDistanceWithRandomness = origin2TriangleCenterDistance + (randomNumber * RandomnessScalar); + + vec3 ExplosionRadius = (origin2TriangleCenterVector * (TimeSinceDeath /** currentAccelaration*/)) - (origin2TriangleCenterVector * fullDistanceWithRandomness); + + vec4 screenPos; + + if (fullDistanceWithRandomness <= TimeSinceDeath) + { + for(int i = 0; i < gl_in.length(); i++) + { + screenPos = gl_in[i].gl_Position; + + vec3 ExplodedPosition = Input[i].Position + ExplosionRadius; + + Normal = Input[i].Normal; + Position = Input[i].Position; + TextureCoordinate = Input[i].TextureCoordinate; + DiffuseColor = Input[i].DiffuseColor; + + ExplosionColor = EndColor * timePercetage; + + gl_Position = P*V*M * vec4(ExplodedPosition, 1.0); + EmitVertex(); + } + } + else + { + for(int i = 0; i < gl_in.length(); i++) + { + screenPos = gl_in[i].gl_Position; + + Normal = Input[i].Normal; + Position = Input[i].Position; + TextureCoordinate = Input[i].TextureCoordinate; + DiffuseColor = Input[i].DiffuseColor; + + ExplosionColor = EndColor; + + gl_Position = screenPos; + EmitVertex(); + } + } + + //// Explosion from origin + //for(int i = 0; i < gl_in.length(); i++) + //{ + // vec4 screenPos = gl_in[i].gl_Position; + // + // if (fullRandomness <= travelUnitF) + // { + // maXimum = (origin2TriangleCenterVector * travelUnitF) - (origin2TriangleCenterVector * fullRandomness); + // vec3 movedPosition = vec3(Input[i].Position + maXimum); + // + // vec4 changedPos = M * vec4(movedPosition, 1.0); //objectspace + // if (Gravity == true) + // { + // changedPos.y = changedPos.y - pow((travelUnitF - fullRandomness) * GravityForce, 2); + // } + // screenPos = P*V * changedPos; //sceenspace + // } + // + // Normal = Input[i].Normal; + // Position = Input[i].Position; + // TextureCoordinate = Input[i].TextureCoordinate; + // DiffuseColor = Input[i].DiffuseColor; + // if (ColorPerPolygon == false) + // { + // ExplosionColor = EndColor * travelUnitF; + // } + // else + // { + // vec3 movedCenterPos = vec3(centerOfTriangle + maXimum); + // ExplosionColor = EndColor * (distance(ExplosionOrigin, movedCenterPos) - distance(ExplosionOrigin, centerOfTriangle)); + // } + // + // gl_Position = screenPos; + // //gl_Position = gl_in[i].gl_Position; + // EmitVertex(); + //} + } \ No newline at end of file diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index 454c1338..fb791cea 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -51,16 +51,22 @@ void DrawScenePass::Draw(RenderQueueCollection& rq) glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color)); - glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(coolDeathAnimationJob->OriginPos)); + glUniform3fv(glGetUniformLocation(ShaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(coolDeathAnimationJob->ExplosionOrigin)); glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), coolDeathAnimationJob->TimeSinceDeath); - glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), coolDeathAnimationJob->EndOfDeath); + glUniform1f(glGetUniformLocation(ShaderHandle, "ExplosionDuration"), coolDeathAnimationJob->ExplosionDuration); glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), coolDeathAnimationJob->Gravity); glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), coolDeathAnimationJob->GravityForce); glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), coolDeathAnimationJob->ObjectRadius); glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(coolDeathAnimationJob->EndColor)); - glUniform1i(glGetUniformLocation(ShaderHandle, "UseRandomness"), coolDeathAnimationJob->UseRandomness); - glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 10, coolDeathAnimationJob->RandomNumbers.data()); + glUniform1i(glGetUniformLocation(ShaderHandle, "Randomness"), coolDeathAnimationJob->Randomness); + glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 20, coolDeathAnimationJob->RandomNumbers.data()); glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), coolDeathAnimationJob->RandomnessScalar); + glUniform2fv(glGetUniformLocation(ShaderHandle, "Acceleration"), 1, glm::value_ptr(coolDeathAnimationJob->Acceleration)); + glUniform1i(glGetUniformLocation(ShaderHandle, "ColorPerPolygon"), coolDeathAnimationJob->ColorPerPolygon); + glUniform1i(glGetUniformLocation(ShaderHandle, "ReverseAnimation"), coolDeathAnimationJob->ReverseAnimation); + glUniform1i(glGetUniformLocation(ShaderHandle, "Wireframe"), coolDeathAnimationJob->Wireframe); + + //TODO: Renderer: bättre textur felhantering samt fler texturer stöd diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index f9a8630d..a266c163 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -114,15 +114,19 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) auto deathComp = world->GetComponent(modelC.EntityID, "CoolDeathAnim"); - job.OriginPos = (glm::vec3)deathComp["OriginPos"]; + job.ExplosionOrigin = (glm::vec3)deathComp["ExplosionOrigin"]; job.TimeSinceDeath = (double)deathComp["TimeSinceDeath"]; - job.EndOfDeath = (double)deathComp["EndOfDeath"]; + job.ExplosionDuration = (double)deathComp["ExplosionDuration"]; job.Gravity = (bool)deathComp["Gravity"]; job.GravityForce = (double)deathComp["GravityForce"]; job.ObjectRadius = (double)deathComp["ObjectRadius"]; job.EndColor = (glm::vec4)deathComp["EndColor"]; - job.UseRandomness = (bool)deathComp["UseRandomness"]; + job.Randomness = (bool)deathComp["Randomness"]; job.RandomnessScalar = (double)deathComp["RandomnessScalar"]; + job.Acceleration = (glm::vec2)deathComp["Acceleration"]; + job.ColorPerPolygon = (bool)deathComp["ColorPerPolygon"]; + job.ReverseAnimation = (bool)deathComp["ReverseAnimation"]; + job.Wireframe = (bool)deathComp["Wireframe"]; job.RandomNumbers = { 0.3257552917701f, 0.07601508315467f, @@ -133,7 +137,17 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) 0.39413607511396f, 0.54579346698979f, 0.83222648353885f, - 0.83635707285086f }; + 0.83635707285086f, + 0.34473986148124f, + 0.98092448710507f, + 0.46346380070944f, + 0.7308761201477f, + 0.70832470371776f, + 0.28268750909841f, + 0.26291620883295f, + 0.07685032816457f, + 0.30760929515008f, + 0.2781575388639f }; job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0; job.DiffuseTexture = texGroup.Texture.get(); From 923589524b6991655a4ccbd55b969397d1c43e1f Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 12 Jan 2016 21:25:15 +0100 Subject: [PATCH 4/9] Fix the accelaration (possibly) I haven't tested so I might just have destroyed everything. --- resources/Shaders/CoolDeathAnim.geom.glsl | 159 +++++++++------------- 1 file changed, 63 insertions(+), 96 deletions(-) diff --git a/resources/Shaders/CoolDeathAnim.geom.glsl b/resources/Shaders/CoolDeathAnim.geom.glsl index b2d346c8..0c2db68d 100644 --- a/resources/Shaders/CoolDeathAnim.geom.glsl +++ b/resources/Shaders/CoolDeathAnim.geom.glsl @@ -13,7 +13,7 @@ uniform vec4 EndColor; uniform bool Randomness; uniform float RandomNumbers[20]; uniform float RandomnessScalar; -uniform vec2 Accelaration; +uniform vec2 Velocity; // CHANGED THIS TO VELOCITY REMEMBER YOU FUCKER uniform bool ColorPerPolygon; uniform bool ReverseAnimation; uniform bool Wireframe; @@ -34,6 +34,7 @@ out vec4 ExplosionColor; layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; +// returns a "random" number based on input parameter float GetRandomNumber(int polygon_index) { int randomIndex = int(mod(polygon_index, 20)); @@ -63,6 +64,8 @@ float GetRandomNumber(int polygon_index) } } +float randomNumber = 0.0; + void main() { // calculate middle of vectors @@ -90,137 +93,101 @@ void main() // center position of triangle vec3 centerOfTriangle = Input[1].Position + (s * dir1); - // center position of triangle to origin vector + // normalized center position of triangle to origin vector vec3 origin2TriangleCenterVector = normalize(centerOfTriangle - ExplosionOrigin); - // time percentage until end of explosion + // time percentage until end of explosion (0.0-1.0) float timePercetage = TimeSinceDeath / ExplosionDuration; - float currentAccelaration = mix(Accelaration.x, Accelaration.y, timePercetage); - - //float TimeSinceDeath2; - - //if (ReverseAnimation == true) - //{ - // TimeSinceDeath2 = pow(TimeSinceDeath, -1); - //} - //else - //{ - // TimeSinceDeath2 = TimeSinceDeath; - //} + // accelaration to use on current frame. is a interpolation between start and end value + float currentAccelaration = mix(Velocity.x, Velocity.y, timePercetage); + // distance between origin and the center of the current triangle float origin2TriangleCenterDistance = distance(ExplosionOrigin, centerOfTriangle); - - - - - - - - - // The distance a polygon will travel under one second. - float travelUnitS = ExplosionDuration / ObjectRadius; - - // The distance a polygon will travel under the current frame. - float travelUnitF = TimeSinceDeath * travelUnitS; - - - - - - - - - - - - - float randomNumber = 0.0; - + // get a random number if randomness is enabled, otherwise the random number will be zero and won't affect the other algorithms if (Randomness == true) { randomNumber = GetRandomNumber(gl_PrimitiveIDIn); } + // the distance from origin to the triangle center with eventual randomness added float fullDistanceWithRandomness = origin2TriangleCenterDistance + (randomNumber * RandomnessScalar); - vec3 ExplosionRadius = (origin2TriangleCenterVector * (TimeSinceDeath /** currentAccelaration*/)) - (origin2TriangleCenterVector * fullDistanceWithRandomness); + // vector from the triangle center to the explosion's shockwave + vec3 triangleCenter2ExplosionRadius = (origin2TriangleCenterVector * (TimeSinceDeath * currentAccelaration)) - (origin2TriangleCenterVector * fullDistanceWithRandomness); - vec4 screenPos; - - if (fullDistanceWithRandomness <= TimeSinceDeath) + // if the triangle is inside the blast radius... + if (fullDistanceWithRandomness <= (TimeSinceDeath * currentAccelaration)) { - for(int i = 0; i < gl_in.length(); i++) + // if explosion color should be affected by distance instead of time... + if (ColorPerPolygon == true) { - screenPos = gl_in[i].gl_Position; + // the position of the center of the triangle after it has exploded + vec3 movedCenterOfTriangle = vec3(centerOfTriangle + triangleCenter2ExplosionRadius); - vec3 ExplodedPosition = Input[i].Position + ExplosionRadius; + // calculate the max distance (s) the triangle will move + float a = (Velocity.y - Velocity.x) / ExplosionDuration; + float s = (Velocity.x * ExplosionDuration) + (0.5 * a * pow(ExplosionDuration, 2)); + ExplosionColor = EndColor * (length(triangleCenter2ExplosionRadius) / s); + //ExplosionColor = EndColor * (distance(ExplosionOrigin, movedCenterOfTriangle) - distance(ExplosionOrigin, centerOfTriangle)) + } + else + { + ExplosionColor = EndColor * timePercetage; + } + + // for every vertex on the triangle... + for (int i = 0; i < gl_in.length(); i++) + { + // move the triangle to the blast radius + vec3 ExplodedPosition = Input[i].Position + triangleCenter2ExplosionRadius; + + // pass through vertex data Normal = Input[i].Normal; Position = Input[i].Position; TextureCoordinate = Input[i].TextureCoordinate; DiffuseColor = Input[i].DiffuseColor; - ExplosionColor = EndColor * timePercetage; + // convert to model space for the gravity to always be in -y + vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0); - gl_Position = P*V*M * vec4(ExplodedPosition, 1.0); + // if there is gravity, apply it + if (Gravity == true) + { + ExplodedPositionInModelSpace.y = ExplodedPositionInModelSpace.y - pow((TimeSinceDeath - fullDistanceWithRandomness) * GravityForce, 2); + } + + // convert to screen space + gl_Position = P*V * vec4(ExplodedPosition, 1.0); EmitVertex(); } } else { + // if explosion color should be affected by distance instead of time... + if (ColorPerPolygon == true) + { + ExplosionColor = vec4(0.0); + } + else + { + ExplosionColor = EndColor * timePercetage; + } + + // for every vertex on the triangle... for(int i = 0; i < gl_in.length(); i++) { - screenPos = gl_in[i].gl_Position; - + // pass through vertex data Normal = Input[i].Normal; Position = Input[i].Position; TextureCoordinate = Input[i].TextureCoordinate; DiffuseColor = Input[i].DiffuseColor; - ExplosionColor = EndColor; - - gl_Position = screenPos; + // no change in position, pass through vertex + gl_Position = gl_in[i].gl_Position; EmitVertex(); } - } - - //// Explosion from origin - //for(int i = 0; i < gl_in.length(); i++) - //{ - // vec4 screenPos = gl_in[i].gl_Position; - // - // if (fullRandomness <= travelUnitF) - // { - // maXimum = (origin2TriangleCenterVector * travelUnitF) - (origin2TriangleCenterVector * fullRandomness); - // vec3 movedPosition = vec3(Input[i].Position + maXimum); - // - // vec4 changedPos = M * vec4(movedPosition, 1.0); //objectspace - // if (Gravity == true) - // { - // changedPos.y = changedPos.y - pow((travelUnitF - fullRandomness) * GravityForce, 2); - // } - // screenPos = P*V * changedPos; //sceenspace - // } - // - // Normal = Input[i].Normal; - // Position = Input[i].Position; - // TextureCoordinate = Input[i].TextureCoordinate; - // DiffuseColor = Input[i].DiffuseColor; - // if (ColorPerPolygon == false) - // { - // ExplosionColor = EndColor * travelUnitF; - // } - // else - // { - // vec3 movedCenterPos = vec3(centerOfTriangle + maXimum); - // ExplosionColor = EndColor * (distance(ExplosionOrigin, movedCenterPos) - distance(ExplosionOrigin, centerOfTriangle)); - // } - // - // gl_Position = screenPos; - // //gl_Position = gl_in[i].gl_Position; - // EmitVertex(); - //} - -} \ No newline at end of file + } +} From 8f8b64f99c95da9083c8580361ca0a7876ca9a9c Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Mon, 18 Jan 2016 11:50:00 +0100 Subject: [PATCH 5/9] First pass that actually work Not at all done, but it'll have to do for now --- include/Engine/Rendering/RenderQueue.h | 15 ++-- include/Game/CoolDeathAnimationSystem.h | 4 ++ resources/Schema/Components/CoolDeathAnim.xml | 15 ++-- resources/Schema/Components/CoolDeathAnim.xsd | 29 ++++---- resources/Schema/Entities/Test.xml | 15 ++-- resources/Shaders/CoolDeathAnim.geom.glsl | 70 +++++++++++-------- src/Engine/Rendering/DrawScenePass.cpp | 15 ++-- src/Engine/Rendering/RenderQueueFactory.cpp | 15 ++-- 8 files changed, 100 insertions(+), 78 deletions(-) diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 942edf07..3267a3cf 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -69,17 +69,18 @@ struct CoolDeathAnimationJob : ModelJob glm::vec3 ExplosionOrigin; double TimeSinceDeath = 0.f; //Seconds double ExplosionDuration = 2.f; - bool Gravity = true; - double GravityForce = 1.f; // Speed - double ObjectRadius = 2.f; // TODO: Change this for object radius when it's available + //bool Gravity = true; + //double GravityForce = 1.f; // Speed + //double ObjectRadius = 2.f; // TODO: Change this for object radius when it's available glm::vec4 EndColor; bool Randomness = false; std::array RandomNumbers; float RandomnessScalar = 1.f; - glm::vec2 Acceleration; - bool ColorPerPolygon = false; - bool ReverseAnimation = false; - bool Wireframe = false; + glm::vec2 Velocity; + bool ColorByDistance = false; + //bool ReverseAnimation = false; + //bool Wireframe = false; + bool ExponentialAccelaration = false; }; struct SpriteJob : RenderJob diff --git a/include/Game/CoolDeathAnimationSystem.h b/include/Game/CoolDeathAnimationSystem.h index adbdd067..e20c23c5 100644 --- a/include/Game/CoolDeathAnimationSystem.h +++ b/include/Game/CoolDeathAnimationSystem.h @@ -16,5 +16,9 @@ public: (double)Component["TimeSinceDeath"] = 0.f; } (double&)Component["TimeSinceDeath"] += dt; + + //if ((bool)Component["Gravity"] == true) { + // (bool)Component["ExponentialAccelaration"] = false; + //} } }; \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xml b/resources/Schema/Components/CoolDeathAnim.xml index b0df7b73..4f48b3e1 100644 --- a/resources/Schema/Components/CoolDeathAnim.xml +++ b/resources/Schema/Components/CoolDeathAnim.xml @@ -2,14 +2,15 @@ 0 2 - 1 - 1 - 2 + + + 0 1 - - 0 - 0 - 0 + + 0 + + + 0 \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xsd b/resources/Schema/Components/CoolDeathAnim.xsd index a44c9acc..c50b0e53 100644 --- a/resources/Schema/Components/CoolDeathAnim.xsd +++ b/resources/Schema/Components/CoolDeathAnim.xsd @@ -18,15 +18,15 @@ How many seconds the death animation should be - + + + The tint the polys end with @@ -36,17 +36,20 @@ Alter the power of the randomness - - The accelaration factors (start/end) + + The velocity factors (start/end) - - Change the color per polygon + + Change the color by its moved distance instead of by its time - + + + + Linear/Exponential accelaration diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 85f31b82..33a82f27 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -76,16 +76,17 @@ 0 2 - 1 - 1 - 2 + + + 0 1 - - 0 - 0 - 0 + + 0 + + + 0 diff --git a/resources/Shaders/CoolDeathAnim.geom.glsl b/resources/Shaders/CoolDeathAnim.geom.glsl index 0c2db68d..4056dad9 100644 --- a/resources/Shaders/CoolDeathAnim.geom.glsl +++ b/resources/Shaders/CoolDeathAnim.geom.glsl @@ -6,17 +6,18 @@ uniform mat4 P; uniform vec3 ExplosionOrigin; uniform float TimeSinceDeath; uniform float ExplosionDuration; -uniform bool Gravity; -uniform float GravityForce; -uniform float ObjectRadius; +//uniform bool Gravity; +//uniform float GravityForce; +//uniform float ObjectRadius; uniform vec4 EndColor; uniform bool Randomness; uniform float RandomNumbers[20]; uniform float RandomnessScalar; -uniform vec2 Velocity; // CHANGED THIS TO VELOCITY REMEMBER YOU FUCKER -uniform bool ColorPerPolygon; -uniform bool ReverseAnimation; -uniform bool Wireframe; +uniform vec2 Velocity; +uniform bool ColorByDistance; +//uniform bool ReverseAnimation; +//uniform bool Wireframe; +uniform bool ExponentialAccelaration; in VertexData{ vec3 Position; @@ -65,6 +66,7 @@ float GetRandomNumber(int polygon_index) } float randomNumber = 0.0; +float randomDistance = 0.0; void main() { @@ -93,45 +95,51 @@ void main() // center position of triangle vec3 centerOfTriangle = Input[1].Position + (s * dir1); - // normalized center position of triangle to origin vector - vec3 origin2TriangleCenterVector = normalize(centerOfTriangle - ExplosionOrigin); + // center position of triangle to origin vector + vec3 origin2TriangleCenterVector = centerOfTriangle - ExplosionOrigin; + vec3 normalizedOrigin2TriangleCenterVector = normalize(origin2TriangleCenterVector); // time percentage until end of explosion (0.0-1.0) float timePercetage = TimeSinceDeath / ExplosionDuration; // accelaration to use on current frame. is a interpolation between start and end value - float currentAccelaration = mix(Velocity.x, Velocity.y, timePercetage); + float currentVelocity = mix(Velocity.x, Velocity.y, timePercetage); + + if (ExponentialAccelaration == true) + { + currentVelocity = pow(currentVelocity, 2) / 2.0; + } // distance between origin and the center of the current triangle - float origin2TriangleCenterDistance = distance(ExplosionOrigin, centerOfTriangle); + float origin2TriangleCenterDistance = length(origin2TriangleCenterVector); // get a random number if randomness is enabled, otherwise the random number will be zero and won't affect the other algorithms if (Randomness == true) { - randomNumber = GetRandomNumber(gl_PrimitiveIDIn); + randomDistance = GetRandomNumber(gl_PrimitiveIDIn) * RandomnessScalar; } // the distance from origin to the triangle center with eventual randomness added - float fullDistanceWithRandomness = origin2TriangleCenterDistance + (randomNumber * RandomnessScalar); - - // vector from the triangle center to the explosion's shockwave - vec3 triangleCenter2ExplosionRadius = (origin2TriangleCenterVector * (TimeSinceDeath * currentAccelaration)) - (origin2TriangleCenterVector * fullDistanceWithRandomness); + float fullDistanceWithRandomness = origin2TriangleCenterDistance + randomDistance; + // vector from the triangle center to the explosion's shockwave + vec3 triangleCenter2ExplosionRadius = (normalizedOrigin2TriangleCenterVector * (TimeSinceDeath * currentVelocity)) - (normalizedOrigin2TriangleCenterVector * fullDistanceWithRandomness); + // if the triangle is inside the blast radius... - if (fullDistanceWithRandomness <= (TimeSinceDeath * currentAccelaration)) + if (fullDistanceWithRandomness <= (TimeSinceDeath * currentVelocity)) { + float maxRadius = max(TimeSinceDeath * currentVelocity, (ExplosionDuration * currentVelocity)); + + float a = (Velocity.y - Velocity.x) / ExplosionDuration; + //float t = sqrt((2 * origin2TriangleCenterDistance) / a); + // if explosion color should be affected by distance instead of time... - if (ColorPerPolygon == true) + if (ColorByDistance == true) { - // the position of the center of the triangle after it has exploded - vec3 movedCenterOfTriangle = vec3(centerOfTriangle + triangleCenter2ExplosionRadius); - // calculate the max distance (s) the triangle will move - float a = (Velocity.y - Velocity.x) / ExplosionDuration; float s = (Velocity.x * ExplosionDuration) + (0.5 * a * pow(ExplosionDuration, 2)); ExplosionColor = EndColor * (length(triangleCenter2ExplosionRadius) / s); - //ExplosionColor = EndColor * (distance(ExplosionOrigin, movedCenterOfTriangle) - distance(ExplosionOrigin, centerOfTriangle)) } else { @@ -154,20 +162,22 @@ void main() vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0); // if there is gravity, apply it - if (Gravity == true) - { - ExplodedPositionInModelSpace.y = ExplodedPositionInModelSpace.y - pow((TimeSinceDeath - fullDistanceWithRandomness) * GravityForce, 2); - } + //if (Gravity == true) + //{ + // // ---DO THIS----> //ExplodedPositionInModelSpace.y = ExplodedPositionInModelSpace.y - TimeSinceHit; + // + // ExplodedPositionInModelSpace.y = ExplodedPositionInModelSpace.y - pow(TimeSinceDeath, 2); + //} - // convert to screen space - gl_Position = P*V * vec4(ExplodedPosition, 1.0); + // convert to screen space + gl_Position = P*V * ExplodedPositionInModelSpace; EmitVertex(); } } else { // if explosion color should be affected by distance instead of time... - if (ColorPerPolygon == true) + if (ColorByDistance == true) { ExplosionColor = vec4(0.0); } diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index fb791cea..ef14e695 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -54,17 +54,18 @@ void DrawScenePass::Draw(RenderQueueCollection& rq) glUniform3fv(glGetUniformLocation(ShaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(coolDeathAnimationJob->ExplosionOrigin)); glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), coolDeathAnimationJob->TimeSinceDeath); glUniform1f(glGetUniformLocation(ShaderHandle, "ExplosionDuration"), coolDeathAnimationJob->ExplosionDuration); - glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), coolDeathAnimationJob->Gravity); - glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), coolDeathAnimationJob->GravityForce); - glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), coolDeathAnimationJob->ObjectRadius); + //glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), coolDeathAnimationJob->Gravity); + //glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), coolDeathAnimationJob->GravityForce); + //glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), coolDeathAnimationJob->ObjectRadius); glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(coolDeathAnimationJob->EndColor)); glUniform1i(glGetUniformLocation(ShaderHandle, "Randomness"), coolDeathAnimationJob->Randomness); glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 20, coolDeathAnimationJob->RandomNumbers.data()); glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), coolDeathAnimationJob->RandomnessScalar); - glUniform2fv(glGetUniformLocation(ShaderHandle, "Acceleration"), 1, glm::value_ptr(coolDeathAnimationJob->Acceleration)); - glUniform1i(glGetUniformLocation(ShaderHandle, "ColorPerPolygon"), coolDeathAnimationJob->ColorPerPolygon); - glUniform1i(glGetUniformLocation(ShaderHandle, "ReverseAnimation"), coolDeathAnimationJob->ReverseAnimation); - glUniform1i(glGetUniformLocation(ShaderHandle, "Wireframe"), coolDeathAnimationJob->Wireframe); + glUniform2fv(glGetUniformLocation(ShaderHandle, "Velocity"), 1, glm::value_ptr(coolDeathAnimationJob->Velocity)); + glUniform1i(glGetUniformLocation(ShaderHandle, "ColorByDistance"), coolDeathAnimationJob->ColorByDistance); + //glUniform1i(glGetUniformLocation(ShaderHandle, "ReverseAnimation"), coolDeathAnimationJob->ReverseAnimation); + //glUniform1i(glGetUniformLocation(ShaderHandle, "Wireframe"), coolDeathAnimationJob->Wireframe); + glUniform1i(glGetUniformLocation(ShaderHandle, "ExponentialAccelaration"), coolDeathAnimationJob->ExponentialAccelaration); diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index a266c163..eacea09a 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -117,16 +117,17 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) job.ExplosionOrigin = (glm::vec3)deathComp["ExplosionOrigin"]; job.TimeSinceDeath = (double)deathComp["TimeSinceDeath"]; job.ExplosionDuration = (double)deathComp["ExplosionDuration"]; - job.Gravity = (bool)deathComp["Gravity"]; - job.GravityForce = (double)deathComp["GravityForce"]; - job.ObjectRadius = (double)deathComp["ObjectRadius"]; + //job.Gravity = (bool)deathComp["Gravity"]; + //job.GravityForce = (double)deathComp["GravityForce"]; + //job.ObjectRadius = (double)deathComp["ObjectRadius"]; job.EndColor = (glm::vec4)deathComp["EndColor"]; job.Randomness = (bool)deathComp["Randomness"]; job.RandomnessScalar = (double)deathComp["RandomnessScalar"]; - job.Acceleration = (glm::vec2)deathComp["Acceleration"]; - job.ColorPerPolygon = (bool)deathComp["ColorPerPolygon"]; - job.ReverseAnimation = (bool)deathComp["ReverseAnimation"]; - job.Wireframe = (bool)deathComp["Wireframe"]; + job.Velocity = (glm::vec2)deathComp["Velocity"]; + job.ColorByDistance = (bool)deathComp["ColorByDistance"]; + //job.ReverseAnimation = (bool)deathComp["ReverseAnimation"]; + //job.Wireframe = (bool)deathComp["Wireframe"]; + job.ExponentialAccelaration = (bool)deathComp["ExponentialAccelaration"]; job.RandomNumbers = { 0.3257552917701f, 0.07601508315467f, From 35269315cc22b1ab2db7b0dcc96cceede9d7b3e2 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Mon, 18 Jan 2016 13:51:32 +0100 Subject: [PATCH 6/9] Rename the thingie --- include/Engine/Rendering/DrawScenePass.h | 2 +- include/Engine/Rendering/RenderQueue.h | 2 +- include/Engine/Rendering/RenderQueueFactory.h | 2 +- include/Engine/Rendering/Renderer.h | 2 +- ...mationSystem.h => ExplosionEffectSystem.h} | 8 +-- include/Game/Game.h | 2 +- resources/Schema/Components.xsd | 2 +- ...{CoolDeathAnim.xml => ExplosionEffect.xml} | 4 +- ...{CoolDeathAnim.xsd => ExplosionEffect.xsd} | 2 +- resources/Schema/Entities/Test.xml | 4 +- ...im.frag.glsl => ExplosionEffect.frag.glsl} | 0 ...im.geom.glsl => ExplosionEffect.geom.glsl} | 0 ...im.vert.glsl => ExplosionEffect.vert.glsl} | 0 src/Engine/Rendering/DrawScenePass.cpp | 64 +++++++++---------- src/Engine/Rendering/RenderQueueFactory.cpp | 6 +- src/Engine/Rendering/Renderer.cpp | 12 ++-- src/Game/Game.cpp | 2 +- 17 files changed, 57 insertions(+), 57 deletions(-) rename include/Game/{CoolDeathAnimationSystem.h => ExplosionEffectSystem.h} (75%) rename resources/Schema/Components/{CoolDeathAnim.xml => ExplosionEffect.xml} (92%) rename resources/Schema/Components/{CoolDeathAnim.xsd => ExplosionEffect.xsd} (98%) rename resources/Shaders/{CoolDeathAnim.frag.glsl => ExplosionEffect.frag.glsl} (100%) rename resources/Shaders/{CoolDeathAnim.geom.glsl => ExplosionEffect.geom.glsl} (100%) rename resources/Shaders/{CoolDeathAnim.vert.glsl => ExplosionEffect.vert.glsl} (100%) diff --git a/include/Engine/Rendering/DrawScenePass.h b/include/Engine/Rendering/DrawScenePass.h index 516759f2..ec82eed9 100644 --- a/include/Engine/Rendering/DrawScenePass.h +++ b/include/Engine/Rendering/DrawScenePass.h @@ -31,7 +31,7 @@ private: ShaderProgram* m_BasicForwardProgram; - ShaderProgram* m_CoolDeathAnimProgram; + ShaderProgram* m_ExplosionEffectProgram; }; #endif \ No newline at end of file diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index 3267a3cf..dda57855 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -64,7 +64,7 @@ struct ModelJob : RenderJob }; // Cool Death Animation -struct CoolDeathAnimationJob : ModelJob +struct ExplosionEffectJob : ModelJob { glm::vec3 ExplosionOrigin; double TimeSinceDeath = 0.f; //Seconds diff --git a/include/Engine/Rendering/RenderQueueFactory.h b/include/Engine/Rendering/RenderQueueFactory.h index e1a3507a..5b5b0c73 100644 --- a/include/Engine/Rendering/RenderQueueFactory.h +++ b/include/Engine/Rendering/RenderQueueFactory.h @@ -25,7 +25,7 @@ private: void FillModels(World* world, RenderQueue* renderQueue); void FillLights(World* world, RenderQueue* renderQueue); - void FillCoolDeathAnim(World* world, RenderQueue* renderQueue); + void FillExplosionEffect(World* world, RenderQueue* renderQueue); glm::mat4 ModelMatrix(World* world, EntityID entity); }; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index 476ac9f9..4f7f98a5 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -119,7 +119,7 @@ private: ShaderProgram* m_CalculateFrustumProgram; ShaderProgram* m_LightCullProgram; - ShaderProgram* m_CoolDeathAnimProgram; + ShaderProgram* m_ExplosionEffectProgram; }; diff --git a/include/Game/CoolDeathAnimationSystem.h b/include/Game/ExplosionEffectSystem.h similarity index 75% rename from include/Game/CoolDeathAnimationSystem.h rename to include/Game/ExplosionEffectSystem.h index e20c23c5..ed411d39 100644 --- a/include/Game/CoolDeathAnimationSystem.h +++ b/include/Game/ExplosionEffectSystem.h @@ -1,16 +1,16 @@ #include "Common.h" #include "Core/System.h" -class CoolDeathAnimationSystem : public PureSystem +class ExplosionEffectSystem : public PureSystem { public: - CoolDeathAnimationSystem(EventBroker* eventBroker) - : PureSystem(eventBroker, "CoolDeathAnim") + ExplosionEffectSystem(EventBroker* eventBroker) + : PureSystem(eventBroker, "ExplosionEffect") { } virtual void UpdateComponent(World* world, ComponentWrapper& object, double dt) override { - ComponentWrapper& Component = world->GetComponent(object.EntityID, "CoolDeathAnim"); + ComponentWrapper& Component = world->GetComponent(object.EntityID, "ExplosionEffect"); if ((double)Component["TimeSinceDeath"] > (double)Component["ExplosionDuration"]) { (double)Component["TimeSinceDeath"] = 0.f; diff --git a/include/Game/Game.h b/include/Game/Game.h index 900b7aec..96ab3e0e 100644 --- a/include/Game/Game.h +++ b/include/Game/Game.h @@ -16,7 +16,7 @@ #include "Core/EntityXMLFile.h" #include "Core/SystemPipeline.h" #include "RaptorCopterSystem.h" -#include "CoolDeathAnimationSystem.h" +#include "ExplosionEffectSystem.h" #include "PlayerSystem.h" #include "Editor/EditorSystem.h" diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index f95937ee..50c1fb2e 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -8,5 +8,5 @@ - + \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xml b/resources/Schema/Components/ExplosionEffect.xml similarity index 92% rename from resources/Schema/Components/CoolDeathAnim.xml rename to resources/Schema/Components/ExplosionEffect.xml index 4f48b3e1..4b414944 100644 --- a/resources/Schema/Components/CoolDeathAnim.xml +++ b/resources/Schema/Components/ExplosionEffect.xml @@ -1,4 +1,4 @@ - + 0 2 @@ -13,4 +13,4 @@ 0 - \ No newline at end of file + \ No newline at end of file diff --git a/resources/Schema/Components/CoolDeathAnim.xsd b/resources/Schema/Components/ExplosionEffect.xsd similarity index 98% rename from resources/Schema/Components/CoolDeathAnim.xsd rename to resources/Schema/Components/ExplosionEffect.xsd index c50b0e53..cdde5e52 100644 --- a/resources/Schema/Components/CoolDeathAnim.xsd +++ b/resources/Schema/Components/ExplosionEffect.xsd @@ -3,7 +3,7 @@ - + A component that trigger the death effect diff --git a/resources/Schema/Entities/Test.xml b/resources/Schema/Entities/Test.xml index 33a82f27..ee7fc7b0 100644 --- a/resources/Schema/Entities/Test.xml +++ b/resources/Schema/Entities/Test.xml @@ -72,7 +72,7 @@ Models/Core/UnitRaptor.obj - + 0 2 @@ -87,7 +87,7 @@ 0 - + diff --git a/resources/Shaders/CoolDeathAnim.frag.glsl b/resources/Shaders/ExplosionEffect.frag.glsl similarity index 100% rename from resources/Shaders/CoolDeathAnim.frag.glsl rename to resources/Shaders/ExplosionEffect.frag.glsl diff --git a/resources/Shaders/CoolDeathAnim.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl similarity index 100% rename from resources/Shaders/CoolDeathAnim.geom.glsl rename to resources/Shaders/ExplosionEffect.geom.glsl diff --git a/resources/Shaders/CoolDeathAnim.vert.glsl b/resources/Shaders/ExplosionEffect.vert.glsl similarity index 100% rename from resources/Shaders/CoolDeathAnim.vert.glsl rename to resources/Shaders/ExplosionEffect.vert.glsl diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index ef14e695..152e71f4 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -21,12 +21,12 @@ void DrawScenePass::InitializeShaderPrograms() m_BasicForwardProgram->Compile(); m_BasicForwardProgram->Link(); - m_CoolDeathAnimProgram = ResourceManager::Load("#CoolDeathAnimProgram"); - m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/CoolDeathAnim.vert.glsl"))); - m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/CoolDeathAnim.geom.glsl"))); - m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/CoolDeathAnim.frag.glsl"))); - m_CoolDeathAnimProgram->Compile(); - m_CoolDeathAnimProgram->Link(); + m_ExplosionEffectProgram = ResourceManager::Load("#ExplosionEffectProgram"); + m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ExplosionEffect.vert.glsl"))); + m_ExplosionEffectProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + m_ExplosionEffectProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ExplosionEffect.frag.glsl"))); + m_ExplosionEffectProgram->Compile(); + m_ExplosionEffectProgram->Link(); } @@ -41,46 +41,46 @@ void DrawScenePass::Draw(RenderQueueCollection& rq) //TODO: Render: Add code for more jobs than modeljobs. for (auto &job : rq.Forward) { - auto coolDeathAnimationJob = std::dynamic_pointer_cast(job); - if (coolDeathAnimationJob) { - GLuint ShaderHandle = m_CoolDeathAnimProgram->GetHandle(); //--- + auto explosionEffectJob = std::dynamic_pointer_cast(job); + if (explosionEffectJob) { + GLuint ShaderHandle = m_ExplosionEffectProgram->GetHandle(); //--- - m_CoolDeathAnimProgram->Bind(); + m_ExplosionEffectProgram->Bind(); //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms - glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(coolDeathAnimationJob->ModelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(explosionEffectJob->ModelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); - glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color)); - glUniform3fv(glGetUniformLocation(ShaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(coolDeathAnimationJob->ExplosionOrigin)); - glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), coolDeathAnimationJob->TimeSinceDeath); - glUniform1f(glGetUniformLocation(ShaderHandle, "ExplosionDuration"), coolDeathAnimationJob->ExplosionDuration); - //glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), coolDeathAnimationJob->Gravity); - //glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), coolDeathAnimationJob->GravityForce); - //glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), coolDeathAnimationJob->ObjectRadius); - glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(coolDeathAnimationJob->EndColor)); - glUniform1i(glGetUniformLocation(ShaderHandle, "Randomness"), coolDeathAnimationJob->Randomness); - glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 20, coolDeathAnimationJob->RandomNumbers.data()); - glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), coolDeathAnimationJob->RandomnessScalar); - glUniform2fv(glGetUniformLocation(ShaderHandle, "Velocity"), 1, glm::value_ptr(coolDeathAnimationJob->Velocity)); - glUniform1i(glGetUniformLocation(ShaderHandle, "ColorByDistance"), coolDeathAnimationJob->ColorByDistance); - //glUniform1i(glGetUniformLocation(ShaderHandle, "ReverseAnimation"), coolDeathAnimationJob->ReverseAnimation); - //glUniform1i(glGetUniformLocation(ShaderHandle, "Wireframe"), coolDeathAnimationJob->Wireframe); - glUniform1i(glGetUniformLocation(ShaderHandle, "ExponentialAccelaration"), coolDeathAnimationJob->ExponentialAccelaration); + glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(explosionEffectJob->Color)); + glUniform3fv(glGetUniformLocation(ShaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(explosionEffectJob->ExplosionOrigin)); + glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), explosionEffectJob->TimeSinceDeath); + glUniform1f(glGetUniformLocation(ShaderHandle, "ExplosionDuration"), explosionEffectJob->ExplosionDuration); + //glUniform1i(glGetUniformLocation(ShaderHandle, "Gravity"), explosionEffectJob->Gravity); + //glUniform1f(glGetUniformLocation(ShaderHandle, "GravityForce"), explosionEffectJob->GravityForce); + //glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), explosionEffectJob->ObjectRadius); + glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(explosionEffectJob->EndColor)); + glUniform1i(glGetUniformLocation(ShaderHandle, "Randomness"), explosionEffectJob->Randomness); + glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 20, explosionEffectJob->RandomNumbers.data()); + glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), explosionEffectJob->RandomnessScalar); + glUniform2fv(glGetUniformLocation(ShaderHandle, "Velocity"), 1, glm::value_ptr(explosionEffectJob->Velocity)); + glUniform1i(glGetUniformLocation(ShaderHandle, "ColorByDistance"), explosionEffectJob->ColorByDistance); + //glUniform1i(glGetUniformLocation(ShaderHandle, "ReverseAnimation"), explosionEffectJob->ReverseAnimation); + //glUniform1i(glGetUniformLocation(ShaderHandle, "Wireframe"), explosionEffectJob->Wireframe); + glUniform1i(glGetUniformLocation(ShaderHandle, "ExponentialAccelaration"), explosionEffectJob->ExponentialAccelaration); //TODO: Renderer: bättre textur felhantering samt fler texturer stöd - if (coolDeathAnimationJob->DiffuseTexture != nullptr) { + if (explosionEffectJob->DiffuseTexture != nullptr) { glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, coolDeathAnimationJob->DiffuseTexture->m_Texture); + glBindTexture(GL_TEXTURE_2D, explosionEffectJob->DiffuseTexture->m_Texture); } else { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } - glBindVertexArray(coolDeathAnimationJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, coolDeathAnimationJob->Model->ElementBuffer); - glDrawElementsBaseVertex(GL_TRIANGLES, coolDeathAnimationJob->EndIndex - coolDeathAnimationJob->StartIndex + 1, GL_UNSIGNED_INT, 0, coolDeathAnimationJob->StartIndex); + glBindVertexArray(explosionEffectJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, 0, explosionEffectJob->StartIndex); continue; } diff --git a/src/Engine/Rendering/RenderQueueFactory.cpp b/src/Engine/Rendering/RenderQueueFactory.cpp index eacea09a..7540925d 100644 --- a/src/Engine/Rendering/RenderQueueFactory.cpp +++ b/src/Engine/Rendering/RenderQueueFactory.cpp @@ -90,7 +90,7 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) } for (auto texGroup : model->TextureGroups) { - bool hasDeathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim"); + bool hasDeathComp = world->HasComponent(modelC.EntityID, "ExplosionEffect"); if (!hasDeathComp) { ModelJob job; @@ -110,9 +110,9 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue) renderQueue->Add(job); } else { - CoolDeathAnimationJob job; + ExplosionEffectJob job; - auto deathComp = world->GetComponent(modelC.EntityID, "CoolDeathAnim"); + auto deathComp = world->GetComponent(modelC.EntityID, "ExplosionEffect"); job.ExplosionOrigin = (glm::vec3)deathComp["ExplosionOrigin"]; job.TimeSinceDeath = (double)deathComp["TimeSinceDeath"]; diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index e96d3df3..b509c664 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -76,12 +76,12 @@ void Renderer::InitializeShaders() m_DrawScreenQuadProgram->Compile(); m_DrawScreenQuadProgram->Link(); - m_CoolDeathAnimProgram = ResourceManager::Load("#CoolDeathAnimProgram"); - //m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/CoolDeathAnim.vert.glsl"))); - //m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/CoolDeathAnim.geom.glsl"))); - //m_CoolDeathAnimProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/CoolDeathAnim.frag.glsl"))); - //m_CoolDeathAnimProgram->Compile(); - //m_CoolDeathAnimProgram->Link(); + m_ExplosionEffectProgram = ResourceManager::Load("#ExplosionEffectProgram"); + //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ExplosionEffect.vert.glsl"))); + //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + //m_ExplosionEffectProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ExplosionEffect.frag.glsl"))); + //m_ExplosionEffectProgram->Compile(); + //m_ExplosionEffectProgram->Link(); diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index fdc22db2..403a5617 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -57,7 +57,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(m_Renderer); m_SystemPipeline->AddSystem(); m_SystemPipeline->AddSystem(); - m_SystemPipeline->AddSystem(); + m_SystemPipeline->AddSystem(); // Invoke network if (m_Config->Get("Networking.StartNetwork", false)) { From 1411964dcf76ef819796421301699187951fed32 Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Mon, 18 Jan 2016 14:24:31 +0100 Subject: [PATCH 7/9] hourglass assets fixed --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 673d4a4e..f222f5e6 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 673d4a4e4c5a3f5bc9fedf82234e8f8751f63a44 +Subproject commit f222f5e69242d511fa7f5924e07f94a6b2d7f4fd From 77e1dacb6f5437e1dba1183c9f2f011f88ddb35c Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Tue, 19 Jan 2016 09:58:52 +0100 Subject: [PATCH 8/9] Merge --- include/Engine/Rendering/DrawFinalPass.h | 1 + include/Engine/Rendering/ExplosionEffectJob.h | 34 +++++- resources/Shaders/ExplosionEffect.frag.glsl | 16 +-- resources/Shaders/ExplosionEffect.geom.glsl | 95 ++++++++++++----- resources/Shaders/ExplosionEffect.vert.glsl | 2 + resources/Shaders/ForwardPlus.frag.glsl | 3 +- resources/Shaders/ForwardPlus.vert.glsl | 2 + src/Engine/Rendering/DrawFinalPass.cpp | 100 ++++++++++++++---- src/Engine/Rendering/DrawScenePass.cpp | 6 +- 9 files changed, 195 insertions(+), 64 deletions(-) diff --git a/include/Engine/Rendering/DrawFinalPass.h b/include/Engine/Rendering/DrawFinalPass.h index 52876592..e9d823ca 100644 --- a/include/Engine/Rendering/DrawFinalPass.h +++ b/include/Engine/Rendering/DrawFinalPass.h @@ -32,6 +32,7 @@ private: const LightCullingPass* m_LightCullingPass; ShaderProgram* m_ForwardPlusProgram; + ShaderProgram* m_ExplosionEffectProgram; }; diff --git a/include/Engine/Rendering/ExplosionEffectJob.h b/include/Engine/Rendering/ExplosionEffectJob.h index 48f33550..86749f7f 100644 --- a/include/Engine/Rendering/ExplosionEffectJob.h +++ b/include/Engine/Rendering/ExplosionEffectJob.h @@ -45,7 +45,7 @@ struct ExplosionEffectJob : ModelJob //bool Wireframe = false; bool ExponentialAccelaration = false; - std::array RandomNumbers = { + std::array RandomNumbers = { 0.3257552917701f, 0.07601508315467f, 0.57408909014151f, @@ -65,7 +65,37 @@ struct ExplosionEffectJob : ModelJob 0.26291620883295f, 0.07685032816457f, 0.30760929515008f, - 0.2781575388639f }; + 0.2781575388639f , + 0.016950582161988f , + 0.25787915254844f , + 0.76293767279151f , + 0.67730279903733f , + 0.49042877018937f , + 0.13002237823327f , + 0.62803373841012f , + 0.94525353747665f , + 0.32893980076953f , + 0.95952951719962f , + 0.056386206790985f , + 0.012030893476694f , + 0.93090049220757f, + 0.83579883064879f, + 0.79733513938139f, + 0.8796381046435f , + 0.94160434600972f , + 0.76901855588379f , + 0.50253688101775f , + 0.82457069578793f , + 0.80157403359263f , + 0.87291810189975f , + 0.64679548919517f , + 0.42664138899494f , + 0.77171308303797f , + 0.75567959237643f , + 0.45190826265696f , + 0.59844922628181f , + 0.56534937655802f , + 0.195656257307f}; void CalculateHash() override { diff --git a/resources/Shaders/ExplosionEffect.frag.glsl b/resources/Shaders/ExplosionEffect.frag.glsl index 9108aa81..32ababe5 100644 --- a/resources/Shaders/ExplosionEffect.frag.glsl +++ b/resources/Shaders/ExplosionEffect.frag.glsl @@ -7,17 +7,19 @@ uniform vec4 Color; uniform sampler2D texture0; -in vec3 Normal; -in vec3 Position; -in vec2 TextureCoordinate; -in vec4 DiffuseColor; -in vec4 ExplosionColor; +in VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; + vec4 DiffuseColor; + vec4 ExplosionColor; +}Input; out vec4 fragmentColor; void main() { - vec4 texel = texture2D(texture0, TextureCoordinate); - fragmentColor = texel * DiffuseColor * Color + ExplosionColor; + vec4 texel = texture2D(texture0, Input.TextureCoordinate); + fragmentColor = texel * Input.DiffuseColor * Color + Input.ExplosionColor; } \ No newline at end of file diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index 4056dad9..b5c5b4ba 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -11,7 +11,7 @@ uniform float ExplosionDuration; //uniform float ObjectRadius; uniform vec4 EndColor; uniform bool Randomness; -uniform float RandomNumbers[20]; +uniform float RandomNumbers[50]; uniform float RandomnessScalar; uniform vec2 Velocity; uniform bool ColorByDistance; @@ -24,13 +24,16 @@ in VertexData{ vec3 Normal; vec2 TextureCoordinate; vec4 DiffuseColor; + vec4 ExplosionColor; }Input[]; -out vec3 Normal; -out vec3 Position; -out vec2 TextureCoordinate; -out vec4 DiffuseColor; -out vec4 ExplosionColor; +out VertexData{ + vec3 Position; + vec3 Normal; + vec2 TextureCoordinate; + vec4 DiffuseColor; + vec4 ExplosionColor; +}Output; layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; @@ -38,7 +41,7 @@ layout(triangle_strip, max_vertices = 3) out; // returns a "random" number based on input parameter float GetRandomNumber(int polygon_index) { - int randomIndex = int(mod(polygon_index, 20)); + int randomIndex = int(mod(polygon_index, 50)); switch (randomIndex) { @@ -62,6 +65,36 @@ float GetRandomNumber(int polygon_index) case 17: return RandomNumbers[17]; case 18: return RandomNumbers[18]; case 19: return RandomNumbers[19]; + case 20: return RandomNumbers[20]; + case 21: return RandomNumbers[21]; + case 22: return RandomNumbers[22]; + case 23: return RandomNumbers[23]; + case 24: return RandomNumbers[24]; + case 25: return RandomNumbers[25]; + case 26: return RandomNumbers[26]; + case 27: return RandomNumbers[27]; + case 28: return RandomNumbers[28]; + case 29: return RandomNumbers[29]; + case 30: return RandomNumbers[30]; + case 31: return RandomNumbers[31]; + case 32: return RandomNumbers[32]; + case 33: return RandomNumbers[33]; + case 34: return RandomNumbers[34]; + case 35: return RandomNumbers[35]; + case 36: return RandomNumbers[36]; + case 37: return RandomNumbers[37]; + case 38: return RandomNumbers[38]; + case 39: return RandomNumbers[39]; + case 40: return RandomNumbers[40]; + case 41: return RandomNumbers[41]; + case 42: return RandomNumbers[42]; + case 43: return RandomNumbers[43]; + case 44: return RandomNumbers[44]; + case 45: return RandomNumbers[45]; + case 46: return RandomNumbers[46]; + case 47: return RandomNumbers[47]; + case 48: return RandomNumbers[48]; + case 49: return RandomNumbers[49]; } } @@ -102,8 +135,16 @@ void main() // time percentage until end of explosion (0.0-1.0) float timePercetage = TimeSinceDeath / ExplosionDuration; + // get a random number if randomness is enabled, otherwise the random number will be zero and won't affect the other algorithms + if (Randomness == true) + { + randomDistance = GetRandomNumber(gl_PrimitiveIDIn) * RandomnessScalar; + } + + vec2 randomVelocity = Velocity * (randomDistance + 1.0); + // accelaration to use on current frame. is a interpolation between start and end value - float currentVelocity = mix(Velocity.x, Velocity.y, timePercetage); + float currentVelocity = mix(randomVelocity.x, randomVelocity.y, timePercetage); if (ExponentialAccelaration == true) { @@ -113,12 +154,6 @@ void main() // distance between origin and the center of the current triangle float origin2TriangleCenterDistance = length(origin2TriangleCenterVector); - // get a random number if randomness is enabled, otherwise the random number will be zero and won't affect the other algorithms - if (Randomness == true) - { - randomDistance = GetRandomNumber(gl_PrimitiveIDIn) * RandomnessScalar; - } - // the distance from origin to the triangle center with eventual randomness added float fullDistanceWithRandomness = origin2TriangleCenterDistance + randomDistance; @@ -130,20 +165,20 @@ void main() { float maxRadius = max(TimeSinceDeath * currentVelocity, (ExplosionDuration * currentVelocity)); - float a = (Velocity.y - Velocity.x) / ExplosionDuration; + float a = (randomVelocity.y - randomVelocity.x) / ExplosionDuration; //float t = sqrt((2 * origin2TriangleCenterDistance) / a); // if explosion color should be affected by distance instead of time... if (ColorByDistance == true) { // calculate the max distance (s) the triangle will move - float s = (Velocity.x * ExplosionDuration) + (0.5 * a * pow(ExplosionDuration, 2)); + float s = (randomVelocity.x * ExplosionDuration) + (0.5 * a * pow(ExplosionDuration, 2)); - ExplosionColor = EndColor * (length(triangleCenter2ExplosionRadius) / s); + Output.ExplosionColor = EndColor * (length(triangleCenter2ExplosionRadius) / s); } else { - ExplosionColor = EndColor * timePercetage; + Output.ExplosionColor = EndColor * timePercetage; } // for every vertex on the triangle... @@ -153,10 +188,10 @@ void main() vec3 ExplodedPosition = Input[i].Position + triangleCenter2ExplosionRadius; // pass through vertex data - Normal = Input[i].Normal; - Position = Input[i].Position; - TextureCoordinate = Input[i].TextureCoordinate; - DiffuseColor = Input[i].DiffuseColor; + Output.Normal = Input[i].Normal; + Output.Position = Input[i].Position; + Output.TextureCoordinate = Input[i].TextureCoordinate; + Output.DiffuseColor = Input[i].DiffuseColor; // convert to model space for the gravity to always be in -y vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0); @@ -179,25 +214,27 @@ void main() // if explosion color should be affected by distance instead of time... if (ColorByDistance == true) { - ExplosionColor = vec4(0.0); + Output.ExplosionColor = vec4(0.0); } else { - ExplosionColor = EndColor * timePercetage; + Output.ExplosionColor = EndColor * timePercetage; } // for every vertex on the triangle... for(int i = 0; i < gl_in.length(); i++) { // pass through vertex data - Normal = Input[i].Normal; - Position = Input[i].Position; - TextureCoordinate = Input[i].TextureCoordinate; - DiffuseColor = Input[i].DiffuseColor; + Output.Normal = Input[i].Normal; + Output.Position = Input[i].Position; + Output.TextureCoordinate = Input[i].TextureCoordinate; + Output.DiffuseColor = Input[i].DiffuseColor; // no change in position, pass through vertex gl_Position = gl_in[i].gl_Position; EmitVertex(); } - } + } + + //EndPrimitive(); } diff --git a/resources/Shaders/ExplosionEffect.vert.glsl b/resources/Shaders/ExplosionEffect.vert.glsl index 20ab9051..04e1bda2 100644 --- a/resources/Shaders/ExplosionEffect.vert.glsl +++ b/resources/Shaders/ExplosionEffect.vert.glsl @@ -21,6 +21,7 @@ out VertexData{ vec3 Normal; vec2 TextureCoordinate; vec4 DiffuseColor; + vec4 ExplosionColor; }Output; void main() @@ -31,4 +32,5 @@ void main() Output.TextureCoordinate = TextureCoords; Output.Normal = Normal; Output.DiffuseColor = DiffuseVertexColor; + Output.ExplosionColor = vec4(0.0); } \ No newline at end of file diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 3d5b9bfd..f659f508 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -45,6 +45,7 @@ in VertexData{ vec3 Normal; vec2 TextureCoordinate; vec4 DiffuseColor; + vec4 ExplosionColor; }Input; out vec4 fragmentColor; @@ -114,7 +115,7 @@ void main() totalLighting.Specular += result.Specular; } - fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; + fragmentColor += (Input.DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; //fragmentColor += vec4(0.0, LightGrids.Data[currentTile].Amount/3.0, 0, 1); //fragmentColor = texel * Input.DiffuseColor * Color; diff --git a/resources/Shaders/ForwardPlus.vert.glsl b/resources/Shaders/ForwardPlus.vert.glsl index 20ab9051..04e1bda2 100644 --- a/resources/Shaders/ForwardPlus.vert.glsl +++ b/resources/Shaders/ForwardPlus.vert.glsl @@ -21,6 +21,7 @@ out VertexData{ vec3 Normal; vec2 TextureCoordinate; vec4 DiffuseColor; + vec4 ExplosionColor; }Output; void main() @@ -31,4 +32,5 @@ void main() Output.TextureCoordinate = TextureCoords; Output.Normal = Normal; Output.DiffuseColor = DiffuseVertexColor; + Output.ExplosionColor = vec4(0.0); } \ No newline at end of file diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index b0ca4afe..c464f8ab 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -20,6 +20,13 @@ void DrawFinalPass::InitializeShaderPrograms() m_ForwardPlusProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlus.frag.glsl"))); m_ForwardPlusProgram->Compile(); m_ForwardPlusProgram->Link(); + + m_ExplosionEffectProgram = ResourceManager::Load("#ExplosionEffectProgram"); + m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardPlus.vert.glsl"))); + m_ExplosionEffectProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); + m_ExplosionEffectProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardPlus.frag.glsl"))); + m_ExplosionEffectProgram->Compile(); + m_ExplosionEffectProgram->Link(); } void DrawFinalPass::Draw(RenderScene& scene) @@ -27,39 +34,88 @@ void DrawFinalPass::Draw(RenderScene& scene) GLERROR("DrawFinalPass::Draw: Pre"); DrawFinalPassState state; - m_ForwardPlusProgram->Bind(); - GLuint shaderHandle = m_ForwardPlusProgram->GetHandle(); - - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO()); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO()); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO()); - - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); - glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + GLuint shaderHandle; + //TODO: Render: Add code for more jobs than modeljobs. for (auto &job : scene.ForwardJobs) { - auto modelJob = std::dynamic_pointer_cast(job); - if(modelJob) { - //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms - glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); - glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); - if(modelJob->DiffuseTexture != nullptr) { + auto explosionEffectJob = std::dynamic_pointer_cast(job); + if (explosionEffectJob) { + m_ExplosionEffectProgram->Bind(); + shaderHandle = m_ExplosionEffectProgram->GetHandle(); //--- + + GLERROR("DrawFinalPass::ExplosionEffect: ENDsdufhsdilfuh"); + + //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(explosionEffectJob->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())); + glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(explosionEffectJob->Color)); + glUniform3fv(glGetUniformLocation(shaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(explosionEffectJob->ExplosionOrigin)); + glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), explosionEffectJob->TimeSinceDeath); + glUniform1f(glGetUniformLocation(shaderHandle, "ExplosionDuration"), explosionEffectJob->ExplosionDuration); + glUniform4fv(glGetUniformLocation(shaderHandle, "EndColor"), 1, glm::value_ptr(explosionEffectJob->EndColor)); + glUniform1i(glGetUniformLocation(shaderHandle, "Randomness"), explosionEffectJob->Randomness); + glUniform1fv(glGetUniformLocation(shaderHandle, "RandomNumbers"), 50, explosionEffectJob->RandomNumbers.data()); + glUniform1f(glGetUniformLocation(shaderHandle, "RandomnessScalar"), explosionEffectJob->RandomnessScalar); + glUniform2fv(glGetUniformLocation(shaderHandle, "Velocity"), 1, glm::value_ptr(explosionEffectJob->Velocity)); + glUniform1i(glGetUniformLocation(shaderHandle, "ColorByDistance"), explosionEffectJob->ColorByDistance); + glUniform1i(glGetUniformLocation(shaderHandle, "ExponentialAccelaration"), explosionEffectJob->ExponentialAccelaration); + GLERROR("DrawFinalPass::ExplosionEffect: asdasdasdasdasdasd"); + + //TODO: Renderer: bättre textur felhantering samt fler texturer stöd + if (explosionEffectJob->DiffuseTexture != nullptr) { glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); + glBindTexture(GL_TEXTURE_2D, explosionEffectJob->DiffuseTexture->m_Texture); } else { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); } - - glBindVertexArray(modelJob->Model->VAO); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); - glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); - + GLERROR("DrawFinalPass::ExplosionEffect: END1"); + glBindVertexArray(explosionEffectJob->Model->VAO); + GLERROR("DrawFinalPass::ExplosionEffect: END2"); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer); + GLERROR("DrawFinalPass::ExplosionEffect: END3"); + glDrawElementsBaseVertex(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, 0, explosionEffectJob->StartIndex); + GLERROR("DrawFinalPass::ExplosionEffect: END"); + m_ExplosionEffectProgram->Unbind(); continue; + } else { + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) { + m_ForwardPlusProgram->Bind(); + shaderHandle = m_ForwardPlusProgram->GetHandle(); + + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO()); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO()); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO()); + + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix())); + glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height); + + //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms + glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); + + if (modelJob->DiffuseTexture != nullptr) { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); + } else { + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); + } + + glBindVertexArray(modelJob->Model->VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); + glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); + GLERROR("DrawFinalPass::Model: END"); + m_ForwardPlusProgram->Unbind(); + continue; + } } + } GLERROR("DrawFinalPass::Draw: END"); diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index b3ff4b49..9686f3cf 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -21,11 +21,11 @@ void DrawScenePass::InitializeShaderPrograms() m_BasicForwardProgram->Compile(); m_BasicForwardProgram->Link(); m_ExplosionEffectProgram = ResourceManager::Load("#ExplosionEffectProgram"); - m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ExplosionEffect.vert.glsl"))); + /* m_ExplosionEffectProgram->AddShader(std::shared_ptr(new VertexShader("Shaders/ExplosionEffect.vert.glsl"))); m_ExplosionEffectProgram->AddShader(std::shared_ptr(new GeometryShader("Shaders/ExplosionEffect.geom.glsl"))); m_ExplosionEffectProgram->AddShader(std::shared_ptr(new FragmentShader("Shaders/ExplosionEffect.frag.glsl"))); m_ExplosionEffectProgram->Compile(); - m_ExplosionEffectProgram->Link(); + m_ExplosionEffectProgram->Link();*/ } void DrawScenePass::Draw(RenderScene& scene) @@ -55,7 +55,7 @@ void DrawScenePass::Draw(RenderScene& scene) //glUniform1f(glGetUniformLocation(ShaderHandle, "ObjectRadius"), explosionEffectJob->ObjectRadius); glUniform4fv(glGetUniformLocation(ShaderHandle, "EndColor"), 1, glm::value_ptr(explosionEffectJob->EndColor)); glUniform1i(glGetUniformLocation(ShaderHandle, "Randomness"), explosionEffectJob->Randomness); - glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 20, explosionEffectJob->RandomNumbers.data()); + glUniform1fv(glGetUniformLocation(ShaderHandle, "RandomNumbers"), 50, explosionEffectJob->RandomNumbers.data()); glUniform1f(glGetUniformLocation(ShaderHandle, "RandomnessScalar"), explosionEffectJob->RandomnessScalar); glUniform2fv(glGetUniformLocation(ShaderHandle, "Velocity"), 1, glm::value_ptr(explosionEffectJob->Velocity)); glUniform1i(glGetUniformLocation(ShaderHandle, "ColorByDistance"), explosionEffectJob->ColorByDistance); From 382e00cff457bc0fa1df93eb05ce3f6cb19b687d Mon Sep 17 00:00:00 2001 From: Ayumiwii Date: Thu, 21 Jan 2016 15:34:08 +0100 Subject: [PATCH 9/9] Randomness fixed Redundant continue removed Redundant cross product removed --- resources/Shaders/ExplosionEffect.geom.glsl | 56 +-------------------- src/Engine/Rendering/DrawFinalPass.cpp | 4 +- 2 files changed, 4 insertions(+), 56 deletions(-) diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index b5c5b4ba..8fb239e6 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -43,59 +43,7 @@ float GetRandomNumber(int polygon_index) { int randomIndex = int(mod(polygon_index, 50)); - switch (randomIndex) - { - case 0: return RandomNumbers[0]; - case 1: return RandomNumbers[1]; - case 2: return RandomNumbers[2]; - case 3: return RandomNumbers[3]; - case 4: return RandomNumbers[4]; - case 5: return RandomNumbers[5]; - case 6: return RandomNumbers[6]; - case 7: return RandomNumbers[7]; - case 8: return RandomNumbers[8]; - case 9: return RandomNumbers[9]; - case 10: return RandomNumbers[10]; - case 11: return RandomNumbers[11]; - case 12: return RandomNumbers[12]; - case 13: return RandomNumbers[13]; - case 14: return RandomNumbers[14]; - case 15: return RandomNumbers[15]; - case 16: return RandomNumbers[16]; - case 17: return RandomNumbers[17]; - case 18: return RandomNumbers[18]; - case 19: return RandomNumbers[19]; - case 20: return RandomNumbers[20]; - case 21: return RandomNumbers[21]; - case 22: return RandomNumbers[22]; - case 23: return RandomNumbers[23]; - case 24: return RandomNumbers[24]; - case 25: return RandomNumbers[25]; - case 26: return RandomNumbers[26]; - case 27: return RandomNumbers[27]; - case 28: return RandomNumbers[28]; - case 29: return RandomNumbers[29]; - case 30: return RandomNumbers[30]; - case 31: return RandomNumbers[31]; - case 32: return RandomNumbers[32]; - case 33: return RandomNumbers[33]; - case 34: return RandomNumbers[34]; - case 35: return RandomNumbers[35]; - case 36: return RandomNumbers[36]; - case 37: return RandomNumbers[37]; - case 38: return RandomNumbers[38]; - case 39: return RandomNumbers[39]; - case 40: return RandomNumbers[40]; - case 41: return RandomNumbers[41]; - case 42: return RandomNumbers[42]; - case 43: return RandomNumbers[43]; - case 44: return RandomNumbers[44]; - case 45: return RandomNumbers[45]; - case 46: return RandomNumbers[46]; - case 47: return RandomNumbers[47]; - case 48: return RandomNumbers[48]; - case 49: return RandomNumbers[49]; - } + return RandomNumbers[randomIndex]; } float randomNumber = 0.0; @@ -120,7 +68,7 @@ void main() mat3 matrisA = mat3(vecA, dir2, vecB); - float lengthA = length(cross(dir1, dir2)); + float lengthA = length(vecB); lengthA = lengthA * lengthA; float s = determinant(matrisA) / lengthA; diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index c464f8ab..c9018a34 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -80,7 +80,7 @@ void DrawFinalPass::Draw(RenderScene& scene) glDrawElementsBaseVertex(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, 0, explosionEffectJob->StartIndex); GLERROR("DrawFinalPass::ExplosionEffect: END"); m_ExplosionEffectProgram->Unbind(); - continue; + } else { auto modelJob = std::dynamic_pointer_cast(job); if (modelJob) { @@ -112,7 +112,7 @@ void DrawFinalPass::Draw(RenderScene& scene) glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); GLERROR("DrawFinalPass::Model: END"); m_ForwardPlusProgram->Unbind(); - continue; + } }