Skip to content

Commit 9344cc5

Browse files
authored
Merge pull request #13 from KTStephano/v0.7
V0.7 -> Master
2 parents 57b8c44 + 37150b3 commit 9344cc5

33 files changed

+1727
-616
lines changed

Examples/ExampleEnv01/StratusGFX.cpp

Lines changed: 69 additions & 68 deletions
Large diffs are not rendered by default.

Examples/ExampleEnv02/Sponza.cpp

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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

8080
struct 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

9192
struct 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;

Examples/ExampleEnv04/Forest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <StratusUtils.h>
1313
#include <memory>
1414
#include <filesystem>
15+
#include "StratusAsync.h"
1516

1617
class RandomLightMover { //: public stratus::Entity {
1718
glm::vec3 _direction = glm::vec3(0.0f);

Source/StratusApplication.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "StratusApplication.h"
2+
#include "StratusResourceManager.h"
3+
#include "StratusRendererFrontend.h"
4+
#include "StratusMaterial.h"
5+
#include "StratusEngine.h"
6+
7+
namespace stratus {
8+
#define INSTANCE(type) stratus::##type::Instance()
9+
10+
Application * Application::_instance = nullptr;
11+
12+
ResourceManager * Application::Resources() {
13+
return INSTANCE(ResourceManager);
14+
}
15+
16+
RendererFrontend * Application::World() {
17+
return INSTANCE(RendererFrontend);
18+
}
19+
20+
MaterialManager * Application::Materials() {
21+
return INSTANCE(MaterialManager);
22+
}
23+
24+
Engine * Application::Stratus() {
25+
return INSTANCE(Engine);
26+
}
27+
}

Source/StratusApplication.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@
44
#include <string>
55

66
namespace stratus {
7+
class ResourceManager;
8+
class RendererFrontend;
9+
class MaterialManager;
10+
class Engine;
11+
712
// Special interface class which the engine knows is the entry point
813
// for the application (e.g. editor or game)
914
class Application : public SystemModule {
15+
friend class Engine;
16+
1017
public:
18+
static Application * Instance() { return _instance; }
19+
1120
virtual ~Application() = default;
1221

1322
// Sets the name of the window
@@ -16,5 +25,14 @@ namespace stratus {
1625
virtual const char * Name() const {
1726
return GetAppName();
1827
}
28+
29+
// Convenience functions for common use cases
30+
static ResourceManager * Resources();
31+
static RendererFrontend * World();
32+
static MaterialManager * Materials();
33+
static Engine * Stratus();
34+
35+
private:
36+
static Application * _instance;
1937
};
2038
}

0 commit comments

Comments
 (0)