X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fstates.cpp;h=5a9ae0a3379760711ef75ddd2048d183e734df5b;hb=196f02bdbbd372b77141201f045fcfea318093b1;hp=86b2e82c3b71e3d9d9ab630a515facde11573ab9;hpb=02d5571eef7630c38968af264a441aa43e802d0f;p=blobs.git diff --git a/src/app/states.cpp b/src/app/states.cpp index 86b2e82..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,36 +57,43 @@ void MasterState::OnKeyDown(const SDL_KeyboardEvent &e) { } void MasterState::OnRender(graphics::Viewport &viewport) { - assets.shaders.planet_surface.Activate(); - assets.shaders.planet_surface.SetTexture(assets.textures.tiles); int num_lights = 0; for (auto sun : sim.Suns()) { // TODO: source sun's light color and strength - assets.shaders.planet_surface.SetLight( - num_lights, - glm::vec3(cam.View() * cam.Model(*sun)[3]), - glm::vec3(1.0f, 1.0f, 1.0f), - 1.0e6f); + 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) { + 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 - assets.shaders.planet_surface.SetLight( - num_lights, - glm::vec3(cam.View() * cam.Model(*planet)[3]), - glm::vec3(1.0f, 1.0f, 1.0f), - 10.0f); + 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) { + if (num_lights >= graphics::PlanetSurface::MAX_LIGHTS || num_lights >= graphics::CreatureSkin::MAX_LIGHTS) { break; } } + assets.shaders.planet_surface.Activate(); 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); @@ -100,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); + } } }