diff --git a/externals/cage b/externals/cage index 69781d0..24ace38 160000 --- a/externals/cage +++ b/externals/cage @@ -1 +1 @@ -Subproject commit 69781d056d3a12454f9aa0d55f76b0b0ed580441 +Subproject commit 24ace3855e74046628b08d9120e3c3fcda520c60 diff --git a/sources/simple/lights.cpp b/sources/simple/lights.cpp index 526f6fb..f874968 100644 --- a/sources/simple/lights.cpp +++ b/sources/simple/lights.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -148,11 +147,7 @@ int main(int argc, char *args[]) { try { - // log to console - Holder log1 = newLogger(); - log1->format.bind(); - log1->output.bind(); - + initializeConsoleLogger(); engineInitialize(EngineCreateConfig()); // events @@ -180,6 +175,7 @@ int main(int argc, char *args[]) { // spot lights Entity *e = ents->create(5 + i); e->value().object = HashString("cage-tests/bottle/other.obj?arrow"); + //e->value().object = HashString("cage/model/axes.obj"); LightComponent &l = e->value(); l.lightType = LightTypeEnum::Spot; l.spotAngle = Degs(40); @@ -198,7 +194,7 @@ int main(int argc, char *args[]) CameraComponent &c = e->value(); c.near = 0.1; c.far = 1000; - e->value(); + //e->value(); LightComponent &l = e->value(); l.lightType = LightTypeEnum::Directional; l.intensity = 1; diff --git a/sources/simple/manyLights.cpp b/sources/simple/manyLights.cpp index 94b3a26..dd01f02 100644 --- a/sources/simple/manyLights.cpp +++ b/sources/simple/manyLights.cpp @@ -2,8 +2,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -11,13 +13,29 @@ using namespace cage; constexpr uint32 AssetsName = HashString("cage-tests/translucent/translucent.pack"); -constexpr uint32 lightsCount = 500; struct MovingComponent { Vec3 velocity; }; +struct OrbitingComponent +{ + Vec3 origin; + Real dist; + Rads pitch, yaw; + Rads yawSpeed; + + Transform make(uint64 time) const + { + Transform t; + t.orientation = Quat(pitch, yaw + yawSpeed * time, {}); + t.position = origin + t.orientation * Vec3(0, 0, dist); + t.scale = 0.1; + return t; + } +}; + void update() { entitiesVisitor( @@ -28,30 +46,47 @@ void update() mv.velocity *= -1; }, engineEntities(), false); + + const uint64 time = engineControlTime(); + entitiesVisitor([time](TransformComponent &t, const OrbitingComponent &orb) { t = orb.make(time); }, engineEntities(), false); +} + +void initializeGui() +{ + Holder g = newGuiBuilder(engineGuiEntities()); + auto _1 = g->alignment(Vec2()); + auto _2 = g->panel(); + auto _3 = g->row(); + g->label().text("lights limit: "); + g->horizontalSliderBar(CameraComponent().maxLights, 0, 200) + .event(inputFilter( + [](input::GuiValue in) + { + Entity *e = engineEntities()->get(1); + e->value().maxLights = numeric_cast(in.entity->value().value); + })); } int main(int argc, char *args[]) { try { - // log to console - Holder log1 = newLogger(); - log1->format.bind(); - log1->output.bind(); - + initializeConsoleLogger(); engineInitialize(EngineCreateConfig()); // events - const auto updateListener = controlThread().update.listen(&update); + const auto updateListener = controlThread().update.listen(update); const auto closeListener = engineWindow()->events.listen(inputFilter([](input::WindowClose) { engineStop(); })); // window engineWindow()->setMaximized(); engineWindow()->title("many lights"); + initializeGui(); // entities EntityManager *ents = engineEntities(); ents->defineComponent(MovingComponent()); + ents->defineComponent(OrbitingComponent()); { // camera Entity *e = ents->create(1); TransformComponent &t = e->value(); @@ -62,6 +97,8 @@ int main(int argc, char *args[]) c.far = 1000; c.ambientColor = Vec3(1); c.ambientIntensity = 0.2; + ScreenSpaceEffectsComponent &s = e->value(); + s.effects &= ~ScreenSpaceEffectsFlags::Bloom; } { // sun Entity *e = ents->create(2); @@ -71,28 +108,64 @@ int main(int argc, char *args[]) LightComponent &l = e->value(); l.lightType = LightTypeEnum::Directional; l.color = Vec3(1, 1, 0.5); - l.intensity = 2; + l.intensity = 1; ShadowmapComponent &s = e->value(); - s.resolution = 2048; - s.directionalWorldSize = 15; + s.resolution = 4096; + s.directionalWorldSize = 20; } - { // floor + { // green floor Entity *e = ents->create(5); e->value().object = HashString("cage-tests/translucent/shapes.blend?Ground"); - e->value().position = Vec3(0, -0.2, 0); + e->value().position = Vec3(0, 0, 0); + } + { // gray floor + Entity *e = ents->create(6); + e->value().object = HashString("cage-tests/bottle/other.obj?plane"); + e->value().position = Vec3(0, 0, 0); } - // lights - for (uint32 i = 0; i < lightsCount; i++) + { // bottle + Entity *e = ents->create(7); + e->value().object = HashString("cage-tests/bottle/bottle.obj"); + e->value().position += Vec3(1, 0, 0); + e->value().scale = 0.3; + } + // spot lights + for (uint32 i = 0; i < 3; i++) + { + Entity *e = ents->createUnique(); + e->value(); + OrbitingComponent &orb = e->value(); + orb.origin = (randomChance3() * 2 - 1) * (i * 3 + 1) * Vec3(1, 0, 1); + orb.dist = randomRange(2, 5); + orb.pitch = Degs(randomRange(-50, -40)); + orb.yaw = randomAngle(); + orb.yawSpeed = Degs(20 * 1e-6); + RenderComponent &r = e->value(); + r.object = HashString("cage-tests/bottle/other.obj?arrow"); + LightComponent &l = e->value(); + l.color = r.color = Vec3(i == 0, i == 1, i == 2); + l.lightType = LightTypeEnum::Spot; + l.spotAngle = Degs(60); + l.spotExponent = 10; + l.intensity = 3; + l.minDistance = 1; + l.maxDistance = 100; + ShadowmapComponent &s = e->value(); + s.resolution = 4096; + s.directionalWorldSize = 500; + } + // point lights + for (uint32 i = 0; i < 500; i++) { Entity *e = ents->createAnonymous(); - e->value().position = (randomChance3() * 2 - 1) * 5 * Vec3(1, 0, 1); + e->value().position = randomDirection3() * 8 * Vec3(1, 0, 1) + Vec3(1, 0.2, 1); e->value().scale = 0.03; e->value().velocity = randomDirection3() * 0.02 * Vec3(1, 0, 1); - e->value().color = randomChance3() * 0.5 + 0.5; - e->value().intensity = randomRange(0.01, 3.0); - e->value().object = HashString("cage-tests/translucent/shapes.blend?Bulb"); - e->value().color = e->value().color; - e->value().intensity = e->value().intensity; + RenderComponent &r = e->value(); + r.object = HashString("cage-tests/translucent/shapes.blend?Bulb"); + LightComponent &l = e->value(); + l.color = r.color = randomChance3() * 0.5 + 0.5; + l.intensity = r.intensity = randomRange(0.5, 2.0); } Holder cameraCtrl = newFpsCamera(ents->get(1));