mirror of
https://github.com/mwpenny/portal64-still-alive.git
synced 2024-10-20 10:37:37 -04:00
Don't cull animated objects in rooms where many exist
Calculating whether or not to cull many objects can be more expensive than rendering them
This commit is contained in:
parent
2b09deb1fe
commit
1318e8ec4b
|
@ -47,6 +47,8 @@ void staticRenderTraverseIndex(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ANIMATED_CULL_THRESHOLD 50
|
||||||
|
|
||||||
void staticRenderPopulateRooms(struct FrustrumCullingInformation* cullingInfo, Mtx* staticMatrices, struct Transform* staticTransforms, struct RenderScene* renderScene) {
|
void staticRenderPopulateRooms(struct FrustrumCullingInformation* cullingInfo, Mtx* staticMatrices, struct Transform* staticTransforms, struct RenderScene* renderScene) {
|
||||||
int currentRoom = 0;
|
int currentRoom = 0;
|
||||||
|
|
||||||
|
@ -60,18 +62,24 @@ void staticRenderPopulateRooms(struct FrustrumCullingInformation* cullingInfo, M
|
||||||
|
|
||||||
struct BoundingBoxs16* animatedBox = roomIndex->animatedBoxes;
|
struct BoundingBoxs16* animatedBox = roomIndex->animatedBoxes;
|
||||||
|
|
||||||
|
// For rooms with with many animated elements, calculating whether
|
||||||
|
// or not to cull them is more expensive than just rendering them
|
||||||
|
short animatedElementCount = roomIndex->animatedRange.max - roomIndex->animatedRange.min;
|
||||||
|
u8 shouldCull = animatedElementCount < ANIMATED_CULL_THRESHOLD;
|
||||||
|
|
||||||
for (int i = roomIndex->animatedRange.min; i < roomIndex->animatedRange.max; ++i, ++animatedBox) {
|
for (int i = roomIndex->animatedRange.min; i < roomIndex->animatedRange.max; ++i, ++animatedBox) {
|
||||||
struct StaticContentElement* staticElement = &gCurrentLevel->staticContent[i];
|
struct StaticContentElement* staticElement = &gCurrentLevel->staticContent[i];
|
||||||
|
|
||||||
struct RotatedBox rotatedBox;
|
|
||||||
|
|
||||||
struct Transform* transform = &staticTransforms[staticElement->transformIndex];
|
struct Transform* transform = &staticTransforms[staticElement->transformIndex];
|
||||||
|
|
||||||
|
if (shouldCull) {
|
||||||
|
struct RotatedBox rotatedBox;
|
||||||
rotatedBoxTransform(transform, animatedBox, &rotatedBox);
|
rotatedBoxTransform(transform, animatedBox, &rotatedBox);
|
||||||
|
|
||||||
if (isRotatedBoxOutsideFrustrum(cullingInfo, &rotatedBox)) {
|
if (isRotatedBoxOutsideFrustrum(cullingInfo, &rotatedBox)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Vector3 center;
|
struct Vector3 center;
|
||||||
vector3AddScaled(&staticElement->center, &transform->position, 1.0f / SCENE_SCALE, ¢er);
|
vector3AddScaled(&staticElement->center, &transform->position, 1.0f / SCENE_SCALE, ¢er);
|
||||||
|
|
Loading…
Reference in a new issue