Compare commits

...

12 Commits

Author SHA1 Message Date
Jace 7e12d00874 Merge branch 'master' into CoolDeathAnimation
# Conflicts:
#	include/Engine/Rendering/ModelJob.h
#	resources/Shaders/ForwardPlus.frag.glsl
#	src/Engine/Rendering/DrawFinalPass.cpp
#	src/Engine/Rendering/RenderSystem.cpp
2016-01-27 10:43:23 +01:00
stiffly 44baa47bba Merge remote-tracking branch 'origin/master' into CoolDeathAnimation
# Conflicts:
#	include/Engine/Common.h
#	include/Engine/Rendering/DrawFinalPass.h
#	include/Engine/Rendering/DrawScenePass.h
#	include/Engine/Rendering/RenderQueue.h
#	include/Engine/Rendering/Renderer.h
#	resources/Shaders/ForwardPlus.frag.glsl
#	resources/Shaders/ForwardPlus.vert.glsl
#	src/Engine/Rendering/DrawFinalPass.cpp
#	src/Engine/Rendering/DrawScenePass.cpp
#	src/Engine/Rendering/RenderSystem.cpp
#	src/Engine/Rendering/Renderer.cpp
#	src/Game/Game.cpp
2016-01-25 01:21:15 +01:00
Ayumiwii 382e00cff4 Randomness fixed
Redundant continue removed
Redundant cross product removed
2016-01-21 15:34:08 +01:00
Ayumiwii 77e1dacb6f Merge 2016-01-19 09:58:52 +01:00
Ayumiwii 37aa1eaa18 Merge remote-tracking branch 'origin/master' into CoolDeathAnimation
# Conflicts:
#	include/Engine/Rendering/DrawScenePass.h
#	include/Engine/Rendering/RenderQueue.h
#	include/Engine/Rendering/RenderQueueFactory.h
#	include/Engine/Rendering/Renderer.h
#	include/Game/Game.h
#	resources/Schema/Components.xsd
#	resources/Schema/Entities/Test.xml
#	resources/Schema/Types/Entity.xsd
#	src/Engine/Rendering/DrawScenePass.cpp
#	src/Engine/Rendering/RenderQueueFactory.cpp
#	src/Engine/Rendering/Renderer.cpp
#	src/Game/Game.cpp
2016-01-18 16:02:43 +01:00
Ayumiwii 1411964dcf hourglass assets fixed 2016-01-18 14:24:31 +01:00
Ayumiwii 35269315cc Rename the thingie 2016-01-18 13:51:32 +01:00
Ayumiwii 8f8b64f99c First pass that actually work
Not at all done, but it'll have to do for now
2016-01-18 11:50:00 +01:00
FakeShemp 923589524b Fix the accelaration (possibly)
I haven't tested so I might just have destroyed everything.
2016-01-12 21:25:15 +01:00
Ayumiwii 00eeed2e20 Broken stuff, refactoring 2016-01-12 16:16:42 +01:00
Ayumiwii 0630885d92 Many more things done 2016-01-11 19:59:45 +01:00
Ayumiwii 3467315aef Lots of things done 2016-01-08 16:42:59 +01:00
22 changed files with 636 additions and 63 deletions
+1
View File
@@ -5,6 +5,7 @@
#include <map>
#include <unordered_map>
#include <algorithm>
#include <array>
#include "Core/Util/Logging.h"
#include "Core/Util/IfDebug.h"
+1
View File
@@ -43,6 +43,7 @@ private:
const LightCullingPass* m_LightCullingPass;
ShaderProgram* m_ForwardPlusProgram;
ShaderProgram* m_ExplosionEffectProgram;
};
#endif
@@ -0,0 +1,106 @@
#ifndef ExplosionEffectJob_h__
#define ExplosionEffectJob_h__
#include <cstdint>
#include "../Common.h"
#include "../GLM.h"
#include "../Core/ComponentWrapper.h"
#include "Texture.h"
#include "Model.h"
#include "RenderJob.h"
#include "../Core/ResourceManager.h"
#include "Camera.h"
#include "../Core/World.h"
struct ExplosionEffectJob : ModelJob
{
ExplosionEffectJob(ComponentWrapper explosionEffectComponent, ::Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialGroup matGroup, ComponentWrapper modelComponent, ::World* world, glm::vec4 fillColor, float fillPercentage)
: ModelJob(model, camera, matrix, matGroup, modelComponent, world, fillColor, fillPercentage)
{
ExplosionOrigin = (glm::vec3)explosionEffectComponent["ExplosionOrigin"];
TimeSinceDeath = (double)explosionEffectComponent["TimeSinceDeath"];
ExplosionDuration = (double)explosionEffectComponent["ExplosionDuration"];
EndColor = (glm::vec4)explosionEffectComponent["EndColor"];
Randomness = (bool)explosionEffectComponent["Randomness"];
RandomnessScalar = (double)explosionEffectComponent["RandomnessScalar"];
Velocity = (glm::vec2)explosionEffectComponent["Velocity"];
ColorByDistance = (bool)explosionEffectComponent["ColorByDistance"];
ExponentialAccelaration = (bool)explosionEffectComponent["ExponentialAccelaration"];
};
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 Randomness = false;
float RandomnessScalar = 1.f;
glm::vec2 Velocity;
bool ColorByDistance = false;
//bool ReverseAnimation = false;
//bool Wireframe = false;
bool ExponentialAccelaration = false;
std::array<float, 50> RandomNumbers = {
0.3257552917701f,
0.07601508315467f,
0.57408909014151f,
0.0f,
0.8618231368539f,
0.074957156588769f,
0.39413607511396f,
0.54579346698979f,
0.83222648353885f,
0.83635707285086f,
0.34473986148124f,
0.98092448710507f,
0.46346380070944f,
0.7308761201477f,
0.70832470371776f,
0.28268750909841f,
0.26291620883295f,
0.07685032816457f,
0.30760929515008f,
0.2781575388639f ,
0.016950582161988f ,
0.25787915254844f ,
0.76293767279151f ,
0.67730279903733f ,
0.49042877018937f ,
0.13002237823327f ,
0.62803373841012f ,
0.94525353747665f ,
0.32893980076953f ,
0.95952951719962f ,
0.056386206790985f ,
0.012030893476694f ,
0.93090049220757f,
0.83579883064879f,
0.79733513938139f,
0.8796381046435f ,
0.94160434600972f ,
0.76901855588379f ,
0.50253688101775f ,
0.82457069578793f ,
0.80157403359263f ,
0.87291810189975f ,
0.64679548919517f ,
0.42664138899494f ,
0.77171308303797f ,
0.75567959237643f ,
0.45190826265696f ,
0.59844922628181f ,
0.56534937655802f ,
0.195656257307f};
void CalculateHash() override
{
Hash = 0;
}
};
#endif
+1
View File
@@ -14,6 +14,7 @@
#include "TextJob.h"
#include "PointLightJob.h"
#include "DirectionalLightJob.h"
#include "ExplosionEffectJob.h"
struct RenderScene
{
+2
View File
@@ -73,6 +73,8 @@ private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
//--------------------ShaderPrograms-------------------//
ShaderProgram* m_BasicForwardProgram;
ShaderProgram* m_ExplosionEffectProgram;
};
#endif
+24
View File
@@ -0,0 +1,24 @@
#include "Common.h"
#include "Core/System.h"
class ExplosionEffectSystem : public PureSystem
{
public:
ExplosionEffectSystem(World* world, EventBroker* eventBroker)
: System(world, eventBroker)
, PureSystem("ExplosionEffect")
{ }
virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& component, double dt) override
{
if ((double)component["TimeSinceDeath"] > (double)component["ExplosionDuration"]) {
(double)component["TimeSinceDeath"] = 0.f;
}
(double&)component["TimeSinceDeath"] += dt;
//if ((bool)Component["Gravity"] == true) {
// (bool)Component["ExponentialAccelaration"] = false;
//}
}
};
+1
View File
@@ -14,6 +14,7 @@
#include "Core/EKeyDown.h"
#include "Core/EntityFilePreprocessor.h"
#include "Core/SystemPipeline.h"
#include "ExplosionEffectSystem.h"
#include "Editor/EditorSystem.h"
#include "Core/EntityFile.h"
#include "Rendering/RenderSystem.h"
+1
View File
@@ -12,6 +12,7 @@
<xs:include schemaLocation="Components/PointLight.xsd"/>
<xs:include schemaLocation="Components/DirectionalLight.xsd"/>
<xs:include schemaLocation="Components/Trigger.xsd"/>
<xs:include schemaLocation="Components/ExplosionEffect.xsd"/>
<xs:include schemaLocation="Components/Health.xsd"/>
<xs:include schemaLocation="Components/CapturePoint.xsd"/>
<xs:include schemaLocation="Components/Listener.xsd"/>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ExplosionEffect xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ExplosionEffect.xsd">
<ExplosionOrigin X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath>
<ExplosionDuration>2</ExplosionDuration>
<!--<Gravity>1</Gravity>-->
<!--<GravityForce>1</GravityForce>-->
<!--<ObjectRadius>2</ObjectRadius>-->
<EndColor R="0" G="0" B="0" A="0"/>
<Randomness>0</Randomness>
<RandomnessScalar>1</RandomnessScalar>
<Velocity X="2" Y="2"/>
<ColorByDistance>0</ColorByDistance>
<!--<ReverseAnimation>0</ReverseAnimation>-->
<!--<Wireframe>0</Wireframe>-->
<ExponentialAccelaration>0</ExponentialAccelaration>
</ExplosionEffect>
@@ -0,0 +1,57 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="ExplosionEffect">
<xs:annotation>
<xs:documentation>A component that trigger the death effect</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<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>Seconds since death</xs:documentation></xs:annotation>
</xs:element>
<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>
</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:annotation><xs:documentation>Object radius (TO BE REMOVED AND AUTOMATED)</xs:documentation></xs:annotation>
</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>
<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="Velocity" type="t:Vector" minOccurs="0">
<xs:annotation><xs:documentation>The velocity factors (start/end)</xs:documentation></xs:annotation>
</xs:element>
<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: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: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>
</xs:element>
</xs:schema>
+9 -3
View File
@@ -25,10 +25,16 @@
<Entity>
<Components>
<c:Animation>
<Name>Crouch Walk</Name>
<Time>701.10570384634161</Time>
<Speed>32</Speed>
<Name>Run</Name>
<Time>0.56277947897317659</Time>
<Speed>1</Speed>
</c:Animation>
<c:ExplosionEffect>
<Velocity X="0" Y="1.10000002" Z="3.30000019"/>
<ExplosionOrigin X="-0.600000024" Y="1" Z="0"/>
<TimeSinceDeath>0.95625903442123672</TimeSinceDeath>
<EndColor A="0" B="0.815686285" G="1" R="0"/>
</c:ExplosionEffect>
<c:Model>
<Resource>Models/AssaultAnimated.mesh</Resource>
<Color A="1" B="392156.875" G="1" R="1"/>
+17
View File
@@ -18,6 +18,23 @@
</c:Transform>
<c:Camera>
</c:Camera>
<Orientation X="0.0" Y="0.0" Z="0"/>
<c:ExplosionEffect>
<ExplosionOrigin X="0" Y="0" Z="0"/>
<TimeSinceDeath>0</TimeSinceDeath>
<ExplosionDuration>2</ExplosionDuration>
<!--<Gravity>1</Gravity>-->
<!--<GravityForce>1</GravityForce>-->
<!--<ObjectRadius>2</ObjectRadius>-->
<EndColor R="0" G="0" B="0" A="0"/>
<Randomness>0</Randomness>
<RandomnessScalar>1</RandomnessScalar>
<Velocity X="2" Y="2"/>
<ColorByDistance>0</ColorByDistance>
<!--<ReverseAnimation>0</ReverseAnimation>-->
<!--<Wireframe>0</Wireframe>-->
<ExponentialAccelaration>0</ExponentialAccelaration>
</c:ExplosionEffect>
<c:Model>
<Resource>Models/Camera.mesh</Resource>
</c:Model>
+1
View File
@@ -15,6 +15,7 @@
<xs:element ref="c:Model" minOccurs="0"/>
<xs:element ref="c:RaptorCopter" minOccurs="0"/>
<xs:element ref="c:Player" minOccurs="0"/>
<xs:element ref="c:ExplosionEffect" minOccurs="0"/>
<xs:element ref="c:Camera" minOccurs="0"/>
<xs:element ref="c:Text" minOccurs="0"/>
<xs:element ref="c:AABB" minOccurs="0"/>
@@ -0,0 +1,25 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec4 Color;
uniform sampler2D texture0;
in VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 DiffuseColor;
vec4 ExplosionColor;
}Input;
out vec4 fragmentColor;
void main()
{
vec4 texel = texture2D(texture0, Input.TextureCoordinate);
fragmentColor = texel * Input.DiffuseColor * Color + Input.ExplosionColor;
}
+179
View File
@@ -0,0 +1,179 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 ExplosionOrigin;
uniform float TimeSinceDeath;
uniform float ExplosionDuration;
uniform vec4 EndColor;
uniform bool Randomness;
uniform float RandomNumbers[50];
uniform float RandomnessScalar;
uniform vec2 Velocity;
uniform bool ColorByDistance;
uniform bool ExponentialAccelaration;
in VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 ExplosionColor;
}Input[];
out VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 ExplosionColor;
}Output;
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
// returns a "random" number based on input parameter
float GetRandomNumber(int polygon_index)
{
int randomIndex = int(mod(polygon_index, 50));
return RandomNumbers[randomIndex];
}
float randomNumber = 0.0;
float randomDistance = 0.0;
void main()
{
// 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);
// calculate intersection
// normalize direction
vec3 dir1 = normalize(v1);
vec3 dir2 = normalize(v2);
vec3 vecA = Input[2].Position - Input[1].Position; //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);
// 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;
// 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;
}
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;
}
// distance between origin and the center of the current triangle
float origin2TriangleCenterDistance = length(origin2TriangleCenterVector);
// 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);
// if the triangle is inside the blast radius...
if (fullDistanceWithRandomness <= (TimeSinceDeath * currentVelocity))
{
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));
Output.ExplosionColor = EndColor * (length(triangleCenter2ExplosionRadius) / s);
}
else
{
Output.ExplosionColor = EndColor * 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;
// 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();
}
}
else
{
// if explosion color should be affected by distance instead of time...
if (ColorByDistance == true)
{
Output.ExplosionColor = vec4(0.0);
}
else
{
Output.ExplosionColor = EndColor * timePercetage;
}
// 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;
// no change in position, pass through vertex
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
}
//EndPrimitive();
}
@@ -0,0 +1,36 @@
#version 430
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 Tangent;
layout(location = 3) in vec3 BiTangent;
layout(location = 4) in vec2 TextureCoords;
layout(location = 5) in vec4 DiffuseVertexColor;
layout(location = 6) in vec4 SpecularVertexColor;
layout(location = 7) in vec4 BoneIndices1;
layout(location = 8) in vec4 BoneIndices2;
layout(location = 9) in vec4 BoneWeights1;
layout(location = 10) in vec4 BoneWeights2;
out VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 DiffuseColor;
vec4 ExplosionColor;
}Output;
void main()
{
gl_Position = P*V*M * vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoordinate = TextureCoords;
Output.Normal = Normal;
Output.DiffuseColor = DiffuseVertexColor;
Output.ExplosionColor = vec4(0.0);
}
+4 -5
View File
@@ -50,6 +50,7 @@ in VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 ExplosionColor;
}Input;
out vec4 sceneColor;
@@ -137,8 +138,8 @@ void main()
totalLighting.Specular += light_result.Specular;
}
//sceneColor += Input.DiffuseColor;
vec4 color_result = DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * diffuseTexel * Color;
vec4 color_result = (DiffuseColor + Input.ExplosionColor) * (totalLighting.Diffuse + totalLighting.Specular) * diffuseTexel * Color;
float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0;
@@ -161,9 +162,7 @@ void main()
} else {
bloomColor = vec4(0.0, 0.0, 0.0, 1.0);
} */
//sceneColor += Input.DiffuseColor * (totalLighting.Diffuse) * diffuseTexel * Color;
//sceneColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1);
+2
View File
@@ -17,6 +17,7 @@ out VertexData{
vec3 Position;
vec3 Normal;
vec2 TextureCoordinate;
vec4 ExplosionColor;
}Output;
void main()
@@ -36,4 +37,5 @@ void main()
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
Output.TextureCoordinate = TextureCoords;
Output.Normal = vec3(M * vec4(Normal, 0.0));
Output.ExplosionColor = vec4(0.0);
}
+114 -50
View File
@@ -25,7 +25,7 @@ void DrawFinalPass::InitializeFrameBuffers()
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_FLOAT, 4);
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
@@ -42,6 +42,15 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ForwardPlusProgram->BindFragDataLocation(0, "sceneColor");
m_ForwardPlusProgram->BindFragDataLocation(1, "bloomColor");
m_ForwardPlusProgram->Link();
m_ExplosionEffectProgram = ResourceManager::Load<ShaderProgram>("#ExplosionEffectProgram");
m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardPlus.vert.glsl")));
m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/ExplosionEffect.geom.glsl")));
m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardPlus.frag.glsl")));
m_ExplosionEffectProgram->Compile();
m_ExplosionEffectProgram->BindFragDataLocation(0, "sceneColor");
m_ExplosionEffectProgram->BindFragDataLocation(1, "bloomColor");
m_ExplosionEffectProgram->Link();
}
void DrawFinalPass::Draw(RenderScene& scene)
@@ -49,68 +58,123 @@ void DrawFinalPass::Draw(RenderScene& scene)
GLERROR("DrawFinalPass::Draw: Pre");
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
m_ForwardPlusProgram->Bind();
GLuint shaderHandle = m_ForwardPlusProgram->GetHandle();
if (scene.ClearDepth) {
glClear(GL_DEPTH_BUFFER_BIT);
}
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO());
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
GLuint shaderHandle;
//TODO: Render: Add code for more jobs than modeljobs.
for (auto &job : scene.ForwardJobs) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if(modelJob) {
auto explosionEffectJob = std::dynamic_pointer_cast<ExplosionEffectJob>(job);
if (explosionEffectJob) {
m_ExplosionEffectProgram->Bind();
shaderHandle = m_ExplosionEffectProgram->GetHandle(); //---
GLERROR("DrawFinalPass::ExplosionEffect: 1");
//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(modelJob->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(modelJob->DiffuseColor));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(explosionEffectJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(explosionEffectJob->Color));
glUniform3fv(glGetUniformLocation(shaderHandle, "ExplosionOrigin"), 1, glm::value_ptr(explosionEffectJob->ExplosionOrigin));
glUniform1f(glGetUniformLocation(shaderHandle, "TimeSinceDeath"), explosionEffectJob->TimeSinceDeath);
glUniform1f(glGetUniformLocation(shaderHandle, "ExplosionDuration"), explosionEffectJob->ExplosionDuration);
glUniform4fv(glGetUniformLocation(shaderHandle, "EndColor"), 1, glm::value_ptr(explosionEffectJob->EndColor));
glUniform1i(glGetUniformLocation(shaderHandle, "Randomness"), explosionEffectJob->Randomness);
glUniform1fv(glGetUniformLocation(shaderHandle, "RandomNumbers"), 50, explosionEffectJob->RandomNumbers.data());
glUniform1f(glGetUniformLocation(shaderHandle, "RandomnessScalar"), explosionEffectJob->RandomnessScalar);
glUniform2fv(glGetUniformLocation(shaderHandle, "Velocity"), 1, glm::value_ptr(explosionEffectJob->Velocity));
glUniform1i(glGetUniformLocation(shaderHandle, "ColorByDistance"), explosionEffectJob->ColorByDistance);
glUniform1i(glGetUniformLocation(shaderHandle, "ExponentialAccelaration"), explosionEffectJob->ExponentialAccelaration);
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(explosionEffectJob->DiffuseColor));
GLERROR("DrawFinalPass::ExplosionEffect: 2");
if (explosionEffectJob->Model->m_RawModel->m_Skeleton != nullptr) {
if (explosionEffectJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = explosionEffectJob->Skeleton->GetFrameBones(*explosionEffectJob->Animation, explosionEffectJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
}
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
if (explosionEffectJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, explosionEffectJob->DiffuseTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glBindVertexArray(explosionEffectJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, explosionEffectJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, explosionEffectJob->EndIndex - explosionEffectJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(explosionEffectJob->StartIndex*sizeof(unsigned int)));
GLERROR("DrawFinalPass::ExplosionEffect: END");
//m_ExplosionEffectProgram->Unbind();
} else {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
m_ForwardPlusProgram->Bind();
GLERROR("1.1");
shaderHandle = m_ForwardPlusProgram->GetHandle();
if (scene.ClearDepth) {
glClear(GL_DEPTH_BUFFER_BIT);
}
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, m_LightCullingPass->LightSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, m_LightCullingPass->LightGridSSBO());
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, m_LightCullingPass->LightIndexSSBO());
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
//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(modelJob->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "DiffuseColor"), 1, glm::value_ptr(modelJob->DiffuseColor));
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(modelJob->FillColor));
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), modelJob->FillPercentage);
glActiveTexture(GL_TEXTURE0);
if(modelJob->DiffuseTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1);
if (modelJob->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->IncandescenceTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
/*if(modelJob->GlowMap != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->GlowMap->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}*/
//TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :)
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
if (modelJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones( *modelJob->Animation, modelJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
if (modelJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE1);
if (modelJob->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->IncandescenceTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
/*if(modelJob->GlowMap != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->GlowMap->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
}*/
//TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :)
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
if (modelJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones(*modelJob->Animation, modelJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex*sizeof(unsigned int)));
GLERROR("DrawFinalPass::Model: END");
// m_ForwardPlusProgram->Unbind();
}
}
}
GLERROR("DrawFinalPass::Draw: END");
delete state;
+27 -5
View File
@@ -78,19 +78,41 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
float fillPercentage = 0.f;
glm::vec4 fillColor = glm::vec4(0);
if(m_World->HasComponent(modelComponent.EntityID, "Fill")) {
auto fillComponent = m_World->GetComponent(modelComponent.EntityID, "Fill");
fillPercentage = (float)(double)fillComponent["Percentage"];
fillColor = (glm::vec4)fillComponent["Color"];
}
glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, m_World);
for (auto matGroup : model->MaterialGroups()) {
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(model, m_Camera, modelMatrix, matGroup, modelComponent, m_World, fillColor, fillPercentage));
jobs.push_back(modelJob);
if (m_World->HasComponent(modelComponent.EntityID, "ExplosionEffect")) {
auto explosionEffectComponent = m_World->GetComponent(modelComponent.EntityID, "ExplosionEffect");
std::shared_ptr<ExplosionEffectJob> explosionEffectJob = std::shared_ptr<ExplosionEffectJob>(new ExplosionEffectJob(
explosionEffectComponent,
model,
m_Camera,
modelMatrix,
matGroup,
modelComponent,
m_World,
fillColor,
fillPercentage
));
jobs.push_back(explosionEffectJob);
} else {
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(
model,
m_Camera,
modelMatrix,
matGroup,
modelComponent,
m_World,
fillColor,
fillPercentage
));
jobs.push_back(modelJob);
}
}
}
}
+10
View File
@@ -63,6 +63,15 @@ void Renderer::InitializeWindow()
void Renderer::InitializeShaders()
{
m_BasicForwardProgram = ResourceManager::Load<ShaderProgram>("#m_BasicForwardProgram");
m_ExplosionEffectProgram = ResourceManager::Load<ShaderProgram>("#ExplosionEffectProgram");
//m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ExplosionEffect.vert.glsl")));
//m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/ExplosionEffect.geom.glsl")));
//m_ExplosionEffectProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ExplosionEffect.frag.glsl")));
//m_ExplosionEffectProgram->Compile();
//m_ExplosionEffectProgram->Link();
}
void Renderer::InputUpdate(double dt)
@@ -98,6 +107,7 @@ void Renderer::Draw(RenderFrame& frame)
m_LightCullingPass->FillLightList(*scene);
m_LightCullingPass->CullLights(*scene);
m_DrawFinalPass->Draw(*scene);
//m_DrawScenePass->Draw(*scene);
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
+1
View File
@@ -80,6 +80,7 @@ Game::Game(int argc, char* argv[])
// All systems with orderlevel 0 will be updated first.
unsigned int updateOrderLevel = 0;
m_SystemPipeline->AddSystem<RaptorCopterSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ExplosionEffectSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<HealthSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PlayerMovementSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<InterpolationSystem>(updateOrderLevel);