diff --git a/Escape-the-Dawn/GameWorld.cpp b/Escape-the-Dawn/GameWorld.cpp index 43352df..8979ec8 100644 --- a/Escape-the-Dawn/GameWorld.cpp +++ b/Escape-the-Dawn/GameWorld.cpp @@ -34,12 +34,10 @@ void GameWorld::Initialize() // Fucking lights ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, 4.f, 0.f); - transform->Position = glm::vec3(10.f, 2.f, 5.f); + transform->Position = glm::vec3(0.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 5.0); + pointLight->Diffuse = glm::vec3(0.0, 0.0, 5.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; @@ -48,13 +46,10 @@ void GameWorld::Initialize() model->ModelFile = "Models/sphere.obj"; ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(10.f, 4.f, 0.f); - transform->Position = glm::vec3(0.f, 2.f, 5.f); + transform->Position = glm::vec3(10.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Specular = glm::vec3(3.0, 3.0, 3.0); - pointLight->Diffuse = glm::vec3(3.0, 0.0, 0.0); + pointLight->Diffuse = glm::vec3(0.0, 5.0, 0.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; @@ -63,12 +58,10 @@ void GameWorld::Initialize() model->ModelFile = "Models/sphere.obj"; ent = CreateEntity(); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(0.f, -4.f, 0.f); - transform->Position = glm::vec3(-10.f, 2.f, 5.f); + transform->Position = glm::vec3(-10.f, 7.f, 0.f); pointLight = AddComponent(ent, "PointLight"); pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); - pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0); + pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.f; pointLight->quadraticAttenuation = 0.f; @@ -91,6 +84,13 @@ void GameWorld::Initialize() transform->Scale = glm::vec3(1.0f); model = AddComponent(m_Player, "Model"); model->ModelFile = "Models/ship.obj"; + pointLight = AddComponent(m_Player, "PointLight"); + pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); + pointLight->Diffuse = glm::vec3(5.0, 0.0, 0.0); + pointLight->constantAttenuation = 0.f; + pointLight->linearAttenuation = 1.f; + pointLight->quadraticAttenuation = 0.f; + pointLight->spotExponent = 0.0f; AddComponent(m_Player, "Input"); auto bounds = AddComponent(m_Player, "Bounds"); bounds->Origin = glm::vec3(0.f, 0.f, 2.f); diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp index 0948515..13c2967 100644 --- a/Escape-the-Dawn/Renderer.cpp +++ b/Escape-the-Dawn/Renderer.cpp @@ -9,6 +9,7 @@ Renderer::Renderer() m_SunPosition = glm::vec3(0, 10, 10); m_SunTarget = glm::vec3(0, 0, 0); m_SunProjection = glm::ortho(-20, 20, -20, 20, -10, 20); + Lights = 512; } void Renderer::Initialize() @@ -138,12 +139,12 @@ void Renderer::Draw(double dt) glBindVertexArray(m_DebugAABB); glDrawArrays(GL_LINES, 0, 24); } - AABBsToRender.clear(); + #endif DrawDebugShadowMap(); - ModelsToRender.clear(); + ClearStuff(); glfwSwapBuffers(m_Window); } @@ -177,13 +178,13 @@ void Renderer::DrawScene() m_ShaderProgram.Bind(); glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthBiasMVP)); - glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), 3, Light_position.data()); - glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), 3, Light_specular.data()); - glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), 3, Light_diffuse.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), 3, Light_constantAttenuation.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), 3, Light_linearAttenuation.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), 3, Light_quadraticAttenuation.data()); - glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), 3, Light_spotExponent.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "position"), Lights, Light_position.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "specular"), Lights, Light_specular.data()); + glUniform3fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "diffuse"), Lights, Light_diffuse.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "constantAttenuation"), Lights, Light_constantAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "linearAttenuation"), Lights, Light_linearAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "quadraticAttenuation"), Lights, Light_quadraticAttenuation.data()); + glUniform1fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "spotExponent"), Lights, Light_spotExponent.data()); if (m_DrawWireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } @@ -315,7 +316,7 @@ void Renderer::AddPointLightToDraw( Light_linearAttenuation.push_back(_linearAttenuation); Light_quadraticAttenuation.push_back(_quadraticAttenuation); Light_spotExponent.push_back(_spotExponent); - + Lights = Light_constantAttenuation.size(); } GLuint Renderer::CreateQuad() @@ -417,3 +418,16 @@ void Renderer::AddAABBToDraw(glm::vec3 origin, glm::vec3 volumeVector) model *= glm::scale(volumeVector); AABBsToRender.push_back(model); } + +void Renderer::ClearStuff() +{ + AABBsToRender.clear(); + ModelsToRender.clear(); + Light_position.clear(); + Light_specular.clear(); + Light_diffuse.clear(); + Light_constantAttenuation.clear(); + Light_linearAttenuation.clear(); + Light_quadraticAttenuation.clear(); + Light_spotExponent.clear(); +} diff --git a/Escape-the-Dawn/Renderer.h b/Escape-the-Dawn/Renderer.h index 1f4ef77..1a8361d 100644 --- a/Escape-the-Dawn/Renderer.h +++ b/Escape-the-Dawn/Renderer.h @@ -29,6 +29,7 @@ public: glm::mat4 projectionMatrix; int HEIGHT, WIDTH; + float Lights; struct ModelData { @@ -101,7 +102,8 @@ private: ShaderProgram m_ShaderProgramShadows; ShaderProgram m_ShaderProgramShadowsDrawDepth; ShaderProgram m_ShaderProgramDebugAABB; - + + void ClearStuff(); void DrawScene(); void DrawModels(ShaderProgram &shader); void DrawShadowMap(); diff --git a/Escape-the-Dawn/Shaders/Fragment.glsl b/Escape-the-Dawn/Shaders/Fragment.glsl index a852e1b..9482278 100644 --- a/Escape-the-Dawn/Shaders/Fragment.glsl +++ b/Escape-the-Dawn/Shaders/Fragment.glsl @@ -6,7 +6,7 @@ uniform mat4 view; layout(binding=0) uniform sampler2D texture0; layout(binding=1) uniform sampler2D shadowMap; -const int numberOfLights = 3; +const int numberOfLights = 128; uniform vec3 position[numberOfLights]; uniform vec3 specular[numberOfLights]; diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index 70f9166..397752d 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -24,6 +24,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() bounds = m_World->AddComponent(ent, "Bounds"); collision = m_World->AddComponent(ent, "Collision"); model = m_World->AddComponent(ent, "Model"); + //pointLight = m_World->AddComponent(ent, "PointLight"); positionRandom = -500 + (rand() % 1000); @@ -47,6 +48,13 @@ void Systems::LevelGenerationSystem::SpawnObstacle() transform->Position = glm::vec3( positionRandom, startyz); // fix position bounds->VolumeVector = glm::vec3(1, 1, 1); bounds->Origin = glm::vec3(0,1,0); +// pointLight->Specular = glm::vec3(1.0, 1.0, 1.0); +// pointLight->Diffuse = glm::vec3(1.0, 1.0, 1.0); +// pointLight->Diffuse = glm::vec3(0.0, 3.0, 0.0); +// pointLight->constantAttenuation = 0.f; +// pointLight->linearAttenuation = 1.f; +// pointLight->quadraticAttenuation = 0.f; +// pointLight->spotExponent = 0.0f; model->ModelFile = "Models/obstacle_cube_1.obj"; break; diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.h b/Escape-the-Dawn/Systems/LevelGenerationSystem.h index 5bf91d6..e436df1 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.h +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.h @@ -7,6 +7,7 @@ #include "Components/Bounds.h" #include "Components/Collision.h" #include "Components/Model.h" +#include "Components/PointLight.h" namespace Systems @@ -34,6 +35,7 @@ namespace Systems std::shared_ptr bounds; std::shared_ptr collision; std::shared_ptr model; + std::shared_ptr pointLight; }; } diff --git a/Escape-the-Dawn/Systems/PlayerSystem.cpp b/Escape-the-Dawn/Systems/PlayerSystem.cpp index 04da475..dd715e4 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.cpp +++ b/Escape-the-Dawn/Systems/PlayerSystem.cpp @@ -3,6 +3,7 @@ Systems::PlayerSystem::PlayerSystem( World* world ) : System(world) { + speed = 20; } void Systems::PlayerSystem::Update(double dt) @@ -18,8 +19,6 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa if (input == nullptr) return; - float speed = 20.0f; - auto name = m_World->GetProperty(entity, "Name"); if (name == "Camera") { @@ -60,7 +59,6 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa // TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS } } - name = m_World->GetProperty(entity, "Name"); if (name == "PlayerShip") { diff --git a/Escape-the-Dawn/Systems/PlayerSystem.h b/Escape-the-Dawn/Systems/PlayerSystem.h index 6d995e0..4025a5a 100644 --- a/Escape-the-Dawn/Systems/PlayerSystem.h +++ b/Escape-the-Dawn/Systems/PlayerSystem.h @@ -20,7 +20,7 @@ namespace Systems void UpdateEntity(double dt, EntityID entity, EntityID parent) override; private: - + float speed; }; }