From fb80d088e40a6d62e2b8b9f0666cc779be2bf0c9 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 23 Feb 2016 10:06:21 +0100 Subject: [PATCH 1/7] Redid many a thing for the sake of efficiency --- include/Game/Systems/ExplosionEffectSystem.h | 1 + resources/Schema/Entities/GameMap.xml | 7 + resources/Shaders/ExplosionEffect.geom.glsl | 211 +++++++++---------- src/Game/Systems/ExplosionEffectSystem.cpp | 20 +- 4 files changed, 118 insertions(+), 121 deletions(-) diff --git a/include/Game/Systems/ExplosionEffectSystem.h b/include/Game/Systems/ExplosionEffectSystem.h index 24eee955..d2eafa15 100644 --- a/include/Game/Systems/ExplosionEffectSystem.h +++ b/include/Game/Systems/ExplosionEffectSystem.h @@ -3,6 +3,7 @@ #include "Common.h" #include "Core/System.h" +#include "Engine/GLM.h" class ExplosionEffectSystem : public PureSystem { diff --git a/resources/Schema/Entities/GameMap.xml b/resources/Schema/Entities/GameMap.xml index c3a16361..473b9037 100644 --- a/resources/Schema/Entities/GameMap.xml +++ b/resources/Schema/Entities/GameMap.xml @@ -245,6 +245,13 @@ + + + + + + + diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index 44b44aa6..44ae568b 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -13,6 +13,11 @@ uniform float RandomnessScalar; uniform vec2 Velocity; uniform bool ColorByDistance; uniform bool ExponentialAccelaration; +uniform bool Reverse; +//uniform bool Gravity; +//uniform bool Rotation; +//uniform bool MaxRadius; +//uniform bool Pulsate; in VertexData{ vec3 Position; @@ -37,161 +42,141 @@ out VertexData{ layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; +vec3 EqualTo(vec3 x, vec3 y) { + return 1.0 - abs(sign(x - y)); +} + +vec3 NotEqualTo(vec3 x, vec3 y) { + return abs(sign(x - y)); +} + +vec3 GreaterThan(vec3 x, vec3 y) { + return max(sign(x - y), 0.0); +} + +vec3 LessThan(vec3 x, vec3 y) { + return max(sign(y - x), 0.0); +} + +vec3 GreaterEqualTo(vec3 x, vec3 y) { + return 1.0 - LessThan(x, y); +} + +vec3 LessEqualTo(vec3 x, vec3 y) { + return 1.0 - GreaterThan(x, y); +} + // returns a "random" number based on input parameter float GetRandomNumber(int polygon_index) { - int randomIndex = int(mod(polygon_index, 50)); - - return RandomNumbers[randomIndex]; + return RandomNumbers[int(mod(polygon_index, 50))]; } -float randomNumber = 0.0; -float randomDistance = 0.0; - -void main() +vec3 CalcCenterOfTriangle(vec3 vertex0, vec3 vertex1, vec3 vertex2) { // 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 dir1 = normalize(vertex1 - vertex0); + vec3 dir2 = normalize(vertex2 - vertex0); - // calculate intersection - - // normalize direction - vec3 dir1 = normalize(v1); - vec3 dir2 = normalize(v2); - - vec3 vecA = Input[2].Position - Input[1].Position; //o2 - o1 + vec3 vecA = vertex2 - vertex1; //o2 - o1 vec3 vecB = cross(dir1, dir2); mat3 matrisA = mat3(vecA, dir2, vecB); float lengthA = length(vecB); lengthA = lengthA * lengthA; - + float s = determinant(matrisA) / lengthA; // center position of triangle - vec3 centerOfTriangle = Input[1].Position + (s * dir1); - + return vertex1 + (s * dir1); +} + +void PassThingsThrough(int index) +{ + // pass through vertex data + Output.Normal = Input[index].Normal; + Output.Position = Input[index].Position; + Output.TextureCoordinate = Input[index].TextureCoordinate; + Output.Tangent = Input[index].Tangent; + Output.BiTangent = Input[index].BiTangent; + Output.ExplosionColor = EndColor; +} + +void main() +{ + vec3 centerOfTriangle = CalcCenterOfTriangle(Input[0].Position, Input[1].Position, Input[2].Position); + // center position of triangle to origin vector vec3 origin2TriangleCenterVector = centerOfTriangle - ExplosionOrigin; vec3 normalizedOrigin2TriangleCenterVector = normalize(origin2TriangleCenterVector); + // distance between origin and the center of the current triangle + float origin2TriangleCenterDistance = length(origin2TriangleCenterVector); + // 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; - } + // get a random number if randomness is enabled, otherwise the random distance will be zero and won't affect the other algorithms + float randomDistance = GetRandomNumber(gl_PrimitiveIDIn) * RandomnessScalar * float(Randomness); vec2 randomVelocity = Velocity * (randomDistance + 1.0); // accelaration to use on current frame. is a interpolation between start and end value float currentVelocity = mix(randomVelocity.x, randomVelocity.y, timePercetage); - if (ExponentialAccelaration == true) - { - currentVelocity = pow(currentVelocity, 2) / 2.0; - } + // if the accelaration should be exponential + currentVelocity = currentVelocity * max(currentVelocity * float(ExponentialAccelaration), 1.0); - // distance between origin and the center of the current triangle - float origin2TriangleCenterDistance = length(origin2TriangleCenterVector); + // the distance the blast has moved since the beginning, i.e. its radius + float blastWave = TimeSinceDeath * currentVelocity; // the distance from origin to the triangle center with eventual randomness added - float fullDistanceWithRandomness = origin2TriangleCenterDistance + randomDistance; - - // vector from the triangle center to the explosion's shockwave - vec3 triangleCenter2ExplosionRadius = (normalizedOrigin2TriangleCenterVector * (TimeSinceDeath * currentVelocity)) - (normalizedOrigin2TriangleCenterVector * fullDistanceWithRandomness); + float origin2TriangleCenterDistanceWithRandomness = origin2TriangleCenterDistance + randomDistance; - // if the triangle is inside the blast radius... - if (fullDistanceWithRandomness <= (TimeSinceDeath * currentVelocity)) + vec3 triangleCenter2ExplosionRadius = (normalizedOrigin2TriangleCenterVector * blastWave) - (normalizedOrigin2TriangleCenterVector * origin2TriangleCenterDistanceWithRandomness); + + // if the triangle is inside the blast's radius... + float isInsideBlastRadius = LessEqualTo(vec3(origin2TriangleCenterDistanceWithRandomness), vec3(blastWave)).x; + + // calculate the max distance (s) the triangle will move + float accelaration = (randomVelocity.y - randomVelocity.x) / ExplosionDuration; + float maxDistance = (randomVelocity.x * ExplosionDuration) + (0.5 * accelaration * ExplosionDuration * ExplosionDuration); + + // if explosion color should be affected by distance instead of time... + if (ColorByDistance == true) { - float maxRadius = max(TimeSinceDeath * currentVelocity, (ExplosionDuration * currentVelocity)); - - 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 = (randomVelocity.x * ExplosionDuration) + (0.5 * a * pow(ExplosionDuration, 2)); - float te = (length(triangleCenter2ExplosionRadius) / s); - - Output.ExplosionColor = EndColor; - Output.ExplosionPercentageElapsed = te; - - } - else - { - Output.ExplosionColor = EndColor; - Output.ExplosionPercentageElapsed = 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 - Output.Normal = Input[i].Normal; - Output.Position = Input[i].Position; - Output.TextureCoordinate = Input[i].TextureCoordinate; - Output.Tangent = Input[i].Tangent; - Output.BiTangent = Input[i].BiTangent; - - // convert to model space for the gravity to always be in -y - vec4 ExplodedPositionInModelSpace = M * vec4(ExplodedPosition, 1.0); - - // if there is gravity, apply it - //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 * ExplodedPositionInModelSpace; - EmitVertex(); - } + Output.ExplosionPercentageElapsed = (length(triangleCenter2ExplosionRadius) / maxDistance) * isInsideBlastRadius; } else { - // if explosion color should be affected by distance instead of time... - if (ColorByDistance == true) + Output.ExplosionPercentageElapsed = timePercetage; + } + + vec3 ExplodedPosition; + for (int i = 0; i < gl_in.length(); i++) + { + // move the triangle to the blast radius + if(Reverse == false) { - Output.ExplosionColor = EndColor; - Output.ExplosionPercentageElapsed = 0.0; + ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * isInsideBlastRadius); } else { - Output.ExplosionColor = EndColor; - Output.ExplosionPercentageElapsed = timePercetage; - + // TODO: + // Remove ifs + // account for randomness + // account for velocity + // account for color + + ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * maxDistance * (ExplosionDuration - TimeSinceDeath)); } + + // pass through vertex data + PassThingsThrough(i); - // for every vertex on the triangle... - for(int i = 0; i < gl_in.length(); i++) - { - // pass through vertex data - Output.Normal = Input[i].Normal; - Output.Position = Input[i].Position; - Output.TextureCoordinate = Input[i].TextureCoordinate; - Output.Tangent = Input[i].Tangent; - Output.BiTangent = Input[i].BiTangent; - - // no change in position, pass through vertex - gl_Position = gl_in[i].gl_Position; - EmitVertex(); - } + // convert to window space + gl_Position = P * V * M * vec4(ExplodedPosition, 1.0); + EmitVertex(); } - - //EndPrimitive(); -} +} \ No newline at end of file diff --git a/src/Game/Systems/ExplosionEffectSystem.cpp b/src/Game/Systems/ExplosionEffectSystem.cpp index 2704d2da..6ef668c0 100644 --- a/src/Game/Systems/ExplosionEffectSystem.cpp +++ b/src/Game/Systems/ExplosionEffectSystem.cpp @@ -2,13 +2,17 @@ void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) { - if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) { - (double)component["TimeSinceDeath"] = 0.f; - } - (double&)component["TimeSinceDeath"] += dt; + if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) { + (double)component["TimeSinceDeath"] = 0.f; + } - //if ((bool)Component["Gravity"] == true) { - // (bool)Component["ExponentialAccelaration"] = false; - //} -} + //((glm::vec2)component["Velocity"]).x = min(((glm::vec2)component["Velocity"]).x, ((glm::vec2)component["Velocity"]).y); + (double&)component["TimeSinceDeath"] += dt; + + //if ((bool)component["Pulsate"] == true) { + // if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"] * 0.5) { + // (bool)component["Reverse"] = true; + // } + //} +} \ No newline at end of file From 3ba73b8206b4d3279d18d99a753c96e2bf110c93 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Tue, 1 Mar 2016 23:05:27 +0100 Subject: [PATCH 2/7] Pulsate system implemented. --- resources/Schema/Components/ExplosionEffect.xml | 2 ++ resources/Schema/Components/ExplosionEffect.xsd | 6 ++++++ src/Game/Systems/ExplosionEffectSystem.cpp | 13 ++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/resources/Schema/Components/ExplosionEffect.xml b/resources/Schema/Components/ExplosionEffect.xml index 22692729..1efe913b 100644 --- a/resources/Schema/Components/ExplosionEffect.xml +++ b/resources/Schema/Components/ExplosionEffect.xml @@ -14,4 +14,6 @@ 0 + 0 + 0 \ No newline at end of file diff --git a/resources/Schema/Components/ExplosionEffect.xsd b/resources/Schema/Components/ExplosionEffect.xsd index cdde5e52..77ed6d0b 100644 --- a/resources/Schema/Components/ExplosionEffect.xsd +++ b/resources/Schema/Components/ExplosionEffect.xsd @@ -51,6 +51,12 @@ Linear/Exponential accelaration + + Pulsate the effect + + + Reverse the effect + diff --git a/src/Game/Systems/ExplosionEffectSystem.cpp b/src/Game/Systems/ExplosionEffectSystem.cpp index 6ef668c0..d8944090 100644 --- a/src/Game/Systems/ExplosionEffectSystem.cpp +++ b/src/Game/Systems/ExplosionEffectSystem.cpp @@ -4,15 +4,18 @@ void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrap { if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) { (double)component["TimeSinceDeath"] = 0.f; + if ((bool)component["Pulsate"] == true) { + (bool)component["Reverse"] = false; + } } //((glm::vec2)component["Velocity"]).x = min(((glm::vec2)component["Velocity"]).x, ((glm::vec2)component["Velocity"]).y); (double&)component["TimeSinceDeath"] += dt; - //if ((bool)component["Pulsate"] == true) { - // if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"] * 0.5) { - // (bool)component["Reverse"] = true; - // } - //} + if ((bool)component["Pulsate"] == true) { + if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"] * 0.5) { + (bool)component["Reverse"] = true; + } + } } \ No newline at end of file From 0cf92e99ff8a42aad8e359ff5d9860aa9fb5cf64 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 2 Mar 2016 10:17:49 +0100 Subject: [PATCH 3/7] wip --- include/Engine/Rendering/ExplosionEffectJob.h | 2 ++ resources/Shaders/ExplosionEffect.geom.glsl | 2 +- src/Engine/Rendering/DrawFinalPass.cpp | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/Engine/Rendering/ExplosionEffectJob.h b/include/Engine/Rendering/ExplosionEffectJob.h index 8f339526..453f392c 100644 --- a/include/Engine/Rendering/ExplosionEffectJob.h +++ b/include/Engine/Rendering/ExplosionEffectJob.h @@ -27,6 +27,7 @@ struct ExplosionEffectJob : ModelJob Velocity = (glm::vec2)explosionEffectComponent["Velocity"]; ColorByDistance = (bool)explosionEffectComponent["ColorByDistance"]; ExponentialAccelaration = (bool)explosionEffectComponent["ExponentialAccelaration"]; + Reverse = (bool)explosionEffectComponent["Reverse"]; }; glm::vec3 ExplosionOrigin; @@ -44,6 +45,7 @@ struct ExplosionEffectJob : ModelJob //bool ReverseAnimation = false; //bool Wireframe = false; bool ExponentialAccelaration = false; + bool Reverse = false; std::array RandomNumbers = { 0.3257552917701f, diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index 44ae568b..b202184a 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -169,7 +169,7 @@ void main() // account for velocity // account for color - ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * maxDistance * (ExplosionDuration - TimeSinceDeath)); + ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * maxDistance /** (ExplosionDuration - TimeSinceDeath)*/); } // pass through vertex data diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index d084b919..2544b8a4 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -786,6 +786,8 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrExponentialAccelaration); GLERROR("Bind 15 uniform"); + glUniform1i(glGetUniformLocation(shaderHandle, "Reverse"), job->Reverse); + GLERROR("Bind 15-2 uniform"); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(job->Color)); GLERROR("Bind 16 uniform"); From 53ea5bd37d889364bea3ce7884b6cb54441a220a Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 7 Mar 2016 14:15:17 +0100 Subject: [PATCH 4/7] comment out currently unused thing --- resources/Shaders/ExplosionEffect.geom.glsl | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index b202184a..ef798f37 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -157,20 +157,20 @@ void main() for (int i = 0; i < gl_in.length(); i++) { // move the triangle to the blast radius - if(Reverse == false) - { + //if(Reverse == false) + //{ ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * isInsideBlastRadius); - } - else - { - // TODO: - // Remove ifs - // account for randomness - // account for velocity - // account for color - - ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * maxDistance /** (ExplosionDuration - TimeSinceDeath)*/); - } + //} + //else + //{ + // // TODO: + // // Remove ifs + // // account for randomness + // // account for velocity + // // account for color + // + // ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * maxDistance /** (ExplosionDuration - TimeSinceDeath)*/); + //} // pass through vertex data PassThingsThrough(i); From ee998211646ce6402b7429ae19c2cef5acc823a1 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Mon, 7 Mar 2016 15:45:06 +0100 Subject: [PATCH 5/7] Add reverse and scalar for ColorByDistance --- include/Engine/Rendering/ExplosionEffectJob.h | 4 +++- .../Schema/Components/ExplosionEffect.xml | 2 +- .../Schema/Components/ExplosionEffect.xsd | 6 +++--- resources/Shaders/ExplosionEffect.geom.glsl | 21 ++++--------------- src/Engine/Rendering/DrawFinalPass.cpp | 9 +++++++- src/Game/Systems/ExplosionEffectSystem.cpp | 2 +- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/Engine/Rendering/ExplosionEffectJob.h b/include/Engine/Rendering/ExplosionEffectJob.h index d2d5de3b..1c8efdf9 100644 --- a/include/Engine/Rendering/ExplosionEffectJob.h +++ b/include/Engine/Rendering/ExplosionEffectJob.h @@ -28,6 +28,7 @@ struct ExplosionEffectJob : ModelJob ColorByDistance = (bool)explosionEffectComponent["ColorByDistance"]; ExponentialAccelaration = (bool)explosionEffectComponent["ExponentialAccelaration"]; Reverse = (bool)explosionEffectComponent["Reverse"]; + ColorDistanceScalar = (double)explosionEffectComponent["ColorDistanceScalar"]; }; glm::vec3 ExplosionOrigin; @@ -39,13 +40,14 @@ struct ExplosionEffectJob : ModelJob glm::vec4 EndColor; bool Randomness = false; - float RandomnessScalar = 1.f; + double RandomnessScalar = 1.f; glm::vec2 Velocity; bool ColorByDistance = false; //bool ReverseAnimation = false; //bool Wireframe = false; bool ExponentialAccelaration = false; bool Reverse = false; + double ColorDistanceScalar = 1.f; std::array RandomNumbers = { 0.3257552917701f, diff --git a/resources/Schema/Components/ExplosionEffect.xml b/resources/Schema/Components/ExplosionEffect.xml index 1efe913b..01e7a539 100644 --- a/resources/Schema/Components/ExplosionEffect.xml +++ b/resources/Schema/Components/ExplosionEffect.xml @@ -11,9 +11,9 @@ 1 0 - 0 0 0 + 1 \ No newline at end of file diff --git a/resources/Schema/Components/ExplosionEffect.xsd b/resources/Schema/Components/ExplosionEffect.xsd index 77ed6d0b..5283557b 100644 --- a/resources/Schema/Components/ExplosionEffect.xsd +++ b/resources/Schema/Components/ExplosionEffect.xsd @@ -42,9 +42,6 @@ Change the color by its moved distance instead of by its time - @@ -57,6 +54,9 @@ Reverse the effect + + Scale the distance of the color change + diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index ef798f37..1fdd97b4 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -14,10 +14,10 @@ uniform vec2 Velocity; uniform bool ColorByDistance; uniform bool ExponentialAccelaration; uniform bool Reverse; +uniform float ColorDistanceScalar; //uniform bool Gravity; //uniform bool Rotation; //uniform bool MaxRadius; -//uniform bool Pulsate; in VertexData{ vec3 Position; @@ -146,7 +146,7 @@ void main() // if explosion color should be affected by distance instead of time... if (ColorByDistance == true) { - Output.ExplosionPercentageElapsed = (length(triangleCenter2ExplosionRadius) / maxDistance) * isInsideBlastRadius; + Output.ExplosionPercentageElapsed = (length(triangleCenter2ExplosionRadius) / maxDistance) * isInsideBlastRadius * ColorDistanceScalar; } else { @@ -157,21 +157,8 @@ void main() for (int i = 0; i < gl_in.length(); i++) { // move the triangle to the blast radius - //if(Reverse == false) - //{ - ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * isInsideBlastRadius); - //} - //else - //{ - // // TODO: - // // Remove ifs - // // account for randomness - // // account for velocity - // // account for color - // - // ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * maxDistance /** (ExplosionDuration - TimeSinceDeath)*/); - //} - + ExplodedPosition = Input[i].Position + (triangleCenter2ExplosionRadius * isInsideBlastRadius); + // pass through vertex data PassThingsThrough(i); diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp index 2bda9310..5b71b0d3 100644 --- a/src/Engine/Rendering/DrawFinalPass.cpp +++ b/src/Engine/Rendering/DrawFinalPass.cpp @@ -1047,7 +1047,12 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrExplosionOrigin)); GLERROR("Bind 6 uniform"); - glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), job->TimeSinceDeath); + if (job->Reverse == false) { + glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), job->TimeSinceDeath); + } + else { + glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), (job->ExplosionDuration - job->TimeSinceDeath)); + } GLERROR("Bind 7 uniform"); glUniform1f(glGetUniformLocation(shaderHandle, "ExplosionDuration"), job->ExplosionDuration); GLERROR("Bind 8 uniform"); @@ -1067,6 +1072,8 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptrReverse); GLERROR("Bind 15-2 uniform"); + glUniform1f(glGetUniformLocation(shaderHandle, "ColorDistanceScalar"), job->ColorDistanceScalar); + GLERROR("Bind 15-3 uniform"); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(job->Color)); GLERROR("Bind 16 uniform"); diff --git a/src/Game/Systems/ExplosionEffectSystem.cpp b/src/Game/Systems/ExplosionEffectSystem.cpp index d8944090..6ef5be9d 100644 --- a/src/Game/Systems/ExplosionEffectSystem.cpp +++ b/src/Game/Systems/ExplosionEffectSystem.cpp @@ -9,7 +9,7 @@ void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrap } } - //((glm::vec2)component["Velocity"]).x = min(((glm::vec2)component["Velocity"]).x, ((glm::vec2)component["Velocity"]).y); + //((glm::vec2&)component["Velocity"]).x = glm::min(((glm::vec2)component["Velocity"]).x, ((glm::vec2)component["Velocity"]).y); (double&)component["TimeSinceDeath"] += dt; From 68634126e5e9cd9defdee67e80e4fcf96d19abf3 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Thu, 10 Mar 2016 11:43:11 +0100 Subject: [PATCH 6/7] Add moar optimization thingies and some xml clarifications --- .../Schema/Components/ExplosionEffect.xml | 18 +++++++++--------- resources/Shaders/ExplosionEffect.geom.glsl | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/resources/Schema/Components/ExplosionEffect.xml b/resources/Schema/Components/ExplosionEffect.xml index 01e7a539..00616efd 100644 --- a/resources/Schema/Components/ExplosionEffect.xml +++ b/resources/Schema/Components/ExplosionEffect.xml @@ -1,19 +1,19 @@ - 0 - 2 + 0.0 + 2.0 - 0 - 1 + false + 1.0 - 0 + false - 0 - 0 - 0 - 1 + false + false + false + 1.0 \ No newline at end of file diff --git a/resources/Shaders/ExplosionEffect.geom.glsl b/resources/Shaders/ExplosionEffect.geom.glsl index 1fdd97b4..de588063 100644 --- a/resources/Shaders/ExplosionEffect.geom.glsl +++ b/resources/Shaders/ExplosionEffect.geom.glsl @@ -42,27 +42,27 @@ out VertexData{ layout(triangles) in; layout(triangle_strip, max_vertices = 3) out; -vec3 EqualTo(vec3 x, vec3 y) { +float EqualTo(float x, float y) { return 1.0 - abs(sign(x - y)); } -vec3 NotEqualTo(vec3 x, vec3 y) { +float NotEqualTo(float x, float y) { return abs(sign(x - y)); } -vec3 GreaterThan(vec3 x, vec3 y) { +float GreaterThan(float x, float y) { return max(sign(x - y), 0.0); } -vec3 LessThan(vec3 x, vec3 y) { +float LessThan(float x, float y) { return max(sign(y - x), 0.0); } -vec3 GreaterEqualTo(vec3 x, vec3 y) { +float GreaterEqualTo(float x, float y) { return 1.0 - LessThan(x, y); } -vec3 LessEqualTo(vec3 x, vec3 y) { +float LessEqualTo(float x, float y) { return 1.0 - GreaterThan(x, y); } @@ -118,7 +118,7 @@ void main() float timePercetage = TimeSinceDeath / ExplosionDuration; // get a random number if randomness is enabled, otherwise the random distance will be zero and won't affect the other algorithms - float randomDistance = GetRandomNumber(gl_PrimitiveIDIn) * RandomnessScalar * float(Randomness); + float randomDistance = float(Randomness) * GetRandomNumber(gl_PrimitiveIDIn) * RandomnessScalar; vec2 randomVelocity = Velocity * (randomDistance + 1.0); @@ -137,7 +137,7 @@ void main() vec3 triangleCenter2ExplosionRadius = (normalizedOrigin2TriangleCenterVector * blastWave) - (normalizedOrigin2TriangleCenterVector * origin2TriangleCenterDistanceWithRandomness); // if the triangle is inside the blast's radius... - float isInsideBlastRadius = LessEqualTo(vec3(origin2TriangleCenterDistanceWithRandomness), vec3(blastWave)).x; + float isInsideBlastRadius = LessEqualTo(origin2TriangleCenterDistanceWithRandomness, blastWave); // calculate the max distance (s) the triangle will move float accelaration = (randomVelocity.y - randomVelocity.x) / ExplosionDuration; From 4df936ca704b1e6003bae224e4501c032c9803a9 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Fri, 11 Mar 2016 14:57:02 +0100 Subject: [PATCH 7/7] imon's fix to rule them all might have solved dt anormalities --- src/Game/Systems/ExplosionEffectSystem.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Game/Systems/ExplosionEffectSystem.cpp b/src/Game/Systems/ExplosionEffectSystem.cpp index 71de192a..e75ebb24 100644 --- a/src/Game/Systems/ExplosionEffectSystem.cpp +++ b/src/Game/Systems/ExplosionEffectSystem.cpp @@ -7,12 +7,15 @@ void ExplosionEffectSystem::UpdateComponent(EntityWrapper& entity, ComponentWrap delay = std::max(0.0, delay - dt); } - if (delay <= 0) { - double& timeSinceDeath = component["TimeSinceDeath"]; - timeSinceDeath += (double)component["Speed"] * dt; - if (timeSinceDeath < 0 || timeSinceDeath > (double)component["ExplosionDuration"]) { - timeSinceDeath = 0.0; - } - } + if (delay <= 0) { + double& timeSinceDeath = component["TimeSinceDeath"]; + timeSinceDeath += (double)component["Speed"] * dt; + if (timeSinceDeath < 0) { + timeSinceDeath = 0.0; + } + else if (timeSinceDeath >(double)component["ExplosionDuration"]) { + timeSinceDeath = (double)component["ExplosionDuration"]; + } + } }