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)) {