33#include < iostream>
44#include < StratusPipeline.h>
55#include < StratusCamera.h>
6+ #include " StratusAsync.h"
67#include < chrono>
78#include " StratusEngine.h"
89#include " StratusResourceManager.h"
@@ -36,15 +37,14 @@ class RandomLightMover { //: public stratus::Entity {
3637 glm::vec3 speed;
3738 bool spawnPhysicalMarker;
3839
39- RandomLightMover (const bool spawnPhysicalMarker = true ,
40- const bool brightensWithSun = false )
40+ RandomLightMover (const bool spawnPhysicalMarker = true , stratus::LightPtr ptr = nullptr )
4141 : spawnPhysicalMarker(spawnPhysicalMarker) {
4242 cube = stratus::ResourceManager::Instance ()->CreateCube ();
4343 cube->GetRenderNode ()->SetMaterial (stratus::MaterialManager::Instance ()->CreateDefault ());
4444 cube->GetRenderNode ()->EnableLightInteraction (false );
4545 // cube->scale = glm::vec3(0.25f, 0.25f, 0.25f);
4646 cube->SetLocalScale (glm::vec3 (1 .0f ));
47- light = stratus::LightPtr (new stratus::PointLight (brightensWithSun ));
47+ light = ptr ? ptr : stratus::LightPtr (new stratus::PointLight ());
4848 _changeDirection ();
4949 }
5050
@@ -78,7 +78,8 @@ class RandomLightMover { //: public stratus::Entity {
7878};
7979
8080struct StationaryLight : public RandomLightMover {
81- StationaryLight (const bool spawnPhysicalMarker = true ) : RandomLightMover(spawnPhysicalMarker) {}
81+ StationaryLight (const bool spawnPhysicalMarker = true )
82+ : RandomLightMover(spawnPhysicalMarker) {}
8283
8384 void update (double deltaSeconds) override {
8485 cube->SetLocalPosition (position);
@@ -90,7 +91,7 @@ struct StationaryLight : public RandomLightMover {
9091
9192struct FakeRTGILight : public RandomLightMover {
9293 FakeRTGILight (const bool spawnPhysicalMarker = true )
93- : RandomLightMover(spawnPhysicalMarker, /* brightensWithSun = */ true ) {}
94+ : RandomLightMover(spawnPhysicalMarker, stratus::LightPtr( new stratus::VirtualPointLight()) ) {}
9495
9596 void update (double deltaSeconds) override {
9697 cube->SetLocalPosition (position);
@@ -140,6 +141,17 @@ class Sponza : public stratus::Application {
140141
141142 worldLight->setRotation (stratus::Rotation (stratus::Degrees (0 .0f ), stratus::Degrees (10 .0f ), stratus::Degrees (0 .0f )));
142143
144+ // for (int i = 0; i < 64; ++i) {
145+ // float x = rand() % 600;
146+ // float y = rand() % 600;
147+ // float z = rand() % 200;
148+ // stratus::VirtualPointLight * vpl = new stratus::VirtualPointLight();
149+ // vpl->setIntensity(worldLight->getIntensity() * 50.0f);
150+ // vpl->position = glm::vec3(x, y, z);
151+ // vpl->setColor(worldLight->getColor());
152+ // World()->AddLight(stratus::LightPtr((stratus::Light *)vpl));
153+ // }
154+
143155 return true ;
144156 }
145157
@@ -159,6 +171,8 @@ class Sponza : public stratus::Application {
159171 float fogDensity = stratus::RendererFrontend::Instance ()->GetAtmosphericFogDensity ();
160172 float scatterControl = stratus::RendererFrontend::Instance ()->GetAtmosphericScatterControl ();
161173
174+ const glm::vec3 warmMorningColor = glm::vec3 (254 .0f / 255 .0f , 232 .0f / 255 .0f , 176 .0f / 255 .0f );
175+
162176 // STRATUS_LOG << "Camera " << camera.getYaw() << " " << camera.getPitch() << std::endl;
163177
164178 // Check for key/mouse events
@@ -223,6 +237,11 @@ class Sponza : public stratus::Application {
223237 }
224238 break ;
225239 case SDL_SCANCODE_I:
240+ if (released) {
241+ worldLightMoveDirection = -worldLightMoveDirection;
242+ }
243+ break ;
244+ case SDL_SCANCODE_L:
226245 if (released) {
227246 worldLight->setEnabled ( !worldLight->getEnabled () );
228247 }
@@ -267,8 +286,7 @@ class Sponza : public stratus::Application {
267286 if (released) {
268287 std::unique_ptr<RandomLightMover> mover (new FakeRTGILight (/* spawnPhysicalMarker = */ false ));
269288 mover->light ->setIntensity (worldLight->getIntensity () * 100 );
270- const auto worldLightColor = worldLight->getColor ();
271- mover->light ->setColor (worldLightColor.r , worldLightColor.g , worldLightColor.b );
289+ mover->light ->setColor (warmMorningColor);
272290 mover->position = camera->getPosition ();
273291 mover->addToScene ();
274292 lightMovers.push_back (std::move (mover));
@@ -279,8 +297,7 @@ class Sponza : public stratus::Application {
279297 if (released) {
280298 std::unique_ptr<RandomLightMover> mover (new FakeRTGILight (/* spawnPhysicalMarker = */ false ));
281299 mover->light ->setIntensity (worldLight->getIntensity () * 50 );
282- const auto worldLightColor = worldLight->getColor ();
283- mover->light ->setColor (worldLightColor.r , worldLightColor.g , worldLightColor.b );
300+ mover->light ->setColor (warmMorningColor);
284301 mover->position = camera->getPosition ();
285302 mover->addToScene ();
286303 lightMovers.push_back (std::move (mover));
@@ -293,6 +310,7 @@ class Sponza : public stratus::Application {
293310 mover->light ->setIntensity (worldLight->getIntensity () * 10 );
294311 const auto worldLightColor = glm::vec3 (1 .0f , 0 .0f , 0 .0f );
295312 mover->light ->setColor (worldLightColor.r , worldLightColor.g , worldLightColor.b );
313+ ((stratus::VirtualPointLight *)mover->light .get ())->SetNumShadowSamples (9 );
296314 mover->position = camera->getPosition ();
297315 mover->addToScene ();
298316 lightMovers.push_back (std::move (mover));
@@ -305,6 +323,7 @@ class Sponza : public stratus::Application {
305323 mover->light ->setIntensity (worldLight->getIntensity () * 10 );
306324 const auto worldLightColor = glm::vec3 (0 .0f , 1 .0f , 0 .0f );
307325 mover->light ->setColor (worldLightColor.r , worldLightColor.g , worldLightColor.b );
326+ ((stratus::VirtualPointLight *)mover->light .get ())->SetNumShadowSamples (9 );
308327 mover->position = camera->getPosition ();
309328 mover->addToScene ();
310329 lightMovers.push_back (std::move (mover));
@@ -317,19 +336,34 @@ class Sponza : public stratus::Application {
317336 mover->light ->setIntensity (worldLight->getIntensity () * 10 );
318337 const auto worldLightColor = glm::vec3 (0 .0f , 0 .0f , 1 .0f );
319338 mover->light ->setColor (worldLightColor.r , worldLightColor.g , worldLightColor.b );
339+ ((stratus::VirtualPointLight *)mover->light .get ())->SetNumShadowSamples (9 );
320340 mover->position = camera->getPosition ();
321341 mover->addToScene ();
322342 lightMovers.push_back (std::move (mover));
323343 }
324344 break ;
325345 }
346+ case SDL_SCANCODE_G: {
347+ if (released) {
348+ const bool enabled = World ()->GetGlobalIlluminationEnabled ();
349+ World ()->SetGlobalIlluminationEnabled ( !enabled );
350+ }
351+ break ;
352+ }
326353 case SDL_SCANCODE_C: {
327354 for (auto & light : lightMovers) {
328355 light->removeFromScene ();
329356 }
330357 lightMovers.clear ();
331358 break ;
332359 }
360+ case SDL_SCANCODE_Z:
361+ if (released) {
362+ if (lightMovers.size () > 0 ) {
363+ lightMovers[lightMovers.size () - 1 ]->removeFromScene ();
364+ lightMovers.pop_back ();
365+ }
366+ }
333367 default : break ;
334368 }
335369 break ;
@@ -343,14 +377,17 @@ class Sponza : public stratus::Application {
343377 // worldLight->setRotation(glm::vec3(75.0f, 0.0f, 0.0f));
344378 // worldLight->setRotation(stratus::Rotation(stratus::Degrees(30.0f), stratus::Degrees(0.0f), stratus::Degrees(0.0f)));
345379 if (!worldLightPaused) {
346- worldLight->offsetRotation (glm::vec3 (value * deltaSeconds, 0 .0f , 0 .0f ));
380+ worldLight->offsetRotation (glm::vec3 (worldLightMoveDirection * value * deltaSeconds, 0 .0f , 0 .0f ));
347381 }
348382
383+ #define LERP (x, v1, v2 ) (x * v1 + (1 .0f - x) * v2)
384+
349385 // renderer->toggleWorldLighting(worldLightEnabled);
350386 stratus::RendererFrontend::Instance ()->SetWorldLight (worldLight);
351387 // worldLight->setColor(glm::vec3(1.0f, 0.75f, 0.5));
352388 // worldLight->setColor(glm::vec3(1.0f, 0.75f, 0.75f));
353- worldLight->setColor (glm::vec3 (1 .0f ));
389+ const float x = std::sinf (stratus::Radians (worldLight->getRotation ().x ).value ());
390+ worldLight->setColor (warmMorningColor);
354391 worldLight->setPosition (camera->getPosition ());
355392 // worldLight->setRotation(glm::vec3(90.0f, 0.0f, 0.0f));
356393 // renderer->setWorldLight(worldLight);
@@ -407,6 +444,7 @@ class Sponza : public stratus::Application {
407444 std::vector<stratus::EntityPtr> entities;
408445 stratus::CameraPtr camera;
409446 glm::vec3 cameraSpeed;
447+ float worldLightMoveDirection = 1.0 ; // -1.0 reverses it
410448 float camSpeedDivide = 0 .25f ; // For slowing camera down
411449 stratus::LightPtr cameraLight;
412450 stratus::InfiniteLightPtr worldLight;
0 commit comments