diff --git a/externals/cage b/externals/cage index 7eb3056..fcd947f 160000 --- a/externals/cage +++ b/externals/cage @@ -1 +1 @@ -Subproject commit 7eb305699f32b86a1268fd72e70864fbf7514279 +Subproject commit fcd947f41394fc737e61fe204830191c13748d96 diff --git a/sources/scenes/game.cpp b/sources/scenes/game.cpp index 918d533..82adb26 100644 --- a/sources/scenes/game.cpp +++ b/sources/scenes/game.cpp @@ -110,28 +110,21 @@ void sceneReload() for (int i = 0; i < directionalLightsCount; i++) { directionalLights[i] = engineEntities()->createAnonymous(); - TransformComponent &ts = directionalLights[i]->value(); - ts.orientation = Quat(Degs(randomChance() * -20 - 30), Degs(i * 360.0f / (float)directionalLightsCount + randomChance() * 180 / (float)directionalLightsCount), Degs()); + directionalLights[i]->value().orientation = Quat(Degs(randomChance() * -20 - 30), Degs(i * 360.0f / (float)directionalLightsCount + randomChance() * 180 / (float)directionalLightsCount), Degs()); LightComponent &ls = directionalLights[i]->value(); ls.color = Vec3(1); ls.intensity = 2.5; ls.lightType = LightTypeEnum::Directional; - ShadowmapComponent &ss = directionalLights[i]->value(); - ss.resolution = 2048; + directionalLights[i]->value().resolution = 2048; } // point lights for (int i = 0; i < pointLightsCount; i++) { - pointLights[i] = engineEntities()->createAnonymous(); - TransformComponent &ts = pointLights[i]->value(); - ts.position = (Vec3(randomChance(), randomChance(), randomChance()) * 2 - 1) * 15; - LightComponent &ls = pointLights[i]->value(); - ls.color = colorHsvToRgb(Vec3(randomChance(), 1, 1)); - ls.lightType = LightTypeEnum::Point; - RenderComponent &r = pointLights[i]->value(); - r.color = ls.color; - r.object = HashString("scenes/common/lightbulb.obj"); + Entity *e = pointLights[i] = engineEntities()->createAnonymous(); + e->value().position = (Vec3(randomChance(), randomChance(), randomChance()) * 2 - 1) * 15; + e->value().color = e->value().color = colorHsvToRgb(Vec3(randomChance(), 1, 1)); + e->value().object = HashString("scenes/common/lightbulb.obj"); } } diff --git a/sources/simple/explosions.cpp b/sources/simple/explosions.cpp index 813d72c..5aeae7d 100644 --- a/sources/simple/explosions.cpp +++ b/sources/simple/explosions.cpp @@ -95,7 +95,6 @@ void makeExplosion(const Vec3 &position) l.color += randomRange3(-0.05, 0.05); l.color = clamp(l.color, 0, 1); l.intensity = randomRange(2.0, 4.0); - l.attenuation = Vec3(0, 0.5, 0.5); } } { diff --git a/sources/simple/lights.cpp b/sources/simple/lights.cpp index 24c29e1..d429d6d 100644 --- a/sources/simple/lights.cpp +++ b/sources/simple/lights.cpp @@ -191,8 +191,7 @@ int main(int argc, char *args[]) l.lightType = LightTypeEnum::Spot; l.spotAngle = Degs(40); l.spotExponent = 40; - l.attenuation = Vec3(1, 0, 0.005); - l.intensity = 3; + l.intensity = 100; ShadowmapComponent &s = e->value(); s.resolution = 1024; s.worldSize = Vec3(3, 50, 0); diff --git a/sources/simple/manyLights.cpp b/sources/simple/manyLights.cpp new file mode 100644 index 0000000..7d2c06d --- /dev/null +++ b/sources/simple/manyLights.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace cage; +constexpr uint32 assetsName = HashString("cage-tests/translucent/translucent.pack"); +constexpr uint32 lightsCount = 500; + +struct MovingComponent +{ + Vec3 velocity; +}; + +void update() +{ + entitiesVisitor( + [](TransformComponent &t, MovingComponent &mv) + { + t.position += mv.velocity; + if (length(t.position) > 10) + mv.velocity *= -1; + }, + engineEntities(), false); +} + +int main(int argc, char *args[]) +{ + try + { + // log to console + Holder log1 = newLogger(); + log1->format.bind(); + log1->output.bind(); + + engineInitialize(EngineCreateConfig()); + + // events + const auto updateListener = controlThread().update.listen(&update); + const auto closeListener = engineWindow()->events.listen(inputListener([](auto) { engineStop(); })); + + // window + engineWindow()->setMaximized(); + engineWindow()->title("many lights"); + + // entities + EntityManager *ents = engineEntities(); + ents->defineComponent(MovingComponent()); + { // camera + Entity *e = ents->create(1); + TransformComponent &t = e->value(); + t.position = Vec3(8, 6, 10); + t.orientation = Quat(Degs(-30), Degs(40), Degs()); + CameraComponent &c = e->value(); + c.near = 0.1; + c.far = 1000; + c.ambientColor = Vec3(1); + c.ambientIntensity = 0.2; + } + { // sun + Entity *e = ents->create(2); + TransformComponent &t = e->value(); + t.orientation = Quat(Degs(-50), Degs(-42 + 180), Degs()); + t.position = Vec3(0, 5, 0); + LightComponent &l = e->value(); + l.lightType = LightTypeEnum::Directional; + l.color = Vec3(1, 1, 0.5); + l.intensity = 2; + ShadowmapComponent &s = e->value(); + s.resolution = 2048; + s.worldSize = Vec3(15); + } + { // floor + Entity *e = ents->create(5); + e->value().object = HashString("cage-tests/translucent/shapes.blend?Ground"); + e->value().position = Vec3(0, -0.2, 0); + } + // lights + for (uint32 i = 0; i < lightsCount; i++) + { + Entity *e = ents->createAnonymous(); + e->value().position = (randomChance3() * 2 - 1) * 5 * Vec3(1, 0, 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; + } + + Holder cameraCtrl = newFpsCamera(ents->get(1)); + cameraCtrl->mouseButton = MouseButtonsFlags::Left; + cameraCtrl->movementSpeed = 0.3; + Holder statistics = newStatisticsGui(); + + engineAssets()->add(assetsName); + engineRun(); + engineAssets()->remove(assetsName); + engineFinalize(); + + return 0; + } + catch (...) + { + detail::logCurrentCaughtException(); + return 1; + } +} diff --git a/sources/simple/screamers.cpp b/sources/simple/screamers.cpp index fdbd9f8..b4e2b58 100644 --- a/sources/simple/screamers.cpp +++ b/sources/simple/screamers.cpp @@ -101,7 +101,6 @@ void makeExplosion(const Vec3 &position) l.color += randomRange3(-0.05, 0.05); l.color = saturate(l.color); l.intensity = 8; - l.attenuation = Vec3(0, 1, 0); } } { @@ -120,7 +119,6 @@ void makeExplosion(const Vec3 &position) l.color += randomRange3(-0.05, 0.05); l.color = saturate(l.color); l.intensity = 5; - l.attenuation = Vec3(0, 1, 0); } } { @@ -180,7 +178,6 @@ void spawnScreamer() snd.startTime = engineControlTime(); LightComponent &lig = e->value(); - lig.attenuation = Vec3(0, 1, 0); render.color = lig.color = randomDirection3() * 0.5 + 0.5; lig.intensity = 5; diff --git a/sources/simple/translucent.cpp b/sources/simple/translucent.cpp index fe270fb..6abec45 100644 --- a/sources/simple/translucent.cpp +++ b/sources/simple/translucent.cpp @@ -140,7 +140,6 @@ int main(int argc, char *args[]) l.lightType = LightTypeEnum::Spot; l.spotAngle = Degs(60); l.spotExponent = 40; - l.attenuation = Vec3(0, 0, 0.03); l.color = Vec3(1); l.intensity = 15; ShadowmapComponent &s = e->value(); @@ -247,8 +246,7 @@ int main(int argc, char *args[]) LightComponent &l = e->value(); l.lightType = LightTypeEnum::Point; r.color = l.color = colorHsvToRgb(randomChance3() * Vec3(1, .5, .5) + Vec3(0, .5, .5)); - l.intensity = 3; - l.attenuation = Vec3(0.5, 0, 0.07); + l.intensity = 20; } for (uint32 j = 0; j < 3; j++) {