Broken stuff, refactoring

This commit is contained in:
Ayumiwii
2016-01-12 16:16:42 +01:00
parent 0630885d92
commit 00eeed2e20
8 changed files with 229 additions and 101 deletions
+9 -6
View File
@@ -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<float, 10> RandomNumbers;
bool Randomness = false;
std::array<float, 20> RandomNumbers;
float RandomnessScalar = 1.f;
float Acceleration = 0.f;
glm::vec2 Acceleration;
bool ColorPerPolygon = false;
bool ReverseAnimation = false;
bool Wireframe = false;
};
struct SpriteJob : RenderJob
+1 -1
View File
@@ -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;
@@ -1,11 +1,15 @@
<c:CoolDeathAnim>
<OriginPos X="0" Y="0" Z="0"/>
<ExplosionOrigin X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath>
<EndOfDeath>2</EndOfDeath>
<ExplosionDuration>2</ExplosionDuration>
<Gravity>1</Gravity>
<GravityForce>1</GravityForce>
<ObjectRadius>2</ObjectRadius>
<EndColor R="0" G="0" B="0" A="0"/>
<UseRandomness>0</UseRandomness>
<Randomness>0</Randomness>
<RandomnessScalar>1</RandomnessScalar>
<Acceleration X="2" Y="2"/>
<ColorPerPolygon>0</ColorPerPolygon>
<ReverseAnimation>0</ReverseAnimation>
<Wireframe>0</Wireframe>
</c:CoolDeathAnim>
+17 -5
View File
@@ -9,14 +9,14 @@
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="OriginPos" type="t:Vector" minOccurs="0">
<xs:element name="ExplosionOrigin" type="t:Vector" minOccurs="0">
<xs:annotation><xs:documentation>The position in which to spawn the component</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="TimeSinceDeath" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>Time since death</xs:documentation></xs:annotation>
<xs:annotation><xs:documentation>Seconds since death</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="EndOfDeath" type="t:double" minOccurs="0">
<xs:annotation><xs:documentation>How long the death animation should be</xs:documentation></xs:annotation>
<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:annotation><xs:documentation>Enable/disable gravity</xs:documentation></xs:annotation>
@@ -30,12 +30,24 @@
<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>
<xs:element name="UseRandomness" type="t:bool" minOccurs="0">
<xs:element name="Randomness" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Add some randomness to the explosion</xs:documentation></xs:annotation>
</xs:element>
<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>
<xs:element name="ColorPerPolygon" type="t:bool" minOccurs="0">
<xs:annotation><xs:documentation>Change the color per polygon</xs:documentation></xs:annotation>
</xs:element>
<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:annotation><xs:documentation>Enable/disable wireframe</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
+7 -3
View File
@@ -73,15 +73,19 @@
<Color R="1" G="0.4" B="0.8"/>
</c:Model>
<c:CoolDeathAnim>
<OriginPos X="0" Y="0" Z="0"/>
<ExplosionOrigin X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath>
<EndOfDeath>2</EndOfDeath>
<ExplosionDuration>2</ExplosionDuration>
<Gravity>1</Gravity>
<GravityForce>1</GravityForce>
<ObjectRadius>2</ObjectRadius>
<EndColor R="0" G="0" B="0" A="0"/>
<UseRandomness>0</UseRandomness>
<Randomness>0</Randomness>
<RandomnessScalar>1</RandomnessScalar>
<Acceleration X="2" Y="2"/>
<ColorPerPolygon>0</ColorPerPolygon>
<ReverseAnimation>0</ReverseAnimation>
<Wireframe>0</Wireframe>
</c:CoolDeathAnim>
</Components>
<Children>
+160 -75
View File
@@ -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();
//}
}
+10 -4
View File
@@ -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
+18 -4
View File
@@ -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();