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,