X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fstates.cpp;h=5a9ae0a3379760711ef75ddd2048d183e734df5b;hb=fec78f7f01a03f10f8ff75c9b87929bf8c2d61e4;hp=b9fc57a4c3c15ea179d4a83b34490c513c34ecc7;hpb=cacc0641e5174d8b46e7a7086be6a45c87ab3642;p=blobs.git diff --git a/src/app/states.cpp b/src/app/states.cpp index b9fc57a..5a9ae0a 100644 --- a/src/app/states.cpp +++ b/src/app/states.cpp @@ -1,6 +1,7 @@ #include "MasterState.hpp" #include "../world/Body.hpp" +#include "../world/Creature.hpp" #include "../world/Planet.hpp" #include "../world/Simulation.hpp" #include "../world/Sun.hpp" @@ -56,11 +57,43 @@ void MasterState::OnKeyDown(const SDL_KeyboardEvent &e) { } void MasterState::OnRender(graphics::Viewport &viewport) { - glm::dmat4 ppos = cam.Model(**sim.Suns().begin()); + + int num_lights = 0; + for (auto sun : sim.Suns()) { + // TODO: source sun's light color and strength + glm::vec3 pos(cam.View() * cam.Model(*sun)[3]); + glm::vec3 col(1.0f, 1.0f, 1.0f); + float str = 1.0e6f; + assets.shaders.planet_surface.Activate(); + assets.shaders.planet_surface.SetLight(num_lights, pos, col, str); + assets.shaders.creature_skin.Activate(); + assets.shaders.creature_skin.SetLight(num_lights, pos, col, str); + ++num_lights; + if (num_lights >= graphics::PlanetSurface::MAX_LIGHTS || num_lights >= graphics::CreatureSkin::MAX_LIGHTS) { + break; + } + } + for (auto planet : sim.Planets()) { + // TODO: indirect light from planets, calculate strength and get color somehow + glm::vec3 pos(cam.View() * cam.Model(*planet)[3]); + glm::vec3 col(1.0f, 1.0f, 1.0f); + float str = 10.0f; + assets.shaders.planet_surface.Activate(); + assets.shaders.planet_surface.SetLight(num_lights, pos, col, str); + assets.shaders.creature_skin.Activate(); + assets.shaders.creature_skin.SetLight(num_lights, pos, col, str); + ++num_lights; + if (num_lights >= graphics::PlanetSurface::MAX_LIGHTS || num_lights >= graphics::CreatureSkin::MAX_LIGHTS) { + break; + } + } assets.shaders.planet_surface.Activate(); - assets.shaders.planet_surface.SetTexture(assets.textures.tiles); - assets.shaders.planet_surface.SetLight(glm::vec3(cam.View() * ppos[3]), glm::vec3(1.0f, 1.0f, 1.0f), 1.0e6f); + assets.shaders.planet_surface.SetNumLights(num_lights); + assets.shaders.creature_skin.Activate(); + assets.shaders.creature_skin.SetNumLights(num_lights); + assets.shaders.planet_surface.Activate(); + assets.shaders.planet_surface.SetTexture(assets.textures.tiles); for (auto planet : sim.Planets()) { assets.shaders.planet_surface.SetMVP(cam.Model(*planet), cam.View(), cam.Projection()); planet->Draw(assets, viewport); @@ -75,6 +108,14 @@ void MasterState::OnRender(graphics::Viewport &viewport) { assets.shaders.sun_surface.SetLight(glm::vec3(1.0f, 1.0f, 1.0f), 1.0e6f); assets.shaders.sun_surface.Draw(); } + + assets.shaders.creature_skin.Activate(); + assets.shaders.creature_skin.SetTexture(assets.textures.skins); + // TODO: extend to nearby bodies as well + for (auto c : cam.Reference().Creatures()) { + assets.shaders.creature_skin.SetMVP(cam.Model(c->GetBody()) * glm::mat4(c->LocalTransform()), cam.View(), cam.Projection()); + c->Draw(assets, viewport); + } } }