Draw distance slider (#44)

Helps render performance on integrated GPUs.
Added render culling for baked compounds.
This commit is contained in:
Erin Catto 2026-07-03 20:26:19 -07:00 • committed by GitHub
commit 1bec63c9ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 200 additions and 8 deletions

View file

@ -78,6 +78,7 @@ Camera::Camera()
, m_fov( 60.0f * DEG_TO_RAD )
, m_near( 0.1f )
, m_far( kViewDistance )
, m_drawDistance( kViewDistance )
, m_speed( 10.0f )
, m_width( 0 )
, m_height( 0 )

View file

@ -133,6 +133,12 @@ public:
m_far = far;
}
// Draw/cull box half extent around the eye, in meters. Drives DrawBounds.
void SetDrawDistance( float meters )
{
m_drawDistance = meters;
}
// Recomputes the projection. Call after any SetFov / SetClip change, or
// when the target framebuffer aspect changes outside Update().
void RebuildProj( float aspect );
@ -164,11 +170,11 @@ public:
}
// Cull box for b3World_Draw, in simulation space (length units): a cube of the
// view distance centered on the simulation eye, so the draw set matches the far
// plane reach. The broad phase is queried in length units, hence the scale.
// draw distance centered on the simulation eye. The broad phase is queried in
// length units, hence the scale.
b3AABB DrawBounds() const
{
float h = kViewDistance * m_lengthUnitsPerMeter;
float h = m_drawDistance * m_lengthUnitsPerMeter;
b3Vec3 r = { h, h, h };
return b3OffsetAABB( { b3Neg( r ), r }, DrawOrigin() );
}
@ -182,6 +188,10 @@ public:
float m_near;
float m_far;
// Half extent of the draw/cull box around the eye (meters). Independent of the
// far plane, so it shrinks the draw set without touching the projection.
float m_drawDistance;
// Fly-mode translation speed, m/s. Scroll-tunable while right-mouse held.
float m_speed;