diff --git a/src/Components/ParticleEmitter.h b/src/Components/ParticleEmitter.h index 06a1658..48248a8 100755 --- a/src/Components/ParticleEmitter.h +++ b/src/Components/ParticleEmitter.h @@ -1,7 +1,10 @@ #ifndef Components_ParticleEmitter_h__ #define Components_ParticleEmitter_h__ +#include "System.h" #include "Component.h" +#include "Components/Transform.h" +#include "Components/ParticleEmitter.h" #include "Color.h" #include diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 371dd2e..5d471b8 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -40,11 +40,38 @@ void GameWorld::Initialize() physics->Mass = 10; } - for(int i = 0; i < 10; i++) + { + auto TankTest = CreateEntity(); + auto transform = AddComponent(TankTest, "Transform"); + transform->Position = glm::vec3(1.5f, 0.7f, 5.f); + + auto model = AddComponent(TankTest, "Model"); + model->ModelFile = "Models/Placeholders/tank/Chassi.obj"; + } + + for(int i = 0; i < 83; i++) + { + auto light = CreateEntity(); + auto transform = AddComponent(light, "Transform"); + transform->Position = glm::vec3((float)(2*i)*glm::sin((float)i), 3, (float)(2*i)*glm::cos((float)i)); + + auto pointLight = AddComponent(light, "PointLight"); + pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f); + pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f); + pointLight->constantAttenuation = 0.03f; + pointLight->linearAttenuation = 0.009f; + pointLight->quadraticAttenuation = 0.07f; + pointLight->spotExponent = 0.0f; + + auto model = AddComponent(light, "Model"); + model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; + } + + for(int i = 0; i < 500; i++) { auto ball = CreateEntity(); auto transform = AddComponent(ball, "Transform"); - transform->Position = glm::vec3(0, 5 + i*2, 0); + transform->Position = glm::vec3(i/5.f, 5 + i*2, i/5.f); transform->Scale = glm::vec3(1.0f, 1.0f, 1.0f); transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f)); auto model = AddComponent(ball, "Model"); @@ -84,7 +111,7 @@ void GameWorld::RegisterSystems() //m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); }); m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); }); //m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); }); - ////m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); + m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); }); //m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); }); m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this); }); m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); }); @@ -98,7 +125,7 @@ void GameWorld::AddSystems() //AddSystem("LevelGenerationSystem"); AddSystem("InputSystem"); //AddSystem("CollisionSystem"); - //AddSystem("ParticleSystem"); + AddSystem("ParticleSystem"); //AddSystem("PlayerSystem"); AddSystem("FreeSteeringSystem"); AddSystem("SoundSystem"); diff --git a/src/GameWorld.h b/src/GameWorld.h index 05ca584..264ec4d 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -8,7 +8,7 @@ //#include "Systems/CollisionSystem.h" #include "Systems/InputSystem.h" //#include "Systems/LevelGenerationSystem.h" -//#include "Systems/ParticleSystem.h" +#include "Systems/ParticleSystem.h" //#include "Systems/PlayerSystem.h" #include "Systems/FreeSteeringSystem.h" #include "Systems/RenderSystem.h" diff --git a/src/Shaders/geometry_pass.frag.glsl b/src/Shaders/geometry_pass.frag.glsl new file mode 100644 index 0000000..4fe34ba --- /dev/null +++ b/src/Shaders/geometry_pass.frag.glsl @@ -0,0 +1,20 @@ +#version 430 + +in vec2 TexCoord0; +in vec3 Normal0; +in vec3 WorldPos0; + +layout (location = 0) out vec3 WorldPosOut; +layout (location = 1) out vec3 DiffuseOut; +layout (location = 2) out vec3 NormalOut; +layout (location = 3) out vec3 TexCoordOut; + +uniform sampler2D gColorMap; + +void main() +{ + WorldPosOut = WorldPos0; + DiffuseOut = texture(gColorMap, TexCoord0).xyz; + NormalOut = normalize(Normal0); + TexCoordOut = vec3(TexCoord0, 0.0); +} \ No newline at end of file diff --git a/src/Shaders/geometry_pass.vert.glsl b/src/Shaders/geometry_pass.vert.glsl new file mode 100644 index 0000000..c431ba9 --- /dev/null +++ b/src/Shaders/geometry_pass.vert.glsl @@ -0,0 +1,20 @@ +#version 430 + +layout (location = 0) in vec3 Position; +layout (location = 1) in vec2 TexCoord; +layout (location = 2) in vec3 Normal; + +uniform mat4 gWVP; +uniform mat4 gWorld; + +out vec2 TexCoord0; +out vec3 Normal0; +out vec3 WorldPos0; + +void main() +{ + gl_Position = gWVP * vec4(Position, 1.0); + TexCoord0 = TexCoord; + Normal0 = (gWorld * vec4(Normal, 0.0)).xyz; + WorldPos0 = (gWorld * vec4(Position, 1.0)).xyz; +} \ No newline at end of file diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index 3df99a0..bc23511 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -1,5 +1,6 @@ -#include "ParticleSystem.h" #include "PrecompiledHeader.h" +#include "ParticleSystem.h" + #include "World.h" void Systems::ParticleSystem::Update(double dt) @@ -13,13 +14,10 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID if(!transformComponent) return; - transformComponent->Position.y --; - - timeLived[entity] += dt; + + auto emitterComponent = m_World->GetComponent(entity, "ParticleEmitter"); - - } @@ -35,7 +33,6 @@ void Systems::ParticleSystem::SpawnParticles() auto particle = m_World->CreateEntity(); auto transform = m_World->AddComponent(particle, "Transform"); transform->Position = glm::vec3(0); - particles.push_back(particle); } } diff --git a/src/Systems/ParticleSystem.h b/src/Systems/ParticleSystem.h index 4211d89..35dfee1 100644 --- a/src/Systems/ParticleSystem.h +++ b/src/Systems/ParticleSystem.h @@ -13,16 +13,15 @@ namespace Systems class ParticleSystem : public System { public: - ParticleSystem(World* world); + ParticleSystem(World* world) + :System(world) { }; void RegisterComponents(ComponentFactory* cf) override; void Update(double dt) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; - + void Draw(double dt); private: void SpawnParticles(); - - }; diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 98ee002..6ec3b45 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -41,7 +41,7 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world) worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far // You must specify the size of the broad phase - objects should not be simulated outside this region - worldInfo.setBroadPhaseWorldSize(1000.0f); + worldInfo.setBroadPhaseWorldSize(10000.0f); m_PhysicsWorld = new hkpWorld(worldInfo); } // Register all collision agents, even though only box - box will be used in this particular example. diff --git a/src/gBuffer.cpp b/src/gBuffer.cpp new file mode 100644 index 0000000..5acf690 --- /dev/null +++ b/src/gBuffer.cpp @@ -0,0 +1,40 @@ +#include "PrecompiledHeader.h" +#include "gBuffer.h" + +bool GBuffer::Init(unsigned int WindowWidth, unsigned int WindowHeight) +{ + // Create the FBO + glGenFramebuffers(1, &m_fbo); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo); + + // Create the gbuffer textures + glGenTextures(ARRAY_SIZE_IN_ELEMENTS(m_textures), m_textures); + glGenTextures(1, &m_depthTexture); + + for (unsigned int i = 0 ; i < ARRAY_SIZE_IN_ELEMENTS(m_textures) ; i++) { + glBindTexture(GL_TEXTURE_2D, m_textures[i]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0); + } + + // depth + glBindTexture(GL_TEXTURE_2D, m_depthTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, WindowWidth, WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, + NULL); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_depthTexture, 0); + + GLenum DrawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; + glDrawBuffers(ARRAY_SIZE_IN_ELEMENTS(DrawBuffers), DrawBuffers); + + GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + if (Status != GL_FRAMEBUFFER_COMPLETE) { + printf("FB error, status: 0x%x\n", Status); + return false; + } + + // restore default FBO + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + + return true; +} \ No newline at end of file diff --git a/src/gBuffer.h b/src/gBuffer.h new file mode 100644 index 0000000..721eb15 --- /dev/null +++ b/src/gBuffer.h @@ -0,0 +1,35 @@ +#ifndef gBuffer_h__ +#define gBuffer_h__ + +#include + +class GBuffer +{ +public: + + enum GBUFFER_TEXTURE_TYPE { + GBUFFER_TEXTURE_TYPE_POSITION, + GBUFFER_TEXTURE_TYPE_DIFFUSE, + GBUFFER_TEXTURE_TYPE_NORMAL, + GBUFFER_TEXTURE_TYPE_TEXCOORD, + GBUFFER_NUM_TEXTURES + }; + + GBuffer(); + + ~GBuffer(); + + bool Init(unsigned int WindowWidth, unsigned int WindowHeight); + + void BindForWriting(); + + void BindForReading(); + +private: + + GLuint m_fbo; + GLuint m_textures[GBUFFER_NUM_TEXTURES]; + GLuint m_depthTexture; +}; + +#endif //gBuffer_h__ \ No newline at end of file