First pass that actually work

Not at all done, but it'll have to do for now
This commit is contained in:
Ayumiwii
2016-01-18 11:50:00 +01:00
parent 923589524b
commit 8f8b64f99c
8 changed files with 100 additions and 78 deletions
+8 -7
View File
@@ -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<float, 20> 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
+4
View File
@@ -16,5 +16,9 @@ public:
(double)Component["TimeSinceDeath"] = 0.f;
}
(double&)Component["TimeSinceDeath"] += dt;
//if ((bool)Component["Gravity"] == true) {
// (bool)Component["ExponentialAccelaration"] = false;
//}
}
};
@@ -2,14 +2,15 @@
<ExplosionOrigin X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath>
<ExplosionDuration>2</ExplosionDuration>
<Gravity>1</Gravity>
<GravityForce>1</GravityForce>
<ObjectRadius>2</ObjectRadius>
<!--<Gravity>1</Gravity>-->
<!--<GravityForce>1</GravityForce>-->
<!--<ObjectRadius>2</ObjectRadius>-->
<EndColor R="0" G="0" B="0" A="0"/>
<Randomness>0</Randomness>
<RandomnessScalar>1</RandomnessScalar>
<Acceleration X="2" Y="2"/>
<ColorPerPolygon>0</ColorPerPolygon>
<ReverseAnimation>0</ReverseAnimation>
<Wireframe>0</Wireframe>
<Velocity X="2" Y="2"/>
<ColorByDistance>0</ColorByDistance>
<!--<ReverseAnimation>0</ReverseAnimation>-->
<!--<Wireframe>0</Wireframe>-->
<ExponentialAccelaration>0</ExponentialAccelaration>
</c:CoolDeathAnim>
+16 -13
View File
@@ -18,15 +18,15 @@
<xs:element name="ExplosionDuration" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>How many seconds the death animation should be</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Gravity" type="t:bool" minOccurs="0">
<!--<xs:element name="Gravity" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Enable/disable gravity</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="GravityForce" type="t:double" minOccurs="0">
</xs:element>-->
<!--<xs:element name="GravityForce" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>The force of the gravity</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ObjectRadius" type="t:double" minOccurs="0">
</xs:element>-->
<!--<xs:element name="ObjectRadius" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Object radius (TO BE REMOVED AND AUTOMATED)</xs:documentation></xs:annotation>
</xs:element>
</xs:element>-->
<xs:element name="EndColor" type="t:Color" minOccurs="0">
<xs:annotation><xs:documentation>The tint the polys end with</xs:documentation></xs:annotation>
</xs:element>
@@ -36,17 +36,20 @@
<xs:element name="RandomnessScalar" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Alter the power of the randomness</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Acceleration" type="t:Vector" minOccurs="0">
<xs:annotation><xs:documentation>The accelaration factors (start/end)</xs:documentation></xs:annotation>
<xs:element name="Velocity" type="t:Vector" minOccurs="0">
<xs:annotation><xs:documentation>The velocity factors (start/end)</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ColorPerPolygon" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Change the color per polygon</xs:documentation></xs:annotation>
<xs:element name="ColorByDistance" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Change the color by its moved distance instead of by its time</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="ReverseAnimation" type="t:bool" minOccurs="0">
<!--<xs:element name="ReverseAnimation" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Implosions are cooler</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Wireframe" type="t:bool" minOccurs="0">
</xs:element>-->
<!--<xs:element name="Wireframe" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Enable/disable wireframe</xs:documentation></xs:annotation>
</xs:element>-->
<xs:element name="ExponentialAccelaration" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Linear/Exponential accelaration</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
+8 -7
View File
@@ -76,16 +76,17 @@
<ExplosionOrigin X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath>
<ExplosionDuration>2</ExplosionDuration>
<Gravity>1</Gravity>
<GravityForce>1</GravityForce>
<ObjectRadius>2</ObjectRadius>
<!--<Gravity>1</Gravity>-->
<!--<GravityForce>1</GravityForce>-->
<!--<ObjectRadius>2</ObjectRadius>-->
<EndColor R="0" G="0" B="0" A="0"/>
<Randomness>0</Randomness>
<RandomnessScalar>1</RandomnessScalar>
<Acceleration X="2" Y="2"/>
<ColorPerPolygon>0</ColorPerPolygon>
<ReverseAnimation>0</ReverseAnimation>
<Wireframe>0</Wireframe>
<Velocity X="2" Y="2"/>
<ColorByDistance>0</ColorByDistance>
<!--<ReverseAnimation>0</ReverseAnimation>-->
<!--<Wireframe>0</Wireframe>-->
<ExponentialAccelaration>0</ExponentialAccelaration>
</c:CoolDeathAnim>
</Components>
<Children>
+40 -30
View File
@@ -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);
}
+8 -7
View File
@@ -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);
+8 -7
View File
@@ -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,