Skip to content

Commit

Permalink
Merge pull request #158 from JamesTKhan/cull-optimization
Browse files Browse the repository at this point in the history
Reduce cull check matrix calcs
  • Loading branch information
JamesTKhan authored May 1, 2023
2 parents 4ab255e + c1687ef commit 7b7396d
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@
public abstract class CullableComponent extends AbstractComponent implements ModelEventable {
private final static BoundingBox tmpBounds = new BoundingBox();
private final static Vector3 tmpScale = new Vector3();
private final static short frameCullCheckInterval = 15;
private static DirectionalLight directionalLight;

protected final Vector3 center = new Vector3();
protected final Vector3 dimensions = new Vector3();
protected float radius;

// Render calls since last cull check
protected short framesSinceLastCullCheck = 0;

// Is it offscreen?
protected boolean isCulled = false;
private Array<Event> events;
Expand All @@ -78,9 +82,15 @@ public void render(float delta) {
if (this instanceof ModelCacheable) {
if (((ModelCacheable) this).shouldCache()) {
isCulled = false;
return;
}
}

// If object is not culled, don't perform a cull check every frame, just in intervals
// to reduce matrix calculations
if (!isCulled && framesSinceLastCullCheck++ < frameCullCheckInterval) return;
framesSinceLastCullCheck = 0;

boolean visibleToPerspective;
boolean visibleToShadowMap = false;

Expand Down

0 comments on commit 7b7396d

Please sign in to comment.