diff --git a/game/graphics.cc b/game/graphics.cc index 49ecb3e..0167749 100644 --- a/game/graphics.cc +++ b/game/graphics.cc @@ -649,7 +649,7 @@ void Graphics::render(double time) void Graphics::updateLights() { std::vector> oldClosestLights = std::vector>(*closestLights); - closestLights = level->getClosestLights(); + closestLights = level->getClosestLights(maxShadowSampleCount); if (closestLights->size() > 0) { lightingShader->use(); lightingShader->setUniform("lightCount", (int) closestLights->size()); @@ -873,7 +873,7 @@ void Graphics::enqueueObjects(std::vector>* queue){ } void Graphics::initShadowRenderQueue() { - closestLights = level->getClosestLights(); + closestLights = level->getClosestLights(maxShadowSampleCount); int maxLights = min((int)closestLights->size(), maxShadowSampleCount); shadowRenderQueue = std::vector(maxLights); glViewport(0, 0, cube_size, cube_size); diff --git a/game/level.cc b/game/level.cc index a109b2e..1b6d319 100644 --- a/game/level.cc +++ b/game/level.cc @@ -468,14 +468,14 @@ bool Level::compareLightDistances(shared_ptr a, shared_ptr b) { } } -std::vector>* Level::getClosestLights() { +std::vector>* Level::getClosestLights(unsigned int maximumAmount) { closestLights = std::vector>(lights); std::sort(closestLights.begin(), closestLights.end(), [this](shared_ptr a, shared_ptr b) {return compareLightDistances(a, b); }); - if (lights.size() > 15) { + if (lights.size() > maximumAmount) { closestLights = std::vector>(&closestLights[0], - &closestLights[15]); + &closestLights[maximumAmount]); } // sort pointers for faster comparisons std::sort(closestLights.begin(), closestLights.end()); diff --git a/game/level.hh b/game/level.hh index 42a8c12..a06e20b 100644 --- a/game/level.hh +++ b/game/level.hh @@ -86,7 +86,7 @@ class Level { void addToSpecificChunk(Object* object, int xPosition, int zPosition); void enqueueObjects(Graphics* graphics); void sortObjects(int textureCount); - std::vector>* getClosestLights(); + std::vector>* getClosestLights(unsigned int maximumAmount); int checkMaxSurroundingLights(); private: std::vector getSurroundingChunks(glm::vec3 center, int chunkRenderDistance);