From 2d5ba34a1a37e7b6ca60e755b8d344b81733e7c9 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 14 Mar 2014 03:35:52 +0100 Subject: [PATCH] "Better" lighting and stuff --- Escape-the-Dawn/GameWorld.cpp | 22 ++++++++++--------- Escape-the-Dawn/Renderer.cpp | 12 +++++----- Escape-the-Dawn/Shaders/Fragment.glsl | 2 +- .../Systems/LevelGenerationSystem.cpp | 7 +++--- Escape-the-Dawn/World.cpp | 5 +++++ Escape-the-Dawn/World.h | 2 +- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Escape-the-Dawn/GameWorld.cpp b/Escape-the-Dawn/GameWorld.cpp index ccd6242..205148b 100644 --- a/Escape-the-Dawn/GameWorld.cpp +++ b/Escape-the-Dawn/GameWorld.cpp @@ -38,19 +38,21 @@ void GameWorld::Initialize() pointLight->quadraticAttenuation = 0.f; pointLight->spotExponent = 0.0f; model = AddComponent(ent, "Model"); - model->ModelFile = "Models/sphere.obj"; + model->ModelFile = "Models/sphere.obj";*/ ent = CreateEntity(); + SetProperty(ent, "Name", std::string("Sun")); transform = AddComponent(ent, "Transform"); - transform->Position = glm::vec3(-10.f, 7.f, 0.f); + transform->Position = glm::vec3(0.f, 100.f, 30.f); + AddComponent(ent, "Input"); pointLight = AddComponent(ent, "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->Diffuse = glm::vec3(1.0, 0.45, 0.0); + pointLight->constantAttenuation = 0.009f; + pointLight->linearAttenuation = -0.0177f; + pointLight->quadraticAttenuation = 0.00043f; pointLight->spotExponent = 0.0f; model = AddComponent(ent, "Model"); - model->ModelFile = "Models/sphere.obj";*/ + model->ModelFile = "Models/sphere.obj"; //ground ent = CreateEntity(); @@ -94,7 +96,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(1.5f, 0.25f, 2.5f); pointLight = AddComponent(playerLight, "PointLight"); pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f); - pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f); + pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 0.9f; pointLight->quadraticAttenuation = 0.f; @@ -106,7 +108,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(-1.5f, 0.25f, 2.5f); pointLight = AddComponent(playerLight, "PointLight"); pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f); - pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f); + pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 0.9f; pointLight->quadraticAttenuation = 0.f; @@ -118,7 +120,7 @@ void GameWorld::Initialize() transform->Position = glm::vec3(0.0f, 2.0f, 2.5f); pointLight = AddComponent(playerLight, "PointLight"); pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f); - pointLight->Diffuse = glm::vec3(0.45f, 0.65f, 1.f); + pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f); pointLight->constantAttenuation = 0.f; pointLight->linearAttenuation = 1.0f; pointLight->quadraticAttenuation = 0.f; diff --git a/Escape-the-Dawn/Renderer.cpp b/Escape-the-Dawn/Renderer.cpp index 39e3b2c..ec03c06 100644 --- a/Escape-the-Dawn/Renderer.cpp +++ b/Escape-the-Dawn/Renderer.cpp @@ -13,10 +13,10 @@ Renderer::Renderer() m_DrawBounds = false; #endif - m_ShadowMapRes = 2048*2; + m_ShadowMapRes = 2048*8; m_SunPosition = glm::vec3(0, 1.5f, 10); m_SunTarget = glm::vec3(0, 0, 0); - m_SunProjection = glm::ortho(-200, 200, -10, 100, -800, 800); + m_SunProjection = glm::ortho(-200, 200, -100, 400, -800, 600); Lights = 0; } @@ -29,8 +29,9 @@ void Renderer::Initialize() } // Create a window - WIDTH = 1280; - HEIGHT = 720; + WIDTH = 1920; + HEIGHT = 1080; + glfwWindowHint(GLFW_SAMPLES, 16); m_Window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL", nullptr, nullptr); if (!m_Window) { LOG_ERROR("GLFW: Failed to create window"); @@ -308,7 +309,7 @@ void Renderer::DrawShadowMap() void Renderer::DrawDebugShadowMap() { glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, 200*(16.f/9.f), 200); + glViewport(0, 0, 400, 400); glClear(GL_DEPTH_BUFFER_BIT); //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -525,4 +526,5 @@ void Renderer::ClearStuff() Light_linearAttenuation.clear(); Light_quadraticAttenuation.clear(); Light_spotExponent.clear(); + Lights = 0; } \ No newline at end of file diff --git a/Escape-the-Dawn/Shaders/Fragment.glsl b/Escape-the-Dawn/Shaders/Fragment.glsl index 5e3f603..4aead15 100644 --- a/Escape-the-Dawn/Shaders/Fragment.glsl +++ b/Escape-the-Dawn/Shaders/Fragment.glsl @@ -23,7 +23,7 @@ in VertexData { vec3 ShadowCoord; } Input; -vec3 scene_ambient = vec3(0.98, 0.95, 0.7); +vec3 scene_ambient = vec3(0.5, 0.5, 0.5); out vec4 fragmentColor; diff --git a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp index b578fd8..de4e695 100644 --- a/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp +++ b/Escape-the-Dawn/Systems/LevelGenerationSystem.cpp @@ -25,14 +25,13 @@ void Systems::LevelGenerationSystem::SpawnObstacle() auto model = m_World->AddComponent(ent, "Model"); auto sound = m_World->AddComponent(ent, "SoundEmitter"); - positionRandom = -500 + startx + (rand() % 1000); transform->Position = glm::vec3(positionRandom, startyz); - transform->Velocity = glm::vec3(0.f, 10.f, 0); + transform->Velocity = glm::vec3(0.f, 30.f, 0); sound->Loop = true; sound->Gain = 1.f; - sound->ReferenceDistance = 4.f; + sound->ReferenceDistance = 0.5f; m_World->GetSystem("SoundSystem")->PlaySound(sound, "Sounds/hum.wav"); if(typeRandom >= 0 && typeRandom < 1) // Mountain stuff :D @@ -77,7 +76,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle() // Put it below ground level - transform->Position.y -= bounds->VolumeVector.y * 2.f; + transform->Position.y -= transform->Scale.y * bounds->VolumeVector.y * 2.f; } diff --git a/Escape-the-Dawn/World.cpp b/Escape-the-Dawn/World.cpp index 15bbe40..8cb255c 100644 --- a/Escape-the-Dawn/World.cpp +++ b/Escape-the-Dawn/World.cpp @@ -63,6 +63,11 @@ bool World::ValidEntity(EntityID entity) void World::RemoveEntity(EntityID entity) { m_EntitiesToRemove.push_back(entity); + for (auto pair : m_EntityParents) { + if (pair.second == entity) { + m_EntitiesToRemove.push_back(pair.first); + } + } } void World::ProcessEntityRemovals() diff --git a/Escape-the-Dawn/World.h b/Escape-the-Dawn/World.h index b481397..6879e1f 100644 --- a/Escape-the-Dawn/World.h +++ b/Escape-the-Dawn/World.h @@ -81,7 +81,7 @@ protected: EntityID m_LastEntityID; std::stack m_RecycledEntityIDs; // A bottom to top tree. A map of child entities to parent entities. - std::unordered_map m_EntityParents ; + std::unordered_map m_EntityParents; std::unordered_map> m_EntityProperties; std::unordered_map>> m_ComponentsOfType;