MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / CollectLights

Method CollectLights

TombEngine/Renderer/RendererFrame.cpp:621–782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619 }
620
621 void Renderer::CollectLights(const Vector3& pos, float radius, int roomNumber, int prevRoomNumber, bool prioritizeShadowLight, bool useCachedRoomLights, std::vector<RendererLightNode>* roomsLights, std::vector<RendererLight*>* outputLights)
622 {
623 if (_rooms.size() <= roomNumber)
624 return;
625
626 // Now collect lights from dynamic list and from rooms
627 std::vector<RendererLightNode> tempLights;
628 tempLights.reserve(MAX_LIGHTS_DRAW);
629
630 auto& room = _rooms[roomNumber];
631
632 RendererLight* brightestLight = nullptr;
633 float brightest = 0.0f;
634
635 // Dynamic lights have the priority
636 for (auto& light : _dynamicLights[_dynamicLightList])
637 {
638 float distSqr = Vector3::DistanceSquared(pos, light.Position);
639
640 // Collect only lights nearer than 20 sectors
641 if (distSqr >= SQUARE(BLOCK(20)))
642 continue;
643
644 // Check the out radius
645 if (distSqr > SQUARE(light.Out + radius))
646 continue;
647
648 float distance = sqrt(distSqr);
649 float attenuation = 1.0f - distance / light.Out;
650 float intensity = attenuation * light.Intensity * light.Luma;
651
652 // If collecting shadows, try collecting shadow-casting light.
653 if (prioritizeShadowLight && light.CastShadows && intensity >= brightest)
654 {
655 brightest = intensity;
656 brightestLight = &light;
657 }
658
659 RendererLightNode node = { &light, intensity, distance, 1 };
660 tempLights.push_back(node);
661 }
662
663 if (!useCachedRoomLights)
664 {
665 // Check current room and neighbor rooms.
666 for (int roomToCheck : room.Neighbors)
667 {
668 auto& currentRoom = _rooms[roomToCheck];
669 int lightCount = (int)currentRoom.Lights.size();
670
671 for (int j = 0; j < lightCount; j++)
672 {
673 auto& light = currentRoom.Lights[j];
674
675 float intensity = 0;
676 float dist = 0;
677
678 // Check only lights different from sun.

Callers

nothing calls this directly

Calls 7

LumaFunction · 0.85
sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected