From 5d53472286b3c0e9214dda1cf0f6621e78aaa573 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 27 May 2014 07:08:39 +0200 Subject: [PATCH 01/21] CreateExplosion now Event-based (not tested) --- assets | 2 +- src/Events/CreateExplosion.h | 24 +++++++++++++++++++ vs11/Returngeance/Returngeance.vcxproj | 1 + .../Returngeance/Returngeance.vcxproj.filters | 6 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Events/CreateExplosion.h diff --git a/assets b/assets index 6cc3858..72b93d5 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 6cc38589ed77dbb3b9c34c1168d52e0f86e1de46 +Subproject commit 72b93d5750283864f244241e65a38436d05c5f96 diff --git a/src/Events/CreateExplosion.h b/src/Events/CreateExplosion.h new file mode 100644 index 0000000..76f2312 --- /dev/null +++ b/src/Events/CreateExplosion.h @@ -0,0 +1,24 @@ +#ifndef Event_CreateExplosion_h__ +#define Event_CreateExplosion_h__ + +#include "EventBroker.h" +#include +#include + +namespace Events +{ + struct CreateExplosion : Event + { + glm::vec3 Position; + double LifeTime; + int ParticlesToSpawn; + std::string spritePath; + glm::quat RelativeUpOrientation; + float Speed; + float SpreadAngle; + float ParticleScale; + }; + +} + +#endif // Event_CreateExplosion_h__ diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 6a99e47..d0a9467 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -163,6 +163,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 2bf19bf..fccf111 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -158,6 +158,9 @@ {cb06b441-90b8-46ed-b347-4190dac7185b} + + {ddd3c442-7c2f-4690-9308-fcef62deee0b} + @@ -397,6 +400,9 @@ Gameplay\Components + + Particle System\Events + From 571edbc214aa12dd353d23a518ce63944ce9a390 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 27 May 2014 07:09:22 +0200 Subject: [PATCH 02/21] ... even more event-based --- src/Systems/ParticleSystem.cpp | 48 ++++++++++------------------------ src/Systems/ParticleSystem.h | 9 ++++--- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 9b094d3..f16d9ad 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -8,7 +8,7 @@ void Systems::ParticleSystem::Initialize() { m_TransformSystem = m_World->GetSystem(); tempSpawnedExplosions = false; - EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &ParticleSystem::OnKeyUp); + EVENT_SUBSCRIBE_MEMBER(m_EExplosion, &ParticleSystem::CreateExplosion); } void Systems::ParticleSystem::Update(double dt) @@ -225,53 +225,33 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect alpha = spectrum[0] + dAlpha * timeProgress; } -void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale) +bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) { auto explosion = m_World->CreateEntity(); auto emitter = m_World->AddComponent(explosion); - emitter->LifeTime = _lifeTime; - emitter->SpawnCount = _particlesToSpawn; - emitter->Speed = _speed; - emitter->SpreadAngle = _spreadAngle; - emitter->SpawnFrequency = _lifeTime + 20; //temp -// emitter->UseGoalVelocity = true; -// emitter->GoalVelocity = glm::vec3(0,-_speed, 0); + emitter->LifeTime = e.LifeTime; + emitter->SpawnCount = e.ParticlesToSpawn; + emitter->Speed = e.Speed; + emitter->SpreadAngle = e.SpreadAngle; + emitter->SpawnFrequency = e.LifeTime + 20; //temp + // emitter->UseGoalVelocity = true; + // emitter->GoalVelocity = glm::vec3(0,-_speed, 0); m_World->CommitEntity(explosion); auto particleEnt = m_World->CreateEntity(); auto TEMP = m_World->AddComponent(particleEnt); TEMP->Scale = glm::vec3(0); auto spriteComponent = m_World->AddComponent(particleEnt); - spriteComponent->SpriteFile = _spritePath; + spriteComponent->SpriteFile = e.spritePath; m_World->CommitEntity(particleEnt); emitter->ParticleTemplate = particleEnt; - + auto transform = m_World->AddComponent(explosion); - transform->Position = _pos; - transform->Orientation = _relativeUpOri; - + transform->Position = e.Position; + transform->Orientation = e.RelativeUpOrientation; + SpawnParticles(explosion); m_ExplosionEmitters[explosion] = glfwGetTime(); -} -bool Systems::ParticleSystem::OnKeyUp(const Events::KeyUp &e) -{ - if(!tempSpawnedExplosions) - { - if (e.KeyCode == GLFW_KEY_B) - { - tempSpawnedExplosions = true; - CreateExplosion( - glm::vec3(0, 10, 0), - 0.5, - 60, - "Textures/Sprites/NewtonTreeDeleteASAPPlease.png", - glm::angleAxis(glm::pi()/2, glm::vec3(1,0,0)), - 40, - glm::pi(), - 0.5f - ); - } - } return true; } \ No newline at end of file diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index fad8815..f0a10de 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -9,6 +9,7 @@ #include "Components/Sprite.h" #include "EventBroker.h" #include "Events/KeyUp.h" +#include "Events/CreateExplosion.h" #include "Color.h" #include @@ -35,7 +36,7 @@ public: void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void Initialize() override; - void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale); + //void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale); virtual bool OnCommand(const Events::KeyUp &event) { return false; } @@ -54,8 +55,10 @@ private: bool tempSpawnedExplosions; - EventRelay m_EKeyUp; - bool OnKeyUp(const Events::KeyUp &e); +// EventRelay m_EKeyUp; +// bool OnKeyUp(const Events::KeyUp &e); + EventRelay m_EExplosion; + bool CreateExplosion(const Events::CreateExplosion &e); }; From a5f4c9daa066aaa1ba54a815f552faf845e9b0b7 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 28 May 2014 20:05:28 +0200 Subject: [PATCH 03/21] Fixed so OBJ-loader now loads map_Bump options correctly. --- src/OBJ.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OBJ.cpp b/src/OBJ.cpp index d8f91bf..71ec109 100755 --- a/src/OBJ.cpp +++ b/src/OBJ.cpp @@ -268,7 +268,7 @@ void OBJ::ParseMaterial() continue; } // Normal map (bump map) - if (prefix == "bump") + if (prefix == "bump" || prefix == "map_Bump" ) { MaterialInfo::BumpMap bumpMap; From 761b8e21e19525949bd52ab158e477bd40d47f57 Mon Sep 17 00:00:00 2001 From: Tleety Date: Wed, 28 May 2014 20:24:31 +0200 Subject: [PATCH 04/21] Added blendmap component Added renderque for models with a blendmap component Added shaders for blendmaps --- assets | 2 +- src/Components/BlendMap.h | 24 ++++++ src/GUI/WorldFrame.h | 39 ++++++++- src/GameWorld.cpp | 9 +- src/GameWorld.h | 1 + src/RenderQueue.h | 8 ++ src/Renderer.cpp | 49 +++++++++++ src/Renderer.h | 1 + src/Shaders/BlendMap.frag.glsl | 86 +++++++++++++++++++ src/Shaders/BlendMap.vert.glsl | 35 ++++++++ src/Shaders/Fragment.glsl | 26 ------ vs11/Returngeance/Returngeance.vcxproj | 3 + .../Returngeance/Returngeance.vcxproj.filters | 12 ++- 13 files changed, 260 insertions(+), 35 deletions(-) create mode 100644 src/Components/BlendMap.h create mode 100644 src/Shaders/BlendMap.frag.glsl create mode 100644 src/Shaders/BlendMap.vert.glsl diff --git a/assets b/assets index bc811a1..62d8e73 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit bc811a1b392782213d0823e418bc1d773e1a9641 +Subproject commit 62d8e73c689e993cb26dd35cfda253f2fba04bea diff --git a/src/Components/BlendMap.h b/src/Components/BlendMap.h new file mode 100644 index 0000000..c32cc13 --- /dev/null +++ b/src/Components/BlendMap.h @@ -0,0 +1,24 @@ +#ifndef Components_BlendMap_h__ +#define Components_BlendMap_h__ + +#include "Component.h" +#include "Entity.h" + +namespace Components +{ + struct BlendMap : Component + { + BlendMap() + : TextureRed("Textures/Ground/Asphalt") + , TextureGreen("Textures/Ground/Grass") + , TextureBlue("Textures/Ground/Sand") + , TextureRepeats(100.f) { } + + std::string TextureRed, TextureGreen, TextureBlue; + float TextureRepeats; + + virtual BlendMap* Clone() const override { return new BlendMap(*this); } + }; + +} +#endif // !Components_BlendMap_h__ \ No newline at end of file diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index 995b133..29f4314 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -11,6 +11,8 @@ #include "Components/Model.h" #include "Components/Sprite.h" #include "Components/PointLight.h" +#include "Components/BlendMap.h" + namespace GUI { @@ -56,7 +58,20 @@ public: glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position) * glm::toMat4(absoluteTransform.Orientation) * glm::scale(absoluteTransform.Scale); - EnqueueModel(modelAsset, modelMatrix); + auto blendmapComponent = m_World->GetComponent(entity); + if (blendmapComponent) + { + auto textureRed = ResourceManager->Load("Texture", blendmapComponent->TextureRed); + auto textureGreen = ResourceManager->Load("Texture", blendmapComponent->TextureGreen); + auto textureBlue = ResourceManager->Load("Texture", blendmapComponent->TextureBlue); + float textureRepeat = blendmapComponent->TextureRepeats; + EnqueueBlendMapModel(modelAsset, textureRed, textureGreen, textureBlue, textureRepeat, modelMatrix); + } + else + { + EnqueueModel(modelAsset, modelMatrix); + } + } } @@ -134,6 +149,28 @@ private: } } + void EnqueueBlendMapModel(Model* model, Texture* textureRed, Texture* textureGreen, Texture* textureBlue, float textureRepeat, glm::mat4 modelMatrix) + { + for (auto texGroup : model->TextureGroups) + { + BlendMapModelJob job; + job.TextureID = texGroup.Texture->ResourceID; + job.DiffuseTexture = *texGroup.Texture; + job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0; + job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0; + job.BlendMapTextureRed = (*textureRed); + job.BlendMapTextureGreen = (*textureGreen); + job.BlendMapTextureBlue = (*textureBlue); + job.TextureRepeat = textureRepeat; + job.VAO = model->VAO; + job.StartIndex = texGroup.StartIndex; + job.EndIndex = texGroup.EndIndex; + job.ModelMatrix = modelMatrix; + + RenderQueue.Add(job); + } + } + void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix) { SpriteJob job; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 4d50cc9..e2204f7 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -101,11 +101,10 @@ void GameWorld::Initialize() auto ground = CreateEntity(); auto transform = AddComponent(ground); transform->Position = glm::vec3(0, -50, 0); - //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ground); - model->ModelFile = "Models/TestScene3/testScene.obj"; - //model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj"; + model->ModelFile = "Models/TerrainFiveIstles/Middle.obj"; + auto blendmap = AddComponent(ground); auto physics = AddComponent(ground); physics->Mass = 10; @@ -115,8 +114,7 @@ void GameWorld::Initialize() auto groundshape = CreateEntity(ground); auto transformshape = AddComponent(groundshape); auto meshShape = AddComponent(groundshape); - //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj"; - meshShape->ResourceName = "Models/TestScene3/testScene.obj"; + meshShape->ResourceName = "Models/TerrainFiveIstles/Middle.obj"; CommitEntity(groundshape); @@ -1256,6 +1254,7 @@ void GameWorld::RegisterComponents() m_ComponentFactory.Register([]() { return new Components::Template(); }); m_ComponentFactory.Register([]() { return new Components::Player(); }); m_ComponentFactory.Register([]() { return new Components::Flag(); }); + m_ComponentFactory.Register([]() { return new Components::BlendMap(); }); } void GameWorld::RegisterSystems() diff --git a/src/GameWorld.h b/src/GameWorld.h index d43c8ec..5467f8d 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -33,6 +33,7 @@ #include "Components/Template.h" #include "Components/Transform.h" #include "Components/Viewport.h" +#include "Components/BlendMap.h" #include "Components/Physics.h" #include "Components/SphereShape.h" diff --git a/src/RenderQueue.h b/src/RenderQueue.h index be2d18e..32bb29a 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -45,6 +45,14 @@ struct ModelJob : RenderJob } }; +struct BlendMapModelJob : ModelJob +{ + GLuint BlendMapTextureRed; + GLuint BlendMapTextureGreen; + GLuint BlendMapTextureBlue; + float TextureRepeat; +}; + struct SpriteJob : RenderJob { unsigned int ShaderID; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 576857b..b839533 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -108,6 +108,11 @@ void Renderer::LoadContent() m_ShaderProgramDebugAABB.Compile(); m_ShaderProgramDebugAABB.Link();*/ + m_BlendMapProgram.AddShader(std::shared_ptr(new VertexShader("Shaders/BlendMap.vert.glsl"))); + m_BlendMapProgram.AddShader(std::shared_ptr(new FragmentShader("Shaders/BlendMap.frag.glsl"))); + m_BlendMapProgram.Compile(); + m_BlendMapProgram.Link(); + m_ShaderProgramSkybox.AddShader(std::shared_ptr(new VertexShader("Shaders/Skybox.vert.glsl"))); m_ShaderProgramSkybox.AddShader(std::shared_ptr(new FragmentShader("Shaders/Skybox.frag.glsl"))); m_ShaderProgramSkybox.Compile(); @@ -1036,6 +1041,50 @@ void Renderer::DrawFBOScene(RenderQueue &rq) // continue; //} + + m_BlendMapProgram.Bind(); + GLuint ShaderProgramHandle = m_BlendMapProgram.GetHandle(); + + auto blendMapJob = std::dynamic_pointer_cast(job); + if(blendMapJob) + { + glm::mat4 modelMatrix = blendMapJob->ModelMatrix; + + MVP = cameraMatrix * modelMatrix; + depthMVP = depthCameraMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); + glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview)); + glUniform1f(glGetUniformLocation(ShaderProgramHandle, "TextureRepeats"), blendMapJob->TextureRepeat); + + glBindVertexArray(blendMapJob->VAO); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, blendMapJob->DiffuseTexture); + if (blendMapJob->NormalTexture != 0) + { + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, blendMapJob->NormalTexture); + } + if (blendMapJob->SpecularTexture) + { + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, blendMapJob->SpecularTexture); + } + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRed); + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreen); + glActiveTexture(GL_TEXTURE6); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlue); + + glDrawArrays(GL_TRIANGLES, blendMapJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); + + continue; + } } } diff --git a/src/Renderer.h b/src/Renderer.h index ecdecfc..fe51f00 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -173,6 +173,7 @@ private: ShaderProgram m_FinalPassProgram; ShaderProgram m_SunPassProgram; ShaderProgram m_ForwardRendering; + ShaderProgram m_BlendMapProgram; ShaderProgram m_ShaderProgramNormals; ShaderProgram m_ShaderProgramShadows; diff --git a/src/Shaders/BlendMap.frag.glsl b/src/Shaders/BlendMap.frag.glsl new file mode 100644 index 0000000..47bae51 --- /dev/null +++ b/src/Shaders/BlendMap.frag.glsl @@ -0,0 +1,86 @@ +#version 430 + +layout (binding=0) uniform sampler2D DiffuseTexture; +layout (binding=1) uniform sampler2D ShadowTexture; +layout (binding=2) uniform sampler2D NormalMapTexture; +layout (binding=3) uniform sampler2D SpecularMapTexture; + +//TerrainTextures +layout (binding=4) uniform sampler2D TextureRed; +layout (binding=5) uniform sampler2D TextureGreen; +layout (binding=6) uniform sampler2D TextureBlue; + +uniform float TextureRepeats; //Determines how many times the textures will loop over the terrain +uniform vec3 SunDirection_cameraspace; +uniform mat4 V; + +in VertexData +{ + vec3 Position; + vec3 Normal; + vec2 TextureCoord; + vec4 ShadowCoord; + vec3 Tangent; + vec3 BiTangent; +} Input; + +out vec4 frag_Diffuse; +out vec4 frag_Position; +out vec4 frag_Normal; +out vec4 frag_Specular; + +float Shadow(vec4 ShadowCoord, vec3 normal) +{ + return 1.0; + + if (Input.ShadowCoord.x < 0.0 || Input.ShadowCoord.x > 1.0 || Input.ShadowCoord.y < 0.0 || Input.ShadowCoord.y > 1.0) + return 0.9; + + //Variable bias + vec3 n = normalize(normal); + vec3 l = normalize(SunDirection_cameraspace); + float cosTheta = clamp(dot(n, l), 0.0, 1.0); + float bias = tan(acos(cosTheta)); + bias = clamp(bias, 0.0, 0.00003); + + //Fixed bias + bias = 0; + + if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z + bias) + { + return 0.6; + } + else + { + return 1.0; + } +} + +void main() +{ + vec4 BlendMap = texture2D(DiffuseTexture, Input.TextureCoord.st); + + vec4 TextureRedTexel = texture2D(TextureRed, Input.TextureCoord.st * TextureRepeats); + vec4 TextureGreenTexel = texture2D(TextureGreen, Input.TextureCoord.st * TextureRepeats); + vec4 TextureBlueTexel = texture2D(TextureBlue, Input.TextureCoord.st * TextureRepeats); + + //Mix the Terrain-textures together + TextureRedTexel *= BlendMap.r; + TextureGreenTexel = mix(TextureRedTexel, TextureGreenTexel, BlendMap.g); + vec4 finalBlendTexel = mix(TextureGreenTexel, TextureBlueTexel, BlendMap.b); + + // G-buffer Position + frag_Position = vec4(Input.Position.xyz, 1.0); + + // G-buffer Normal + mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal); + frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); + //frag_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); + //frag_Normal = vec4(Input.Normal, 0.0); + + // Diffuse Texture + frag_Diffuse = finalBlendTexel * Shadow(Input.ShadowCoord, vec3(frag_Normal)); + + //G-buffer Specular + frag_Specular = texture(SpecularMapTexture, Input.TextureCoord); +} \ No newline at end of file diff --git a/src/Shaders/BlendMap.vert.glsl b/src/Shaders/BlendMap.vert.glsl new file mode 100644 index 0000000..4c63e0d --- /dev/null +++ b/src/Shaders/BlendMap.vert.glsl @@ -0,0 +1,35 @@ +#version 430 + +uniform mat4 MVP; +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; +uniform mat4 DepthMVP; + +layout (location = 0) in vec3 Position; +layout (location = 1) in vec3 Normal; +layout (location = 2) in vec2 TextureCoord; +layout (location = 3) in vec3 Tangent; +layout (location = 4) in vec3 BiTangent; + +out VertexData +{ + vec3 Position; + vec3 Normal; + vec2 TextureCoord; + vec4 ShadowCoord; + vec3 Tangent; + vec3 BiTangent; +} Output; + +void main() +{ + gl_Position = MVP * vec4(Position, 1.0); + + Output.Position = vec3(V * M * vec4(Position, 1.0)); + Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0))); + Output.TextureCoord = TextureCoord; + Output.ShadowCoord = DepthMVP * vec4(Position, 1.0); + Output.Tangent = normalize(vec3(inverse(transpose(V * M)) * vec4(Tangent, 0.0))); + Output.BiTangent = normalize(vec3(inverse(transpose(V * M)) * vec4(BiTangent, 0.0))); +} \ No newline at end of file diff --git a/src/Shaders/Fragment.glsl b/src/Shaders/Fragment.glsl index 51a2cf5..439ef3a 100755 --- a/src/Shaders/Fragment.glsl +++ b/src/Shaders/Fragment.glsl @@ -5,13 +5,6 @@ layout (binding=1) uniform sampler2D ShadowTexture; layout (binding=2) uniform sampler2D NormalMapTexture; layout (binding=3) uniform sampler2D SpecularMapTexture; -//TerrainTextures -layout (binding=4) uniform sampler2D AsphaltTexture; -layout (binding=5) uniform sampler2D GrassTexture; -layout (binding=6) uniform sampler2D SandTexture; -layout (binding=7) uniform sampler2D BlendMap; - -uniform float texScale; //Determines how many times the textures will loop over the terrain uniform vec3 SunDirection_cameraspace; uniform mat4 V; @@ -59,25 +52,6 @@ float Shadow(vec4 ShadowCoord, vec3 normal) void main() { - //Fixa så den bara gör detta om modellen har en blend map - //vvvvvv - - vec4 Blend = texture2D(BlendMap, Input.TextureCoord.st ); - vec4 AsphaltTexel = texture2D(AsphaltTexture, Input.TextureCoord.st * texScale); - vec4 GrassTexel = texture2D(GrassTexture, Input.TextureCoord.st * texScale); - vec4 SandTexel = texture2D(SandTexture, Input.TextureCoord.st * texScale); - - //Mix the Terrain-textures together - AsphaltTexel *= Blend.r; - GrassTexel = mix(AsphaltTexel, GrassTexel, Blend.g); - vec4 tex = mix(GrassTexel, SandTexel, Blend.b); - - //^^^^^^ - //Fixa så den bara gör detta om modellen har en blend map - - - - // G-buffer Position frag_Position = vec4(Input.Position.xyz, 1.0); diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index e0a8c6f..678a4de 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -130,6 +130,7 @@ + @@ -233,6 +234,8 @@ + + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index a1bc062..fd91be8 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -169,8 +169,7 @@ {3c2ea0e5-41a1-4b11-a891-1d59ead7223c} - - + {a025d51e-594d-4844-983b-f683726bf1bf} @@ -473,6 +472,9 @@ GUI + + Rendering\Components + @@ -535,5 +537,11 @@ Shaders + + Shaders + + + Shaders + \ No newline at end of file From cc84f04542361d36c1a9be8a2a9bc93d83f8243d Mon Sep 17 00:00:00 2001 From: Tleety Date: Thu, 29 May 2014 23:59:36 +0200 Subject: [PATCH 05/21] Transparent objects working. --- assets | 2 +- src/Components/Model.h | 3 +- src/GUI/Frame.h | 2 +- src/GUI/TextureFrame.h | 2 +- src/GUI/WorldFrame.h | 20 +- src/GameWorld.cpp | 14 +- src/RenderQueue.h | 13 ++ src/Renderer.cpp | 204 ++++++++++++------ src/Renderer.h | 9 +- src/Shaders/FinalForwardPass.frag.glsl | 25 +++ src/Shaders/FinalForwardPass.vert.glsl | 16 ++ src/Shaders/FinalPass.frag.glsl | 3 - src/Shaders/ForwardRendering.frag.glsl | 4 +- vs11/Returngeance/Returngeance.vcxproj | 2 + .../Returngeance/Returngeance.vcxproj.filters | 6 + 15 files changed, 244 insertions(+), 81 deletions(-) create mode 100644 src/Shaders/FinalForwardPass.frag.glsl create mode 100644 src/Shaders/FinalForwardPass.vert.glsl diff --git a/assets b/assets index 066c47e..20edf79 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 066c47ecd71c9f8e7a6d22ed92d42f4be9fc6c3f +Subproject commit 20edf7934ae395a169ab175d17c7da28b7628f29 diff --git a/src/Components/Model.h b/src/Components/Model.h index cacfe17..7c116d4 100755 --- a/src/Components/Model.h +++ b/src/Components/Model.h @@ -11,11 +11,12 @@ namespace Components struct Model : Component { - Model() : Visible(true), ShadowCaster(true) { } + Model() : Visible(true), ShadowCaster(true), Transparent(false) { } std::string ModelFile; Color Color; bool Visible; bool ShadowCaster; + bool Transparent; virtual Model* Clone() const override { return new Model(*this); } }; diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h index a2acb8e..85f756d 100644 --- a/src/GUI/Frame.h +++ b/src/GUI/Frame.h @@ -40,7 +40,7 @@ public: , m_Layer(0) { SetParent(std::shared_ptr(parent)); } - ::RenderQueue RenderQueue; + ::RenderQueuePair RenderQueue; std::shared_ptr Parent() const { return m_Parent; } void SetParent(std::shared_ptr parent) diff --git a/src/GUI/TextureFrame.h b/src/GUI/TextureFrame.h index 6018478..bbdfaef 100644 --- a/src/GUI/TextureFrame.h +++ b/src/GUI/TextureFrame.h @@ -26,7 +26,7 @@ public: job.TextureID = m_Texture->ResourceID; job.Texture = *m_Texture; job.Color = m_Color; - RenderQueue.Add(job); + RenderQueue.Forward.Add(job); renderer->SetCamera(nullptr); renderer->DrawFrame(RenderQueue); diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index 29f4314..89f2ec0 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -69,7 +69,8 @@ public: } else { - EnqueueModel(modelAsset, modelMatrix); + float transparent = modelComponent->Transparent; + EnqueueModel(modelAsset, modelMatrix, transparent); } } @@ -131,7 +132,7 @@ private: std::shared_ptr m_TransformSystem; - void EnqueueModel(Model* model, glm::mat4 modelMatrix) + void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent) { for (auto texGroup : model->TextureGroups) { @@ -144,8 +145,15 @@ private: job.StartIndex = texGroup.StartIndex; job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; - - RenderQueue.Add(job); + job.Transparent = transparent; + if(job.Transparent) + { + RenderQueue.Forward.Add(job); + } + else + { + RenderQueue.Deferred.Add(job); + } } } @@ -167,7 +175,7 @@ private: job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; - RenderQueue.Add(job); + RenderQueue.Deferred.Add(job); } } @@ -178,7 +186,7 @@ private: job.Texture = *texture; job.ModelMatrix = modelMatrix; - RenderQueue.Add(job); + RenderQueue.Forward.Add(job); } }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 6c03f00..d5d4a1d 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -98,7 +98,6 @@ void GameWorld::Initialize() // CommitEntity(ground); //} - { auto ground_middle = CreateEntity(); auto transform = AddComponent(ground_middle); @@ -109,7 +108,7 @@ void GameWorld::Initialize() auto blendmap = AddComponent(ground_middle); blendmap->TextureRed = "Textures/Ground/Sand.png"; blendmap->TextureGreen = "Textures/Ground/Grass.png"; - blendmap->TextureBlue = "Textures/Ground/Asphalt.png"; + blendmap->TextureBlue = "Textures/Ground/Rock.png"; blendmap->TextureRepeats = 30.f; auto physics = AddComponent(ground_middle); @@ -239,6 +238,17 @@ void GameWorld::Initialize() CommitEntity(ground_base_mirrored); } + { + auto tree = CreateEntity(); + auto transform = AddComponent(tree); + transform->Position = glm::vec3(0, -15, 0); + auto model = AddComponent(tree); + model->ModelFile = "Models/Tree/leafs/Leafs.obj"; + model->Transparent = true; + + CommitEntity(tree); + } + EntityID tank1 = CreateTank(1); { auto transform = GetComponent(tank1); diff --git a/src/RenderQueue.h b/src/RenderQueue.h index ba4eae2..a38de8a 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -38,6 +38,7 @@ struct ModelJob : RenderJob unsigned int StartIndex; unsigned int EndIndex; glm::mat4 ModelMatrix; + float Transparent; void CalculateHash() override { @@ -98,4 +99,16 @@ private: std::forward_list> m_Jobs; }; +struct RenderQueuePair +{ + RenderQueue Deferred; + RenderQueue Forward; + + void Clear() + { + Deferred.Clear(); + Forward.Clear(); + } +}; + #endif // RenderQueue_h__ diff --git a/src/Renderer.cpp b/src/Renderer.cpp index b06e513..99f7c61 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -74,10 +74,6 @@ void Renderer::Initialize() m_Camera->SetPosition(glm::vec3(0.0f, 0.0f, 2.f)); glfwSwapInterval(m_VSync); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - glEnable(GL_DEPTH_TEST); - glEnable(GL_SCISSOR_TEST); LoadContent(); } @@ -108,6 +104,11 @@ void Renderer::LoadContent() m_ShaderProgramDebugAABB.Compile(); m_ShaderProgramDebugAABB.Link();*/ + m_FinalForwardPassProgram.AddShader(std::shared_ptr(new VertexShader("Shaders/FinalForwardPass.vert.glsl"))); + m_FinalForwardPassProgram.AddShader(std::shared_ptr(new FragmentShader("Shaders/FinalForwardPass.frag.glsl"))); + m_FinalForwardPassProgram.Compile(); + m_FinalForwardPassProgram.Link(); + m_BlendMapProgram.AddShader(std::shared_ptr(new VertexShader("Shaders/BlendMap.vert.glsl"))); m_BlendMapProgram.AddShader(std::shared_ptr(new FragmentShader("Shaders/BlendMap.frag.glsl"))); m_BlendMapProgram.Compile(); @@ -126,6 +127,7 @@ void Renderer::LoadContent() m_ForwardRendering.AddShader(std::shared_ptr(new VertexShader("Shaders/ForwardRendering.vert.glsl"))); m_ForwardRendering.AddShader(std::shared_ptr(new FragmentShader("Shaders/ForwardRendering.frag.glsl"))); m_ForwardRendering.Compile(); + glBindFragDataLocation(m_ForwardRendering.GetHandle(), 0, "frag_Diffuse"); m_ForwardRendering.Link(); m_ShaderProgramShadows.AddShader(std::shared_ptr(new VertexShader("Shaders/ShadowMap.vert.glsl"))); @@ -261,7 +263,7 @@ void Renderer::Draw(double dt) glfwSwapBuffers(m_Window); } -void Renderer::DrawFrame(RenderQueue &rq) +void Renderer::DrawFrame(RenderQueuePair &rq) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); @@ -305,7 +307,7 @@ void Renderer::DrawFrame(RenderQueue &rq) // } //} - for (auto &job : rq) + for (auto &job : rq.Forward) { //auto modelJob = std::dynamic_pointer_cast(job); //if (modelJob) @@ -358,11 +360,16 @@ void Renderer::DrawFrame(RenderQueue &rq) } } -void Renderer::DrawWorld(RenderQueue &rq) +void Renderer::DrawWorld(RenderQueuePair &rq) { glDisable(GL_BLEND); + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + glEnable(GL_SCISSOR_TEST); - DrawShadowMap(rq); + //DrawShadowMap(rq.Deferred); /* Base pass @@ -385,12 +392,14 @@ void Renderer::DrawWorld(RenderQueue &rq) glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); - DrawFBOScene(rq); + DrawFBOScene(rq.Deferred); /* Lighting pass */ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass); + glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 }; glDrawBuffers(1, lightingPassAttachments); @@ -406,7 +415,7 @@ void Renderer::DrawWorld(RenderQueue &rq) glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture); glCullFace(GL_FRONT); - DrawLightScene(rq); + DrawLightScene(rq.Deferred); DrawSunLightScene(); /* @@ -415,7 +424,9 @@ void Renderer::DrawWorld(RenderQueue &rq) glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); //glViewport(m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height); glViewport(0, 0, m_Width, m_Height); - glScissor(0, 0, m_Width, m_Height); + //glScissor(0, 0, m_Width, m_Height); + glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glClear(GL_DEPTH_BUFFER_BIT); m_FinalPassProgram.Bind(); @@ -433,6 +444,126 @@ void Renderer::DrawWorld(RenderQueue &rq) glBindVertexArray(m_ScreenQuad); glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLES, 0, 6); + + /* + Transparency + */ + ForwardRendering(rq.Forward); +} + +void Renderer::ForwardRendering(RenderQueue &rq) +{ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); + + glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + + // Clear G-buffer + GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + glDrawBuffers(4, attachments); + glClearColor(0.f, 0.f, 0.f, 0.f); + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_FALSE); + + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); + glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); + glm::mat4 MVP; + + m_ForwardRendering.Bind(); + GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle(); + for (auto &job : rq) + { + auto modelJob = std::dynamic_pointer_cast(job); + if (modelJob) + { + glm::mat4 modelMatrix = modelJob->ModelMatrix; + MVP = cameraMatrix * modelMatrix; + + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); + + glBindVertexArray(modelJob->VAO); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); + if (modelJob->NormalTexture != 0) + { + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); + } + if (modelJob->SpecularTexture) + { + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); + } + glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); + + continue; + } + } + //glDepthMask (GL_TRUE); + //glDisable (GL_BLEND); + + /* + Final pass + */ + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glViewport(0, 0, m_Width, m_Height); + glScissor(0, 0, m_Width, m_Height); + + glDisable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + m_FinalForwardPassProgram.Bind(); + //ShaderProgramHandle = m_FinalForwardPassProgram.GetHandle(); + + // Ambient light + //glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "La"), 1, glm::value_ptr(glm::vec3(0.7f))); + //glUniform1f(glGetUniformLocation(ShaderProgramHandle, "Gamma"), Gamma); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); + + glCullFace(GL_BACK); + glBindVertexArray(m_ScreenQuad); + glEnableVertexAttribArray(0); + glDrawArrays(GL_TRIANGLES, 0, 6); + + + + //for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender + //{ + // Model* model; + // glm::mat4 modelMatrix; + // bool visible; + // std::tie(model, modelMatrix, visible, std::ignore) = tuple; + // if (!visible) + // continue; + + // MVP = cameraMatrix * modelMatrix; + // glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); + // glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); + // glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); + // glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height))); + + // glBindVertexArray(model->VAO); + // for (auto texGroup : model->TextureGroups) + // { + // glActiveTexture(GL_TEXTURE0); + // glBindTexture(GL_TEXTURE_2D, *texGroup.Texture); + // glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); + // } + //} } void Renderer::Swap() @@ -855,9 +986,6 @@ void Renderer::FrameBufferTextures() LOG_ERROR("DeferredLighting:Init: m_fbLightingPass incomplete: 0x%x\n", fbStatus); //exit(1); } - - - } void Renderer::DrawFBO() @@ -943,9 +1071,8 @@ void Renderer::DrawFBO() //} } -void Renderer::DrawFBO2() +void Renderer::DrawFBO2(RenderQueue &rq) { - ForwardRendering(); } void Renderer::DrawFBOScene(RenderQueue &rq) @@ -1137,7 +1264,7 @@ void Renderer::DrawSunLightScene() glCullFace(GL_BACK); glEnable(GL_BLEND); - glBlendEquation (GL_FUNC_ADD); + glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE,GL_ONE); glDisable (GL_DEPTH_TEST); @@ -1216,49 +1343,6 @@ void Renderer::UpdateSunProjection() //Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map. } -void Renderer::ForwardRendering() -{ - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, m_Width, m_Height); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glClearColor(0.0f, 0.5f, 0.0f, 1.0f); - - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - - glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix(); - glm::mat4 MVP; - - m_ForwardRendering.Bind(); - GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle(); - - for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender - { - Model* model; - glm::mat4 modelMatrix; - bool visible; - std::tie(model, modelMatrix, visible, std::ignore) = tuple; - if (!visible) - continue; - - MVP = cameraMatrix * modelMatrix; - glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); - glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); - glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); - glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height))); - - glBindVertexArray(model->VAO); - for (auto texGroup : model->TextureGroups) - { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, *texGroup.Texture); - glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); - } - } -} - void Renderer::RegisterCamera(int identifier, float FOV, float nearClip, float farClip) { m_Cameras[identifier] = std::make_shared(FOV, nearClip, farClip); diff --git a/src/Renderer.h b/src/Renderer.h index fe51f00..445601f 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -53,8 +53,8 @@ public: m_Camera = camera; } - void DrawFrame(RenderQueue &rq); - void DrawWorld(RenderQueue &rq); + void DrawFrame(RenderQueuePair &rq); + void DrawWorld(RenderQueuePair &rq); void Swap(); #pragma endregion @@ -174,6 +174,7 @@ private: ShaderProgram m_SunPassProgram; ShaderProgram m_ForwardRendering; ShaderProgram m_BlendMapProgram; + ShaderProgram m_FinalForwardPassProgram; ShaderProgram m_ShaderProgramNormals; ShaderProgram m_ShaderProgramShadows; @@ -190,7 +191,7 @@ private: void CreateShadowMap(int resolution); void FrameBufferTextures(); void DrawFBO(); - void DrawFBO2(); + void DrawFBO2(RenderQueue &rq); void DrawFBOScene(RenderQueue &rq); void DrawLightScene(RenderQueue &rq); void DrawSunLightScene(); @@ -198,7 +199,7 @@ private: glm::mat4 CreateLightMatrix(Light &_light); void UpdateSunProjection(); void CreateNormalMapTangent(); - void ForwardRendering(); + void ForwardRendering(RenderQueue &rq); GLuint CreateQuad(); diff --git a/src/Shaders/FinalForwardPass.frag.glsl b/src/Shaders/FinalForwardPass.frag.glsl new file mode 100644 index 0000000..022efde --- /dev/null +++ b/src/Shaders/FinalForwardPass.frag.glsl @@ -0,0 +1,25 @@ +#version 430 + +//uniform vec3 La; + +layout (binding=0) uniform sampler2D DiffuseTexture; + +in VertexData +{ + vec3 Position; + vec2 TextureCoord; +} Input; + +out vec4 FragmentColor; + +void main() +{ + vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord); + //vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord); + + //FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0); + //FragmentColor = DiffuseTexel; + + FragmentColor = DiffuseTexel; + //FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a); +} \ No newline at end of file diff --git a/src/Shaders/FinalForwardPass.vert.glsl b/src/Shaders/FinalForwardPass.vert.glsl new file mode 100644 index 0000000..05deece --- /dev/null +++ b/src/Shaders/FinalForwardPass.vert.glsl @@ -0,0 +1,16 @@ +#version 430 + +layout(location = 0) in vec3 Position; + +out VertexData +{ + vec3 Position; + vec2 TextureCoord; +} Output; + +void main() +{ + gl_Position = vec4(Position, 1.0); + Output.Position = Position; + Output.TextureCoord = (vec2(Position) + 1) / 2; +} \ No newline at end of file diff --git a/src/Shaders/FinalPass.frag.glsl b/src/Shaders/FinalPass.frag.glsl index 26073a2..5a4faf0 100644 --- a/src/Shaders/FinalPass.frag.glsl +++ b/src/Shaders/FinalPass.frag.glsl @@ -5,7 +5,6 @@ uniform float Gamma; layout (binding=0) uniform sampler2D DiffuseTexture; layout (binding=1) uniform sampler2D LightingTexture; -layout (binding=2) uniform sampler2D ShadowTexture; in VertexData { @@ -19,12 +18,10 @@ void main() { vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord); vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord); - vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord); //FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0); //FragmentColor = DiffuseTexel; FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0); //FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a); - } \ No newline at end of file diff --git a/src/Shaders/ForwardRendering.frag.glsl b/src/Shaders/ForwardRendering.frag.glsl index b76f3aa..8a56b40 100644 --- a/src/Shaders/ForwardRendering.frag.glsl +++ b/src/Shaders/ForwardRendering.frag.glsl @@ -10,11 +10,11 @@ in VertexData { vec2 TextureCoord; } Input; -out vec4 fragmentColor; +out vec4 frag_Diffuse; void main() { // Texture vec4 texel = texture(texture0, Input.TextureCoord); - fragmentColor = texel * Color; + frag_Diffuse = texel; } \ No newline at end of file diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 3ddaaff..c195934 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -238,6 +238,8 @@ + + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index f3893ce..23799af 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -549,5 +549,11 @@ Shaders + + Shaders + + + Shaders + \ No newline at end of file From d17450b55499c14b90d3d9a77f550b847afc1b8b Mon Sep 17 00:00:00 2001 From: Stiffly Date: Fri, 30 May 2014 00:12:28 +0200 Subject: [PATCH 06/21] Some Explosion stuff --- src/InputManager.cpp | 14 ++++++++++++++ src/InputManager.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/InputManager.cpp b/src/InputManager.cpp index b20e072..11f21d7 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,6 +85,20 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } + if(m_CurrentKeyState[GLFW_KEY_B]) + { + Events::CreateExplosion e; + e.LifeTime = 1; + e.ParticleScale = 6; + e.ParticlesToSpawn = 50; + e.Position = glm::vec3(0, -20, 40); + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 3; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/SeriousParticle.png"; + EventBroker->Publish(e); + } + // // Lock mouse while holding LMB // if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) // { diff --git a/src/InputManager.h b/src/InputManager.h index 69827ba..94d178d 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -12,6 +12,7 @@ #include "Events/LockMouse.h" #include "Events/GamepadAxis.h" #include "Events/GamepadButton.h" +#include "Events/CreateExplosion.h" class InputManager { From 9ccf8ecc428aae328fa20549c415e0002b61f30a Mon Sep 17 00:00:00 2001 From: Tleety Date: Fri, 30 May 2014 19:53:00 +0200 Subject: [PATCH 07/21] Fixed being able to draw sprites and normal/specular maps for terrain --- assets | 2 +- src/Components/BlendMap.h | 12 +++++++ src/GUI/WorldFrame.h | 43 +++++++++++++++++++++----- src/GameWorld.cpp | 9 ++++-- src/Model.cpp | 2 +- src/RenderQueue.h | 6 ++++ src/Renderer.cpp | 32 ++++++++++++++++++- src/Shaders/BlendMap.frag.glsl | 30 +++++++++++++++--- src/Shaders/ForwardRendering.frag.glsl | 2 +- 9 files changed, 119 insertions(+), 19 deletions(-) diff --git a/assets b/assets index 20edf79..5de9bdc 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 20edf7934ae395a169ab175d17c7da28b7628f29 +Subproject commit 5de9bdcff878ab06a589101cf718fb74c3344e14 diff --git a/src/Components/BlendMap.h b/src/Components/BlendMap.h index 3106e04..aba9f7c 100644 --- a/src/Components/BlendMap.h +++ b/src/Components/BlendMap.h @@ -10,13 +10,25 @@ namespace Components { BlendMap() : TextureRed("Textures/ErrorTextureRed.png") + , TextureRedNormal("Textures/NeutralNormalMap.png") + , TextureRedSpecular("Textures/NeutralSpecularMap.png") , TextureGreen("Textures/ErrorTextureGreen.png") + , TextureGreenNormal("Textures/NeutralNormalMap.png") + , TextureGreenSpecular("Textures/NeutralSpecularMap.png") , TextureBlue("Textures/ErrorTextureBlue.png") + , TextureBlueNormal("Textures/NeutralNormalMap.png") + , TextureBlueSpecular("Textures/NeutralSpecularMap.png") , TextureRepeats(100.f) { } std::string TextureRed; + std::string TextureRedNormal; + std::string TextureRedSpecular; std::string TextureGreen; + std::string TextureGreenNormal; + std::string TextureGreenSpecular; std::string TextureBlue; + std::string TextureBlueNormal; + std::string TextureBlueSpecular; float TextureRepeats; virtual BlendMap* Clone() const override { return new BlendMap(*this); } diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index 89f2ec0..a0c76e8 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -61,11 +61,24 @@ public: auto blendmapComponent = m_World->GetComponent(entity); if (blendmapComponent) { - auto textureRed = ResourceManager->Load("Texture", blendmapComponent->TextureRed); - auto textureGreen = ResourceManager->Load("Texture", blendmapComponent->TextureGreen); - auto textureBlue = ResourceManager->Load("Texture", blendmapComponent->TextureBlue); + BlendMapTexture RedTexture; + RedTexture.Diffuse = *ResourceManager->Load("Texture", blendmapComponent->TextureRed); + RedTexture.Normal = *ResourceManager->Load("Texture", blendmapComponent->TextureRedNormal); + RedTexture.Specular = *ResourceManager->Load("Texture", blendmapComponent->TextureRedSpecular); + + BlendMapTexture GreenTexture; + GreenTexture.Diffuse = *ResourceManager->Load("Texture", blendmapComponent->TextureGreen); + GreenTexture.Normal = *ResourceManager->Load("Texture", blendmapComponent->TextureGreenNormal); + GreenTexture.Specular = *ResourceManager->Load("Texture", blendmapComponent->TextureGreenSpecular); + + BlendMapTexture BlueTexture; + BlueTexture.Diffuse = *ResourceManager->Load("Texture", blendmapComponent->TextureBlue); + BlueTexture.Normal = *ResourceManager->Load("Texture", blendmapComponent->TextureBlueNormal); + BlueTexture.Specular = *ResourceManager->Load("Texture", blendmapComponent->TextureBlueSpecular); + float textureRepeat = blendmapComponent->TextureRepeats; - EnqueueBlendMapModel(modelAsset, textureRed, textureGreen, textureBlue, textureRepeat, modelMatrix); + + EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix); } else { @@ -113,6 +126,13 @@ protected: std::shared_ptr m_World; private: + struct BlendMapTexture + { + GLuint Diffuse; + GLuint Normal; + GLuint Specular; + }; + EventRelay m_ESetViewportCamera; bool OnSetViewportCamera(const Events::SetViewportCamera &event) { @@ -157,7 +177,7 @@ private: } } - void EnqueueBlendMapModel(Model* model, Texture* textureRed, Texture* textureGreen, Texture* textureBlue, float textureRepeat, glm::mat4 modelMatrix) + void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix) { for (auto texGroup : model->TextureGroups) { @@ -166,9 +186,15 @@ private: job.DiffuseTexture = *texGroup.Texture; job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0; job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0; - job.BlendMapTextureRed = (*textureRed); - job.BlendMapTextureGreen = (*textureGreen); - job.BlendMapTextureBlue = (*textureBlue); + job.BlendMapTextureRed = textureRed.Diffuse; + job.BlendMapTextureRedNormal = textureRed.Normal; + job.BlendMapTextureRedSpecular = textureRed.Specular; + job.BlendMapTextureGreen = textureGreen.Diffuse; + job.BlendMapTextureGreenNormal = textureGreen.Normal; + job.BlendMapTextureGreenSpecular = textureGreen.Specular; + job.BlendMapTextureBlue = textureBlue.Diffuse; + job.BlendMapTextureBlueNormal = textureBlue.Normal; + job.BlendMapTextureBlueSpecular = textureBlue.Specular; job.TextureRepeat = textureRepeat; job.VAO = model->VAO; job.StartIndex = texGroup.StartIndex; @@ -188,6 +214,7 @@ private: RenderQueue.Forward.Add(job); } + }; } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index d5d4a1d..3f2d2b9 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -106,9 +106,12 @@ void GameWorld::Initialize() auto model = AddComponent(ground_middle); model->ModelFile = "Models/TerrainFiveIstles/Middle.obj"; auto blendmap = AddComponent(ground_middle); - blendmap->TextureRed = "Textures/Ground/Sand.png"; - blendmap->TextureGreen = "Textures/Ground/Grass.png"; - blendmap->TextureBlue = "Textures/Ground/Rock.png"; + blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; + blendmap->TextureBlueNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; + blendmap->TextureBlueNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; blendmap->TextureRepeats = 30.f; auto physics = AddComponent(ground_middle); diff --git a/src/Model.cpp b/src/Model.cpp index 1186671..dd5757c 100755 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -93,7 +93,7 @@ Model::Model(std::shared_ptr rm, OBJ &obj) if (Vertices.size() > 0) { CreateTangents(); - //getSimilarVertexIndex(); + getSimilarVertexIndex(); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); } else diff --git a/src/RenderQueue.h b/src/RenderQueue.h index a38de8a..69eed26 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -49,8 +49,14 @@ struct ModelJob : RenderJob struct BlendMapModelJob : ModelJob { GLuint BlendMapTextureRed; + GLuint BlendMapTextureRedNormal; + GLuint BlendMapTextureRedSpecular; GLuint BlendMapTextureGreen; + GLuint BlendMapTextureGreenNormal; + GLuint BlendMapTextureGreenSpecular; GLuint BlendMapTextureBlue; + GLuint BlendMapTextureBlueNormal; + GLuint BlendMapTextureBlueSpecular; float TextureRepeat; }; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 99f7c61..1476306 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -490,6 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq) glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); + glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(modelJob->Color)); glBindVertexArray(modelJob->VAO); @@ -509,6 +510,23 @@ void Renderer::ForwardRendering(RenderQueue &rq) continue; } + + auto spriteJob = std::dynamic_pointer_cast(job); + if (spriteJob) + { + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color)); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); + glBindVertexArray(m_ScreenQuad); + glDrawArrays(GL_TRIANGLES, 0, 6); + + continue; + } } //glDepthMask (GL_TRUE); //glDisable (GL_BLEND); @@ -1142,9 +1160,21 @@ void Renderer::DrawFBOScene(RenderQueue &rq) glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRed); glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreen); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRedNormal); glActiveTexture(GL_TEXTURE6); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRedSpecular); + glActiveTexture(GL_TEXTURE7); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreen); + glActiveTexture(GL_TEXTURE8); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreenNormal); + glActiveTexture(GL_TEXTURE9); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreenSpecular); + glActiveTexture(GL_TEXTURE10); glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlue); + glActiveTexture(GL_TEXTURE11); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlueNormal); + glActiveTexture(GL_TEXTURE12); + glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlueSpecular); glDrawArrays(GL_TRIANGLES, blendMapJob->StartIndex, blendMapJob->EndIndex - blendMapJob->StartIndex + 1); diff --git a/src/Shaders/BlendMap.frag.glsl b/src/Shaders/BlendMap.frag.glsl index 038894b..2e128be 100644 --- a/src/Shaders/BlendMap.frag.glsl +++ b/src/Shaders/BlendMap.frag.glsl @@ -7,8 +7,14 @@ layout (binding=3) uniform sampler2D SpecularMapTexture; //TerrainTextures layout (binding=4) uniform sampler2D TextureRed; -layout (binding=5) uniform sampler2D TextureGreen; -layout (binding=6) uniform sampler2D TextureBlue; +layout (binding=5) uniform sampler2D TextureRedNormal; +layout (binding=6) uniform sampler2D TextureRedSpecular; +layout (binding=7) uniform sampler2D TextureGreen; +layout (binding=8) uniform sampler2D TextureGreenNormal; +layout (binding=9) uniform sampler2D TextureGreenSpecular; +layout (binding=10) uniform sampler2D TextureBlue; +layout (binding=11) uniform sampler2D TextureBlueNormal; +layout (binding=12) uniform sampler2D TextureBlueSpecular; uniform float TextureRepeats; //Determines how many times the textures will loop over the terrain uniform vec3 SunDirection_cameraspace; @@ -61,21 +67,37 @@ void main() vec4 BlendMap = texture(DiffuseTexture, Input.TextureCoord); vec4 TextureRedTexel = texture(TextureRed, Input.TextureCoord * TextureRepeats); + vec4 TextureRedTexelNormal = texture(TextureRedNormal, Input.TextureCoord * TextureRepeats); + //vec4 TextureRedTexelSpecular = texture(TextureRedSpecular, Input.TextureCoord * TextureRepeats); + vec4 TextureGreenTexel = texture(TextureGreen, Input.TextureCoord * TextureRepeats); + vec4 TextureGreenTexelNormal = texture(TextureGreenNormal, Input.TextureCoord * TextureRepeats); + //vec4 TextureGreenTexelSpecular = texture(TextureGreenSpecular, Input.TextureCoord * TextureRepeats); + vec4 TextureBlueTexel = texture(TextureBlue, Input.TextureCoord * TextureRepeats); + vec4 TextureBlueTexelNormal = texture(TextureBlueNormal, Input.TextureCoord * TextureRepeats); + //vec4 TextureBlueTexelSpecular = texture(TextureBlueSpecular, Input.TextureCoord * TextureRepeats); //Mix the Terrain-textures together TextureRedTexel *= BlendMap.r; TextureGreenTexel = mix(TextureRedTexel, TextureGreenTexel, BlendMap.g); vec4 finalBlendTexel = mix(TextureGreenTexel, TextureBlueTexel, BlendMap.b); + + TextureRedTexelNormal *= BlendMap.r; + TextureGreenTexelNormal = mix(TextureRedTexelNormal, TextureGreenTexelNormal, BlendMap.g); + vec4 finalBlendTexelNormal = mix(TextureGreenTexelNormal, TextureBlueTexelNormal, BlendMap.b); + + //TextureRedTexelSpecular *= BlendMap.r; + //TextureGreenTexelSpecular = mix(TextureRedTexelSpecular, TextureGreenTexelSpecular, BlendMap.g); + //vec4 finalBlendTexelSpecular = mix(TextureGreenTexelSpecular, TextureBlueTexelSpecular, BlendMap.b); // G-buffer Position frag_Position = vec4(Input.Position.xyz, 1.0); // G-buffer Normal mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal); - frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); - //frag_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0)); + frag_Normal = normalize(vec4(TBN * vec3(finalBlendTexelNormal), 0.0)); + //frag_Diffuse = normalize(vec4(TBN * vec3(finalBlendTexelNormal), 0.0)); //frag_Normal = vec4(Input.Normal, 0.0); // Diffuse Texture diff --git a/src/Shaders/ForwardRendering.frag.glsl b/src/Shaders/ForwardRendering.frag.glsl index 8a56b40..0d3a7c8 100644 --- a/src/Shaders/ForwardRendering.frag.glsl +++ b/src/Shaders/ForwardRendering.frag.glsl @@ -16,5 +16,5 @@ void main() { // Texture vec4 texel = texture(texture0, Input.TextureCoord); - frag_Diffuse = texel; + frag_Diffuse = texel * Color; } \ No newline at end of file From ed803733dae3903b69028be1eb25fd94b4886b97 Mon Sep 17 00:00:00 2001 From: Tleety Date: Fri, 30 May 2014 19:55:49 +0200 Subject: [PATCH 08/21] Merged ASSets --- assets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets b/assets index 5de9bdc..74035fa 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 5de9bdcff878ab06a589101cf718fb74c3344e14 +Subproject commit 74035fae2626e2e62f803cd7d9817d1e47353f69 From 31348e774ecb2ef8f869284334d42c576f8a78c1 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Fri, 30 May 2014 20:00:09 +0200 Subject: [PATCH 09/21] Trying some stuff, this build did not support sprite rendering --- src/GameWorld.cpp | 14 ++++++++++++-- src/InputManager.cpp | 6 +++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 3eab400..69682b6 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -239,14 +239,24 @@ void GameWorld::Initialize() } { - auto tree = CreateEntity(); + /* auto tree = CreateEntity(); auto transform = AddComponent(tree); transform->Position = glm::vec3(0, -15, 0); auto model = AddComponent(tree); model->ModelFile = "Models/Tree/leafs/Leafs.obj"; model->Transparent = true; - CommitEntity(tree); + CommitEntity(tree);*/ + + + auto thing = CreateEntity(); + auto transform = AddComponent(thing); + transform->Position = glm::vec3(0,15,0); + transform->Scale = glm::vec3(3); +// auto model = AddComponent(thing); +// model->ModelFile = "Models/Barrel/Barrel.obj"; + auto sprite = AddComponent(thing); + sprite->SpriteFile = "Textures/Sprites/SeriousParticle.png"; } EntityID tank1 = CreateTank(1); diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 11f21d7..5e6c942 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,13 +85,13 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } - if(m_CurrentKeyState[GLFW_KEY_B]) + if(m_CurrentKeyState[GLFW_KEY_Z]) { Events::CreateExplosion e; e.LifeTime = 1; e.ParticleScale = 6; - e.ParticlesToSpawn = 50; - e.Position = glm::vec3(0, -20, 40); + e.ParticlesToSpawn = 1; + e.Position = glm::vec3(0, -15, 0); e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); e.Speed = 3; e.SpreadAngle = glm::pi(); From 6c8fff9ed0c5bc3d190d99097c037401001b7b10 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 30 May 2014 22:00:20 +0200 Subject: [PATCH 10/21] Non-retardedly slow sprite rendering --- src/GUI/WorldFrame.h | 2 ++ src/RenderQueue.h | 10 ++++++++++ src/Renderer.cpp | 15 +++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index a0c76e8..5b86204 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -120,6 +120,8 @@ public: ); } } + + RenderQueue.Sort(); } protected: diff --git a/src/RenderQueue.h b/src/RenderQueue.h index 69eed26..932dd69 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -83,6 +83,10 @@ public: { job.CalculateHash(); m_Jobs.push_front(std::shared_ptr(new T(job))); + } + + void Sort() + { m_Jobs.sort(); } @@ -115,6 +119,12 @@ struct RenderQueuePair Deferred.Clear(); Forward.Clear(); } + + void Sort() + { + Deferred.Sort(); + Forward.Sort(); + } }; #endif // RenderQueue_h__ diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 1476306..31f714a 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -490,7 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq) glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); - glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(modelJob->Color)); + glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); glBindVertexArray(modelJob->VAO); @@ -514,11 +514,14 @@ void Renderer::ForwardRendering(RenderQueue &rq) auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color)); + glm::mat4 modelMatrix = spriteJob->ModelMatrix; + MVP = cameraMatrix * modelMatrix; + + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP))); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix))); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4(m_Camera->ViewMatrix()))); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4(cameraProjection))); + glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); From 28c3cf5e1654d9dfb1c2603b36cd75d2e6f27be5 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Fri, 30 May 2014 22:19:03 +0200 Subject: [PATCH 11/21] Optimized ParticleSystem. Still can't see particles though D: --- src/Components/Particle.h | 1 + src/GameWorld.cpp | 92 +++++++++++++-------------- src/Systems/ParticleSystem.cpp | 113 ++++++++++++++++----------------- src/Systems/ParticleSystem.h | 11 +--- 4 files changed, 101 insertions(+), 116 deletions(-) diff --git a/src/Components/Particle.h b/src/Components/Particle.h index d08b1a7..d720dc5 100644 --- a/src/Components/Particle.h +++ b/src/Components/Particle.h @@ -14,6 +14,7 @@ namespace Components std::vector ColorSpectrum; std::vector ScaleSpectrum; double LifeTime; + double SpawnTime; std::vector VelocitySpectrum; std::vector AngularVelocitySpectrum; std::vector OrientationSpectrum; //Keep? diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 93a73ed..95845b9 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -745,29 +745,29 @@ EntityID GameWorld::CreateTank(int playerID) } CommitEntity(wheel); - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); +// auto entity = CreateEntity(tank); +// auto transformComponent = AddComponent(entity); +// transformComponent->Position = glm::vec3(2, -1.7, 2.0); +// transformComponent->Scale = glm::vec3(3, 3, 3); +// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); +// auto emitterComponent = AddComponent(entity); +// emitterComponent->SpawnCount = 2; +// emitterComponent->SpawnFrequency = 0.005; +// emitterComponent->SpreadAngle = glm::pi(); +// emitterComponent->UseGoalVelocity = false; +// emitterComponent->LifeTime = 0.5; +// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); +// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); +// CommitEntity(entity); +// +// auto particleEntity = CreateEntity(entity); +// auto TEMP = AddComponent(particleEntity); +// TEMP->Scale = glm::vec3(0); +// auto spriteComponent = AddComponent(particleEntity); +// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; +// emitterComponent->ParticleTemplate = particleEntity; +// +// CommitEntity(particleEntity); } { @@ -830,29 +830,29 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(wheel); #pragma endregion - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(-2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); +// auto entity = CreateEntity(tank); +// auto transformComponent = AddComponent(entity); +// transformComponent->Position = glm::vec3(-2, -1.7, 2.0); +// transformComponent->Scale = glm::vec3(3, 3, 3); +// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); +// auto emitterComponent = AddComponent(entity); +// emitterComponent->SpawnCount = 2; +// emitterComponent->SpawnFrequency = 0.005; +// emitterComponent->SpreadAngle = glm::pi(); +// emitterComponent->UseGoalVelocity = false; +// emitterComponent->LifeTime = 0.5; +// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); +// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); +// CommitEntity(entity); +// +// auto particleEntity = CreateEntity(entity); +// auto TEMP = AddComponent(particleEntity); +// TEMP->Scale = glm::vec3(0); +// auto spriteComponent = AddComponent(particleEntity); +// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; +// emitterComponent->ParticleTemplate = particleEntity; +// +// CommitEntity(particleEntity); } CommitEntity(tank); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 39ea2fb..a02ea78 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -52,64 +52,59 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID SpawnParticles(entity); emitterComponent->TimeSinceLastSpawn = 0; } + } - std::list::iterator it; - for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();) + auto particleComponent = m_World->GetComponent(entity); + if(particleComponent) + { + EntityID particleID = entity; + auto transformComponent = m_World->GetComponent(particleID); + + double timeLived = glfwGetTime() - particleComponent->SpawnTime; + if(timeLived > particleComponent->LifeTime) { - EntityID particleID = (it)->ParticleID; - auto transformComponent = m_World->GetComponent(particleID); - auto particleComponent = m_World->GetComponent(particleID); + m_World->RemoveEntity(particleID); + } + else + { + // FIX: calculate once + float timeProgress = timeLived / particleComponent->LifeTime; + // ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color); + // Scale interpolation + if(particleComponent->ScaleSpectrum.size() > 1) + VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale); + // Velocity interpolation + if(particleComponent->VelocitySpectrum.size() > 1) + VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity); + - double timeLived = glfwGetTime() - it->SpawnTime; - if(timeLived > particleComponent->LifeTime) + /*// Angular velocity interpolation + if (particleComponent->AngularVelocitySpectrum.size() != 0) { - m_World->RemoveEntity(particleID); - it = m_ParticleEmitter[entity].erase(it); + if(particleComponent->AngularVelocitySpectrum.size() > 1) + { + ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity); + transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); + } + else + { + transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation); + //it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); + } } - else + + //Angular velocity interpolation + if(particleComponent->OrientationSpectrum.size() > 1) { - // FIX: calculate once - float timeProgress = timeLived / particleComponent->LifeTime; - // ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color); - // Scale interpolation - if(particleComponent->ScaleSpectrum.size() > 1) - VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale); - // Velocity interpolation - if(particleComponent->VelocitySpectrum.size() > 1) - VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity); - - // Angular velocity interpolation - if (particleComponent->AngularVelocitySpectrum.size() != 0) - { - if(particleComponent->AngularVelocitySpectrum.size() > 1) - { - ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity); - transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); - } - else - { - transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation); - //it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation); - } - } - - //Angular velocity interpolation - if(particleComponent->OrientationSpectrum.size() > 1) - { - VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation); - glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]); - glm::vec3 v2 = (it->Orientation); - glm::vec3 v3 = glm::normalize(glm::cross(v1,v2)); - float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2))); + VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation); + glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]); + glm::vec3 v2 = (it->Orientation); + glm::vec3 v3 = glm::normalize(glm::cross(v1,v2)); + float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2))); - transformComponent->Orientation = glm::angleAxis(angle, v3); - } - - - transformComponent->Position += transformComponent->Velocity * (float)dt; - - it++; - } + transformComponent->Orientation = glm::angleAxis(angle, v3); + }*/ + transformComponent->Position += transformComponent->Velocity * (float)dt; } } } @@ -173,15 +168,13 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) particle->AngularVelocitySpectrum = eComponent->AngularVelocitySpectrum; - ParticleData data; - data.ParticleID = ent; - data.SpawnTime = glfwGetTime(); - if (particle->AngularVelocitySpectrum.size() != 0) - data.AngularVelocity = particle->AngularVelocitySpectrum[0]; - if (particle->OrientationSpectrum.size() != 0) - data.Orientation = particle->OrientationSpectrum[0]; - else data.Orientation = eOrientation * glm::vec3(0,0,-1); - m_ParticleEmitter[emitterID].push_back(data); + particle->SpawnTime = glfwGetTime(); +// if (particle->AngularVelocitySpectrum.size() != 0) +// data.AngularVelocity = particle->AngularVelocitySpectrum[0]; +// if (particle->OrientationSpectrum.size() != 0) +// data.Orientation = particle->OrientationSpectrum[0]; +// else data.Orientation = eOrientation * glm::vec3(0,0,-1); + //m_ParticleEmitter[emitterID].push_back(data); } } diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index 0ecd79c..c7a59f2 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -16,15 +16,6 @@ namespace Systems { - struct ParticleData - { - EntityID ParticleID; - double SpawnTime; - float AngularVelocity; - glm::vec3 Orientation; - Color color; - }; - class ParticleSystem : public System { public: @@ -49,7 +40,7 @@ private: //void ColorInterpolation(double timeProgress, std::vector spectrum, Color &color); void ScalarInterpolation(double timeProgress, std::vector spectrum, float &alpha); void Billboard(); - std::map> m_ParticleEmitter; + //std::map> m_ParticleEmitter; std::map m_TimeSinceLastSpawn; std::map m_ExplosionEmitters; std::shared_ptr m_TransformSystem; From 0e612cb3f3d6df721729abf80313b1a8ec23a7a4 Mon Sep 17 00:00:00 2001 From: Tleety Date: Fri, 30 May 2014 22:45:00 +0200 Subject: [PATCH 12/21] Colors now working correcly. --- src/Components/Model.h | 5 ++--- src/Components/Sprite.h | 5 +++-- src/GUI/GameFrame.h | 4 ++-- src/GUI/WorldFrame.h | 21 ++++++++++++++------- src/GameWorld.cpp | 36 ++++++++++++++++++++---------------- src/Renderer.cpp | 15 ++++++--------- 6 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/Components/Model.h b/src/Components/Model.h index 7c116d4..7ac792f 100755 --- a/src/Components/Model.h +++ b/src/Components/Model.h @@ -4,16 +4,15 @@ #include #include "Component.h" -#include "Color.h" namespace Components { struct Model : Component { - Model() : Visible(true), ShadowCaster(true), Transparent(false) { } + Model() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)), Visible(true), ShadowCaster(true), Transparent(false) { } std::string ModelFile; - Color Color; + glm::vec4 Color; bool Visible; bool ShadowCaster; bool Transparent; diff --git a/src/Components/Sprite.h b/src/Components/Sprite.h index 29c930f..d28f058 100755 --- a/src/Components/Sprite.h +++ b/src/Components/Sprite.h @@ -4,15 +4,16 @@ #include #include "Component.h" -#include "Color.h" namespace Components { struct Sprite : Component { + Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { } + std::string SpriteFile; - Color Color; + glm::vec4 Color; virtual Sprite* Clone() const override { return new Sprite(*this); } }; diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h index 8286997..d99bc64 100644 --- a/src/GUI/GameFrame.h +++ b/src/GUI/GameFrame.h @@ -25,13 +25,13 @@ public: vp1->X = 0; vp1->Width = 640; vp1->Height = 720 / 2; - new PlayerHUD(vp1, "PlayerHUD", m_World, 1); + //new PlayerHUD(vp1, "PlayerHUD", m_World, 1); vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2->X = vp1->Right(); vp2->Width = 640; vp2->Height = 720 / 2; - new PlayerHUD(vp2, "PlayerHUD", m_World, 2); + //new PlayerHUD(vp2, "PlayerHUD", m_World, 2); auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World); vpc->Y = 720 / 2; diff --git a/src/GUI/WorldFrame.h b/src/GUI/WorldFrame.h index a0c76e8..5aa3746 100644 --- a/src/GUI/WorldFrame.h +++ b/src/GUI/WorldFrame.h @@ -44,6 +44,10 @@ public: { EntityID entity = pair.first; + auto templateComponent = m_World->GetComponent(entity); + if (templateComponent) + continue; + auto transform = m_World->GetComponent(entity); if (!transform) continue; @@ -78,12 +82,11 @@ public: float textureRepeat = blendmapComponent->TextureRepeats; - EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix); + EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix, modelComponent->Color); } else { - float transparent = modelComponent->Transparent; - EnqueueModel(modelAsset, modelMatrix, transparent); + EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color); } } @@ -100,7 +103,7 @@ public: glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position) * glm::toMat4(orientation2D) * glm::scale(absoluteTransform.Scale); - EnqueueSprite(textureAsset, modelMatrix); + EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color); } } @@ -152,7 +155,7 @@ private: std::shared_ptr m_TransformSystem; - void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent) + void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color) { for (auto texGroup : model->TextureGroups) { @@ -166,6 +169,8 @@ private: job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; job.Transparent = transparent; + job.Color = color; + if(job.Transparent) { RenderQueue.Forward.Add(job); @@ -177,7 +182,7 @@ private: } } - void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix) + void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix, glm::vec4 color) { for (auto texGroup : model->TextureGroups) { @@ -200,17 +205,19 @@ private: job.StartIndex = texGroup.StartIndex; job.EndIndex = texGroup.EndIndex; job.ModelMatrix = modelMatrix; + job.Color = color; RenderQueue.Deferred.Add(job); } } - void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix) + void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color) { SpriteJob job; job.TextureID = texture->ResourceID; job.Texture = *texture; job.ModelMatrix = modelMatrix; + job.Color = color; RenderQueue.Forward.Add(job); } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 3f2d2b9..27fa9fd 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -750,14 +750,16 @@ EntityID GameWorld::CreateTank(int playerID) emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); + { + auto particleEntity = CreateEntity(entity); + auto templateComponent = AddComponent(particleEntity); + auto TEMP = AddComponent(particleEntity); + TEMP->Scale = glm::vec3(0); + auto spriteComponent = AddComponent(particleEntity); + spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; + CommitEntity(particleEntity); + emitterComponent->ParticleTemplate = particleEntity; + } } { @@ -835,14 +837,16 @@ EntityID GameWorld::CreateTank(int playerID) emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); CommitEntity(entity); - auto particleEntity = CreateEntity(entity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - emitterComponent->ParticleTemplate = particleEntity; - - CommitEntity(particleEntity); + { + auto particleEntity = CreateEntity(entity); + auto templateComponent = AddComponent(particleEntity); + auto TEMP = AddComponent(particleEntity); + TEMP->Scale = glm::vec3(0); + auto spriteComponent = AddComponent(particleEntity); + spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; + CommitEntity(particleEntity); + emitterComponent->ParticleTemplate = particleEntity; + } } CommitEntity(tank); diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 1476306..1ce74aa 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -490,7 +490,7 @@ void Renderer::ForwardRendering(RenderQueue &rq) glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); - glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(modelJob->Color)); + glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); glBindVertexArray(modelJob->VAO); @@ -514,11 +514,11 @@ void Renderer::ForwardRendering(RenderQueue &rq) auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); - glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color)); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4())); + glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, spriteJob->Texture); @@ -557,8 +557,6 @@ void Renderer::ForwardRendering(RenderQueue &rq) glEnableVertexAttribArray(0); glDrawArrays(GL_TRIANGLES, 0, 6); - - //for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender //{ // Model* model; @@ -589,7 +587,6 @@ void Renderer::Swap() glfwSwapBuffers(m_Window); } - void Renderer::DrawSkybox() { //glBindFramebuffer(GL_FRAMEBUFFER, 0); From ee2f7fcecf8d22189cb6f78b73af9431dd3dfbfd Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 01:11:14 +0200 Subject: [PATCH 13/21] Added some water to see how it looks --- assets | 2 +- src/GameWorld.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/assets b/assets index 74035fa..e7ff07b 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 74035fae2626e2e62f803cd7d9817d1e47353f69 +Subproject commit e7ff07be10092507ff1aff17a3041d4c00aa46e1 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 27fa9fd..c752f4e 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -98,6 +98,41 @@ void GameWorld::Initialize() // CommitEntity(ground); //} + { + auto water = CreateEntity(); + auto transform = AddComponent(water); + transform->Position = glm::vec3(0, -35, 0); + transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); + transform->Scale = glm::vec3(5000.f, 10.f, 5000.f); + auto model = AddComponent(water); + model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; + auto blendmap = AddComponent(water); + blendmap->TextureRed = "Textures/Ground/WaterPlain0017_6_S.jpg"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureGreen = "Textures/Ground/WaterPlain0017_6_S.jpg"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureBlue = "Textures/Ground/WaterPlain0017_6_S.png"; + blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; + blendmap->TextureRepeats = 400.f; + + auto physics = AddComponent(water); + physics->Mass = 10; + physics->Static = true; + physics->CollisionLayer = 1; + { + + auto groundshape = CreateEntity(water); + auto box = AddComponent(groundshape); + box->Depth = 250.f; + box->Height = 5.f; + box->Width = 250.f; + + + CommitEntity(groundshape); + } + CommitEntity(water); + } + { auto ground_middle = CreateEntity(); auto transform = AddComponent(ground_middle); @@ -107,9 +142,9 @@ void GameWorld::Initialize() model->ModelFile = "Models/TerrainFiveIstles/Middle.obj"; auto blendmap = AddComponent(ground_middle); blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg"; - blendmap->TextureBlueNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; + blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg"; - blendmap->TextureBlueNormal = "Textures/Ground/Grass0126_2_SNM.png"; + blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; blendmap->TextureBlue = "Textures/Ground/Cliffs2.png"; blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; blendmap->TextureRepeats = 30.f; From a459a1c69b7099f82b30d5a710fe345a7fe0feba Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 02:03:50 +0200 Subject: [PATCH 14/21] Skybox bugfix --- src/Renderer.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Renderer.cpp b/src/Renderer.cpp index e6aa0ad..f9dbe01 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -392,6 +392,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); + DrawSkybox(); DrawFBOScene(rq.Deferred); /* @@ -593,12 +594,16 @@ void Renderer::Swap() void Renderer::DrawSkybox() { //glBindFramebuffer(GL_FRAMEBUFFER, 0); - //glViewport(0, 0, m_Width, m_Height); - //glScissor(0, 0, m_Width, m_Height); + glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); + glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_ShaderProgramSkybox.Bind(); - glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * glm::toMat4(glm::inverse(m_Camera->Orientation())); + + //glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); + //glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); + + glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height) * glm::inverse(glm::toMat4(m_Camera->Orientation())); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix)); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); m_Skybox->Draw(); From ad075f185ee77f7182e0a1cf5204094170b38477 Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 17:12:31 +0200 Subject: [PATCH 15/21] untracked files on deffered_rendering: a459a1c Skybox bugfix --- src/Systems/WheelPairSystem.cpp | 33 +++++++++++++++++++++++++++++++++ src/Systems/WheelPairSystem.h | 22 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/Systems/WheelPairSystem.cpp create mode 100644 src/Systems/WheelPairSystem.h diff --git a/src/Systems/WheelPairSystem.cpp b/src/Systems/WheelPairSystem.cpp new file mode 100644 index 0000000..b8b6c4a --- /dev/null +++ b/src/Systems/WheelPairSystem.cpp @@ -0,0 +1,33 @@ +#include "PrecompiledHeader.h" +#include "WheelPairSystem.h" +#include "World.h" + +void Systems::WheelPairSystem::RegisterComponents(ComponentFactory* cf) +{ + cf->Register([]() { return new Components::WheelPair(); }); +} + +void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) +{ + auto wheelPair = m_World->GetComponent(entity); + if (!wheelPair) + return; + + auto transform = m_World->GetComponent(entity); + if (!transform) + return; + auto transformFakeFront = m_World->GetComponent(wheelPair->FakeWheelFront); + if (!transformFakeFront) + return; + auto transformFakeBack = m_World->GetComponent(wheelPair->FakeWheelBack); + if (!transformFakeBack) + return; + + glm::vec3 thing = transformFakeBack->Position - transformFakeFront->Position; + + float height = ((transformFakeFront->Position + transformFakeBack->Position) / 2.f).y; + float angle = std::atan2f(thing.y, thing.z); + + transform->Position.y = height; + transform->Orientation = glm::quat(glm::eulerAngles(transform->Orientation) * glm::vec3(0, 1, 1) + glm::vec3(-angle, 0, 0)); +} \ No newline at end of file diff --git a/src/Systems/WheelPairSystem.h b/src/Systems/WheelPairSystem.h new file mode 100644 index 0000000..a2bd224 --- /dev/null +++ b/src/Systems/WheelPairSystem.h @@ -0,0 +1,22 @@ +#ifndef Systems_WheelPairSystem_h__ +#define Systems_WheelPairSystem_h__ + +#include "World.h" +#include "System.h" +#include "Components/Transform.h" +#include "Components/WheelPair.h" + +namespace Systems +{ + class WheelPairSystem : public System + { + public: + + WheelPairSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager) + : System(world, eventBroker, resourceManager) { } + + void RegisterComponents(ComponentFactory* cf) override; + void UpdateEntity(double dt, EntityID entity, EntityID parent) override; + }; +} +#endif // Systems_WheelPairSystem_h__ From 1b252c95e08c87e7135b33dff03bd160153aa33b Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 17:12:31 +0200 Subject: [PATCH 16/21] index on deffered_rendering: a459a1c Skybox bugfix From a31e3faa1ff9c90260cee9ca761323a1dfc063de Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sat, 31 May 2014 22:15:00 +0200 Subject: [PATCH 17/21] Linear fade added to particles --- assets | 2 +- src/Components/Particle.h | 1 + src/Components/ParticleEmitter.h | 3 +- src/GameWorld.cpp | 92 ++++++++++++-------------------- src/Systems/ParticleSystem.cpp | 64 +++++++++++++--------- src/Systems/ParticleSystem.h | 8 +-- 6 files changed, 80 insertions(+), 90 deletions(-) diff --git a/assets b/assets index 74035fa..4724dbb 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 74035fae2626e2e62f803cd7d9817d1e47353f69 +Subproject commit 4724dbbd285a35282295661821ef30548ebd550a diff --git a/src/Components/Particle.h b/src/Components/Particle.h index d720dc5..81355db 100644 --- a/src/Components/Particle.h +++ b/src/Components/Particle.h @@ -15,6 +15,7 @@ namespace Components std::vector ScaleSpectrum; double LifeTime; double SpawnTime; + bool Fade; std::vector VelocitySpectrum; std::vector AngularVelocitySpectrum; std::vector OrientationSpectrum; //Keep? diff --git a/src/Components/ParticleEmitter.h b/src/Components/ParticleEmitter.h index 03eaf05..01ed05c 100755 --- a/src/Components/ParticleEmitter.h +++ b/src/Components/ParticleEmitter.h @@ -30,9 +30,10 @@ struct ParticleEmitter : Component float SpreadAngle; double LifeTime; bool UseGoalVelocity; + bool Fade; glm::vec3 GoalVelocity; std::vector AngularVelocitySpectrum; - std::vector OrientationSpectrum; //Keep? + std::vector OrientationSpectrum; //Keep? noo.. private: double TimeSinceLastSpawn; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index ef15a7f..60473be 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -252,14 +252,14 @@ void GameWorld::Initialize() CommitEntity(tree);*/ - auto thing = CreateEntity(); - auto transform = AddComponent(thing); - transform->Position = glm::vec3(0,15,0); - transform->Scale = glm::vec3(3); -// auto model = AddComponent(thing); -// model->ModelFile = "Models/Barrel/Barrel.obj"; - auto sprite = AddComponent(thing); - sprite->SpriteFile = "Textures/Sprites/SeriousParticle.png"; +// auto thing = CreateEntity(); +// auto transform = AddComponent(thing); +// transform->Position = glm::vec3(0,15,0); +// transform->Scale = glm::vec3(3); +// // auto model = AddComponent(thing); +// // model->ModelFile = "Models/Barrel/Barrel.obj"; +// auto sprite = AddComponent(thing); +// sprite->SpriteFile = "Textures/Sprites/SeriousParticle.png"; } EntityID tank1 = CreateTank(1); @@ -745,31 +745,31 @@ EntityID GameWorld::CreateTank(int playerID) } CommitEntity(wheel); - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - { - auto particleEntity = CreateEntity(entity); - auto templateComponent = AddComponent(particleEntity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - CommitEntity(particleEntity); - emitterComponent->ParticleTemplate = particleEntity; - } +// auto entity = CreateEntity(tank); +// auto transformComponent = AddComponent(entity); +// transformComponent->Position = glm::vec3(2, -1.7, 2.0); +// transformComponent->Scale = glm::vec3(3, 3, 3); +// transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); +// auto emitterComponent = AddComponent(entity); +// emitterComponent->SpawnCount = 2; +// emitterComponent->SpawnFrequency = 0.005; +// emitterComponent->SpreadAngle = glm::pi(); +// emitterComponent->UseGoalVelocity = false; +// emitterComponent->LifeTime = 0.5; +// //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); +// emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); +// CommitEntity(entity); +// +// { +// auto particleEntity = CreateEntity(entity); +// auto templateComponent = AddComponent(particleEntity); +// auto TEMP = AddComponent(particleEntity); +// TEMP->Scale = glm::vec3(0); +// auto spriteComponent = AddComponent(particleEntity); +// spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; +// CommitEntity(particleEntity); +// emitterComponent->ParticleTemplate = particleEntity; +// } } { @@ -832,31 +832,7 @@ EntityID GameWorld::CreateTank(int playerID) CommitEntity(wheel); #pragma endregion - auto entity = CreateEntity(tank); - auto transformComponent = AddComponent(entity); - transformComponent->Position = glm::vec3(-2, -1.7, 2.0); - transformComponent->Scale = glm::vec3(3, 3, 3); - transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); - auto emitterComponent = AddComponent(entity); - emitterComponent->SpawnCount = 2; - emitterComponent->SpawnFrequency = 0.005; - emitterComponent->SpreadAngle = glm::pi(); - emitterComponent->UseGoalVelocity = false; - emitterComponent->LifeTime = 0.5; - //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100); - emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05)); - CommitEntity(entity); - - { - auto particleEntity = CreateEntity(entity); - auto templateComponent = AddComponent(particleEntity); - auto TEMP = AddComponent(particleEntity); - TEMP->Scale = glm::vec3(0); - auto spriteComponent = AddComponent(particleEntity); - spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png"; - CommitEntity(particleEntity); - emitterComponent->ParticleTemplate = particleEntity; - } + } CommitEntity(tank); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index a02ea78..df47cf6 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -22,12 +22,14 @@ void Systems::ParticleSystem::Update(double dt) double timeLived = glfwGetTime() - spawnTime; auto eComp = m_World->GetComponent(explosionID); - if(timeLived > eComp->LifeTime) + if(timeLived > eComp->LifeTime && m_ParticlesToEmitter[explosionID] == NULL) { + auto e = m_World->GetComponent(explosionID); + m_World->RemoveEntity(e->ParticleTemplate); m_World->RemoveEntity(explosionID); it = m_ExplosionEmitters.erase(it); //LOG_INFO("Deleted explosion emitter successfully"); - LOG_INFO("Deleted explosion emitter successfully"); + //LOG_INFO("Deleted explosion emitter successfully. nr of emitters%i", m_ExplosionEmitters.size()); } else { @@ -47,26 +49,34 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID { emitterComponent->TimeSinceLastSpawn += dt; auto emitterTransformComponent = m_World->GetComponent(entity); - if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency) - { - SpawnParticles(entity); - emitterComponent->TimeSinceLastSpawn = 0; - } +// if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency) +// { +// SpawnParticles(entity); +// emitterComponent->TimeSinceLastSpawn = 0; +// } } auto particleComponent = m_World->GetComponent(entity); if(particleComponent) { - EntityID particleID = entity; - auto transformComponent = m_World->GetComponent(particleID); + + EntityID particleID = entity; double timeLived = glfwGetTime() - particleComponent->SpawnTime; + if(timeLived > particleComponent->LifeTime) { m_World->RemoveEntity(particleID); + m_ParticlesToEmitter.erase(particleID); + + LOG_INFO("Removed a particle: %i", particleID); + return; } else { + auto transformComponent = m_World->GetComponent(particleID); + auto eComponent = m_World->GetComponent(m_ParticlesToEmitter[particleID]); + auto sprite = m_World->GetComponent(entity); // FIX: calculate once float timeProgress = timeLived / particleComponent->LifeTime; // ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color); @@ -76,8 +86,16 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID // Velocity interpolation if(particleComponent->VelocitySpectrum.size() > 1) VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity); - - + + if(particleComponent->Fade == true) + { + std::vector spectrum; + spectrum.push_back(1); + spectrum.push_back(0); + float alpha; + ScalarInterpolation(timeProgress, spectrum, alpha); + sprite->Color.w = alpha; + } /*// Angular velocity interpolation if (particleComponent->AngularVelocitySpectrum.size() != 0) { @@ -123,11 +141,11 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) glm::vec3 ePosition = m_TransformSystem->AbsolutePosition(emitterID); glm::quat eOrientation = eTransform->Orientation; glm::vec3 paticleSpeed = glm::vec3(eComponent->Speed); - for(int i = 0; i < eComponent->SpawnCount; i++) { auto ent = m_World->CloneEntity(eComponent->ParticleTemplate); - + LOG_INFO("Spawned a particle: %i", ent); + m_ParticlesToEmitter.insert(std::make_pair(ent, emitterID)); auto particleTransform = m_World->GetComponent(ent); particleTransform->Position = ePosition; @@ -143,6 +161,7 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) particle->LifeTime = eComponent->LifeTime; particle->ScaleSpectrum = eComponent->ScaleSpectrum; particle->VelocitySpectrum.push_back(particleTransform->Velocity); + particle->Fade = eComponent->Fade; if (eComponent->ScaleSpectrum.size() > 0) { @@ -194,23 +213,13 @@ void Systems::ParticleSystem::VectorInterpolation(double timeProgress, std::vect dAxisValue = glm::abs(spectrum[0].y - spectrum[1].y); if (spectrum[0].y > spectrum[1].y) dAxisValue *= -1; - v.y = spectrum[0].y + dAxisValue * timeProgress; + v.y = spectrum[0].y + dAxisValue * timeProgress; dAxisValue = glm::abs(spectrum[0].z - spectrum[1].z); if(spectrum[0].z > spectrum[1].z) dAxisValue *= -1; v.z = spectrum[0].z + dAxisValue * timeProgress; } -// void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector spectrum, Color &c) -// { -// float dColor = glm::abs(spectrum[0].r - spectrum[1].r); -// c.r = spectrum[0].r + dColor * timeProgress; -// dColor = glm::abs(spectrum[0].g - spectrum[1].g); -// c.g = spectrum[0].g + dColor * timeProgress; -// dColor = glm::abs(spectrum[0].b - spectrum[1].b); -// c.b = spectrum[0].b + dColor * timeProgress; -// } - void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vector spectrum, float &alpha) { float dAlpha = glm::abs(spectrum[0] - spectrum[1]); @@ -221,20 +230,22 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) { + LOG_INFO("Spawning an explosion"); auto explosion = m_World->CreateEntity(); auto emitter = m_World->AddComponent(explosion); emitter->LifeTime = e.LifeTime; emitter->SpawnCount = e.ParticlesToSpawn; emitter->Speed = e.Speed; emitter->SpreadAngle = e.SpreadAngle; + emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale)); emitter->SpawnFrequency = e.LifeTime + 20; //temp - // emitter->UseGoalVelocity = true; + emitter->Fade = true; // emitter->GoalVelocity = glm::vec3(0,-_speed, 0); m_World->CommitEntity(explosion); auto particleEnt = m_World->CreateEntity(); + auto templateComponent = m_World->AddComponent(particleEnt); auto TEMP = m_World->AddComponent(particleEnt); - TEMP->Scale = glm::vec3(0); auto spriteComponent = m_World->AddComponent(particleEnt); spriteComponent->SpriteFile = e.spritePath; m_World->CommitEntity(particleEnt); @@ -244,6 +255,7 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) transform->Position = e.Position; transform->Orientation = e.RelativeUpOrientation; + LOG_INFO("Now we should spawn 1 particle!!!!!! not 2 :("); SpawnParticles(explosion); m_ExplosionEmitters[explosion] = glfwGetTime(); diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index c7a59f2..f70cc9d 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -37,12 +37,10 @@ private: float RandomizeAngle(float spreadAngle); //void ScaleInterpolation(double timeProgress, std::vector spectrum, glm::vec3 &scale); void VectorInterpolation(double timeProgress, std::vector spectrum, glm::vec3 &velocity); - //void ColorInterpolation(double timeProgress, std::vector spectrum, Color &color); void ScalarInterpolation(double timeProgress, std::vector spectrum, float &alpha); void Billboard(); //std::map> m_ParticleEmitter; - std::map m_TimeSinceLastSpawn; - std::map m_ExplosionEmitters; + std::shared_ptr m_TransformSystem; bool tempSpawnedExplosions; @@ -51,7 +49,9 @@ private: // bool OnKeyUp(const Events::KeyUp &e); EventRelay m_EExplosion; bool CreateExplosion(const Events::CreateExplosion &e); - + + std::map m_ExplosionEmitters; + std::map m_ParticlesToEmitter; }; } From d40750243284633e62b9a116cda975cf8dde9fc3 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sat, 31 May 2014 22:15:44 +0200 Subject: [PATCH 18/21] CreateExplosion event published on shell collision now. --- src/InputManager.cpp | 13 ------------- src/InputManager.h | 1 - src/Systems/TankSteeringSystem.cpp | 23 +++++++++++++++++++++++ src/Systems/TankSteeringSystem.h | 1 + 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/InputManager.cpp b/src/InputManager.cpp index 5e6c942..01d61ba 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -85,19 +85,6 @@ void InputManager::Update(double dt) EventBroker->Publish(e); } - if(m_CurrentKeyState[GLFW_KEY_Z]) - { - Events::CreateExplosion e; - e.LifeTime = 1; - e.ParticleScale = 6; - e.ParticlesToSpawn = 1; - e.Position = glm::vec3(0, -15, 0); - e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); - e.Speed = 3; - e.SpreadAngle = glm::pi(); - e.spritePath = "Textures/Sprites/SeriousParticle.png"; - EventBroker->Publish(e); - } // // Lock mouse while holding LMB // if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) diff --git a/src/InputManager.h b/src/InputManager.h index 94d178d..69827ba 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -12,7 +12,6 @@ #include "Events/LockMouse.h" #include "Events/GamepadAxis.h" #include "Events/GamepadButton.h" -#include "Events/CreateExplosion.h" class InputManager { diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 5809fd9..bf72fc7 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -126,6 +126,29 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) auto physicsComponents = m_World->GetComponentsOfType(); auto shellTransform = m_World->GetComponent(shellEntity); //auto otherTransform = m_World->GetComponent(otherEntity); + + { + Events::CreateExplosion e; + e.LifeTime = 2; + e.ParticleScale = 8; + e.ParticlesToSpawn = 10; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 3; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Smoke1.png"; + EventBroker->Publish(e); + e.LifeTime = 1; + e.ParticleScale = 12; + e.ParticlesToSpawn = 10; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 6; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Fire.png"; + EventBroker->Publish(e); + } + for (auto &physComponent : *physicsComponents) { EntityID physicsEntity = std::dynamic_pointer_cast(physComponent)->Entity; diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 9a9c696..f3115a6 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -5,6 +5,7 @@ #include "Events/SetVelocity.h" #include "Events/ApplyForce.h" #include "Events/ApplyPointImpulse.h" +#include "Events/CreateExplosion.h" #include "Events/Collision.h" #include "Components/Transform.h" #include "Components/TankSteering.h" From cea2faaaf86a58a6cea8f54621cc046a5bd58358 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sat, 31 May 2014 23:14:13 +0200 Subject: [PATCH 19/21] Removed unnecessary info messages --- src/Systems/ParticleSystem.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index df47cf6..9b4f682 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -69,7 +69,6 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID m_World->RemoveEntity(particleID); m_ParticlesToEmitter.erase(particleID); - LOG_INFO("Removed a particle: %i", particleID); return; } else @@ -144,7 +143,6 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) for(int i = 0; i < eComponent->SpawnCount; i++) { auto ent = m_World->CloneEntity(eComponent->ParticleTemplate); - LOG_INFO("Spawned a particle: %i", ent); m_ParticlesToEmitter.insert(std::make_pair(ent, emitterID)); auto particleTransform = m_World->GetComponent(ent); particleTransform->Position = ePosition; @@ -255,7 +253,6 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) transform->Position = e.Position; transform->Orientation = e.RelativeUpOrientation; - LOG_INFO("Now we should spawn 1 particle!!!!!! not 2 :("); SpawnParticles(explosion); m_ExplosionEmitters[explosion] = glfwGetTime(); From 2d1d4f02f30938df35b41e9423f9006b129072af Mon Sep 17 00:00:00 2001 From: Tleety Date: Sat, 31 May 2014 23:14:33 +0200 Subject: [PATCH 20/21] Fixed some things in gameworld and added a new skymap. --- src/GameWorld.cpp | 77 +++++++++++++++++++----------- src/GameWorld.h | 1 - src/RenderQueue.h | 18 +++---- src/Renderer.cpp | 19 ++++++-- src/Renderer.h | 3 +- src/Systems/TankSteeringSystem.cpp | 2 +- 6 files changed, 76 insertions(+), 44 deletions(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index e3d86ea..09e535c 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -70,26 +70,26 @@ void GameWorld::Initialize() EventBroker->Publish(e); } - { - auto road_base = CreateEntity(); - auto transform = AddComponent(road_base); - transform->Position = glm::vec3(0, -50, 0); - auto model = AddComponent(road_base); - model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; - auto physics = AddComponent(road_base); - physics->Mass = 10; - physics->Static = true; - physics->CollisionLayer = 1; - - auto groundshape = CreateEntity(road_base); - auto transformshape = AddComponent(groundshape); - auto meshShape = AddComponent(groundshape); - meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; - - - CommitEntity(groundshape); - CommitEntity(road_base); - } + { + auto road_base = CreateEntity(); + auto transform = AddComponent(road_base); + transform->Position = glm::vec3(0, -50, 0); + auto model = AddComponent(road_base); + model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; + auto physics = AddComponent(road_base); + physics->Mass = 10; + physics->Static = true; + physics->CollisionLayer = 1; + + auto groundshape = CreateEntity(road_base); + auto transformshape = AddComponent(groundshape); + auto meshShape = AddComponent(groundshape); + meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/BaseRoad.obj"; + + + CommitEntity(groundshape); + CommitEntity(road_base); + } { auto road_middle = CreateEntity(); @@ -143,13 +143,10 @@ void GameWorld::Initialize() auto model = AddComponent(water); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; auto blendmap = AddComponent(water); - blendmap->TextureRed = "Textures/Ground/WaterPlain0017_6_S.png"; - blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png"; - blendmap->TextureGreen = "Textures/Ground/WaterPlain0017_6_S.jpg"; - blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png"; - blendmap->TextureBlue = "Textures/Ground/WaterPlain0017_6_S.png"; - blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png"; - blendmap->TextureRepeats = 400.f; + blendmap->TextureRed = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureGreen = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureBlue = "Textures/Skybox/Sky34/bottom.jpg"; + blendmap->TextureRepeats = 1.f; auto physics = AddComponent(water); physics->Mass = 10; @@ -327,11 +324,33 @@ void GameWorld::Initialize() { auto tree = CreateEntity(); auto transform = AddComponent(tree); - transform->Position = glm::vec3(0, -15, 0); + transform->Position = glm::vec3(0, -10, 0); auto model = AddComponent(tree); - model->ModelFile = "Models/Tree/leafs/Leafs.obj"; + model->ModelFile = "Models/Tree/Stem/Stem.obj"; + auto physics = AddComponent(tree); + physics->Mass = 100.f; + physics->Static = false; + physics->CalculateCenterOfMass = true; + { + auto leafs = CreateEntity(tree); + auto transform = AddComponent(leafs); + auto model = AddComponent(leafs); + model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; model->Transparent = true; + CommitEntity(leafs); + } + { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto box = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0.f, 2.29552f); + box->Width = 0.296f; + box->Height = 2.511f; + box->Depth = 0.296f; + + CommitEntity(shape); + } CommitEntity(tree); } diff --git a/src/GameWorld.h b/src/GameWorld.h index 3837c77..aae2472 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -34,7 +34,6 @@ #include "Components/Template.h" #include "Components/Transform.h" #include "Components/Viewport.h" -#include "Components/BlendMap.h" #include "Components/Physics.h" #include "Components/SphereShape.h" diff --git a/src/RenderQueue.h b/src/RenderQueue.h index 932dd69..2636f84 100644 --- a/src/RenderQueue.h +++ b/src/RenderQueue.h @@ -14,6 +14,9 @@ struct RenderJob { friend class RenderQueue; + glm::mat4 ModelMatrix; + float Depth; + protected: uint64_t Hash; @@ -37,7 +40,6 @@ struct ModelJob : RenderJob GLuint VAO; unsigned int StartIndex; unsigned int EndIndex; - glm::mat4 ModelMatrix; float Transparent; void CalculateHash() override @@ -67,7 +69,6 @@ struct SpriteJob : RenderJob GLuint Texture; glm::vec4 Color; - glm::mat4 ModelMatrix; void CalculateHash() override { @@ -82,31 +83,30 @@ public: void Add(T &job) { job.CalculateHash(); - m_Jobs.push_front(std::shared_ptr(new T(job))); + Jobs.push_front(std::shared_ptr(new T(job))); } void Sort() { - m_Jobs.sort(); + Jobs.sort(); } void Clear() { - m_Jobs.clear(); + Jobs.clear(); } std::forward_list>::const_iterator begin() { - return m_Jobs.begin(); + return Jobs.begin(); } std::forward_list>::const_iterator end() { - return m_Jobs.end(); + return Jobs.end(); } -private: - std::forward_list> m_Jobs; + std::forward_list> Jobs; }; struct RenderQueuePair diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 62626b7..142f7ec 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -18,7 +18,7 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager) CAtt = 1.0f; LAtt = 0.0f; QAtt = 3.0f; - m_ShadowMapRes = 2048*2; + m_ShadowMapRes = 1; m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f); m_SunTarget = glm::vec3(0, 0, 0); m_SunProjection_height = glm::vec2(-40.f, 40.f); @@ -163,7 +163,7 @@ void Renderer::LoadContent() FrameBufferTextures(); m_sphereModel = ResourceManager->Load("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"); - m_Skybox = std::make_shared("Textures/Skybox/Sky34", "jpg"); + m_Skybox = std::make_shared("Textures/Skybox/sky36", "jpg"); } void Renderer::Draw(double dt) @@ -369,6 +369,17 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glDepthMask(GL_TRUE); glEnable(GL_SCISSOR_TEST); + //Sort forward rendering items by z value. + for(auto job : rq.Forward) + { + glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); + glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); + + glm::vec3 spritePos = glm::vec3(cameraMatrix * job->ModelMatrix * glm::vec4(1, 1, 1, 0)); + job->Depth = spritePos.z; + } + rq.Forward.Jobs.sort(Renderer::DepthSort); + //DrawShadowMap(rq.Deferred); /* @@ -392,7 +403,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq) glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); - //DrawSkybox(); + DrawSkybox(); DrawFBOScene(rq.Deferred); /* @@ -512,6 +523,8 @@ void Renderer::ForwardRendering(RenderQueue &rq) continue; } + + auto spriteJob = std::dynamic_pointer_cast(job); if (spriteJob) { diff --git a/src/Renderer.h b/src/Renderer.h index 445601f..dacc6db 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -201,7 +201,8 @@ private: void CreateNormalMapTangent(); void ForwardRendering(RenderQueue &rq); - + static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } + GLuint CreateQuad(); void DrawDebugShadowMap(); GLuint CreateAABB(); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index cc1008b..af7e41b 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -88,7 +88,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit Events::ApplyPointImpulse ePointImpulse ; ePointImpulse.Entity = entity; ePointImpulse.Position = absoluteTransform.Position; - ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f; + ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f; EventBroker->Publish(ePointImpulse); } From 756107363e83e2a47587c009a762edae71f8ef92 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sun, 1 Jun 2014 01:15:53 +0200 Subject: [PATCH 21/21] Some pretty darn cool explosions --- assets | 2 +- src/Components/Particle.h | 1 - src/Components/ParticleEmitter.h | 5 +++-- src/Events/CreateExplosion.h | 5 ++++- src/Renderer.cpp | 2 +- src/Renderer.h | 2 +- src/Systems/ParticleSystem.cpp | 15 ++++++++++++++- src/Systems/TankSteeringSystem.cpp | 24 ++++++++++++++++++------ 8 files changed, 42 insertions(+), 14 deletions(-) diff --git a/assets b/assets index 4724dbb..bd74626 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 4724dbbd285a35282295661821ef30548ebd550a +Subproject commit bd746269ffaf3abc61c0c8ed5d116b317a4cdd68 diff --git a/src/Components/Particle.h b/src/Components/Particle.h index 81355db..065ab62 100644 --- a/src/Components/Particle.h +++ b/src/Components/Particle.h @@ -11,7 +11,6 @@ namespace Components struct Particle : Component { - std::vector ColorSpectrum; std::vector ScaleSpectrum; double LifeTime; double SpawnTime; diff --git a/src/Components/ParticleEmitter.h b/src/Components/ParticleEmitter.h index 01ed05c..f7cb678 100755 --- a/src/Components/ParticleEmitter.h +++ b/src/Components/ParticleEmitter.h @@ -19,13 +19,14 @@ struct ParticleEmitter : Component , SpawnCount(0) , SpreadAngle(0) , LifeTime(0) - , TimeSinceLastSpawn(100) { } // TEMP fulhack så att partiklarna spawnar direkt + , TimeSinceLastSpawn(100) + , Color(glm::vec4(0)) { } EntityID ParticleTemplate; float SpawnFrequency; float Speed; int SpawnCount; - std::vector ColorSpectrum; + glm::vec4 Color; std::vector ScaleSpectrum; float SpreadAngle; double LifeTime; diff --git a/src/Events/CreateExplosion.h b/src/Events/CreateExplosion.h index 76f2312..0fb6310 100644 --- a/src/Events/CreateExplosion.h +++ b/src/Events/CreateExplosion.h @@ -9,14 +9,17 @@ namespace Events { struct CreateExplosion : Event { + CreateExplosion() + : Color(glm::vec4(0)) {} glm::vec3 Position; + glm::vec4 Color; double LifeTime; int ParticlesToSpawn; std::string spritePath; glm::quat RelativeUpOrientation; float Speed; float SpreadAngle; - float ParticleScale; + std::vector ParticleScale; }; } diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 142f7ec..64c74e5 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -163,7 +163,7 @@ void Renderer::LoadContent() FrameBufferTextures(); m_sphereModel = ResourceManager->Load("Model", "Models/Placeholders/PhysicsTest/Sphere.obj"); - m_Skybox = std::make_shared("Textures/Skybox/sky36", "jpg"); + m_Skybox = std::make_shared("Textures/Skybox/sunset", "jpg"); } void Renderer::Draw(double dt) diff --git a/src/Renderer.h b/src/Renderer.h index dacc6db..432e21d 100755 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -201,7 +201,7 @@ private: void CreateNormalMapTangent(); void ForwardRendering(RenderQueue &rq); - static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth < j->Depth); } + static bool DepthSort(const std::shared_ptr &i, const std::shared_ptr &j) { return (i->Depth > j->Depth); } GLuint CreateQuad(); void DrawDebugShadowMap(); diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 9b4f682..45c3646 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -95,6 +95,9 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID ScalarInterpolation(timeProgress, spectrum, alpha); sprite->Color.w = alpha; } + + + /*// Angular velocity interpolation if (particleComponent->AngularVelocitySpectrum.size() != 0) { @@ -161,6 +164,10 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID) particle->VelocitySpectrum.push_back(particleTransform->Velocity); particle->Fade = eComponent->Fade; + auto sprite = m_World->GetComponent(ent); + if(eComponent->Color != glm::vec4(0)) + sprite->Color = eComponent->Color; + if (eComponent->ScaleSpectrum.size() > 0) { if (eComponent->ScaleSpectrum.size() > 1) @@ -235,9 +242,15 @@ bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e) emitter->SpawnCount = e.ParticlesToSpawn; emitter->Speed = e.Speed; emitter->SpreadAngle = e.SpreadAngle; - emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale)); + //emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale)); emitter->SpawnFrequency = e.LifeTime + 20; //temp emitter->Fade = true; + emitter->Color = e.Color; + std::vector scale; + scale.push_back(glm::vec3(e.ParticleScale[0])); + if(e.ParticleScale.size() >= 2) + scale.push_back(glm::vec3(e.ParticleScale[1])); + emitter->ScaleSpectrum = scale; // emitter->GoalVelocity = glm::vec3(0,-_speed, 0); m_World->CommitEntity(explosion); diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index 94f4f25..55ad7c5 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -130,23 +130,35 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) { Events::CreateExplosion e; - e.LifeTime = 2; - e.ParticleScale = 8; - e.ParticlesToSpawn = 10; + e.LifeTime = 3; + e.ParticleScale.push_back(8); + e.ParticlesToSpawn = 20; e.Position = shellTransform->Position; e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); e.Speed = 3; e.SpreadAngle = glm::pi(); e.spritePath = "Textures/Sprites/Smoke1.png"; + e.Color = glm::vec4(0.6,0.6,0.6,1); EventBroker->Publish(e); - e.LifeTime = 1; - e.ParticleScale = 12; + e.LifeTime = 0.7; + e.ParticleScale.push_back(12); e.ParticlesToSpawn = 10; e.Position = shellTransform->Position; e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); + e.Speed = 17; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Fire.png"; + EventBroker->Publish(e); + e.LifeTime = 0.2; + e.ParticleScale.push_back(1); + e.ParticleScale.push_back(15); + e.ParticlesToSpawn = 5; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); e.Speed = 6; e.SpreadAngle = glm::pi(); - e.spritePath = "Textures/Sprites/Fire.png"; + e.spritePath = "Textures/Sprites/Blast1.png"; + e.Color = glm::vec4(2, 2, 2, 0.2); EventBroker->Publish(e); }