17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-31 18:09:04 +01:00

Cull the scenery models drawn on their own on the GPU with the instances

This commit is contained in:
2026-10-19 10:54:04 +02:00
parent ffe77be754
commit b1f880b5a7
10 changed files with 185 additions and 15 deletions

View File

@@ -511,6 +511,16 @@ bool submodel_tree_blocks_instancing( TSubModel const *Sub ) {
if( submodel_tree_blocks_instancing( Sub->Next ) ) { return true; }
return false;
}
// returns true if any submodel of the tree turns to the camera: a billboard is placed from the modelview of the drawn
// instance, which a walk started from the origin of the instance doesn't have
bool submodel_tree_faces_camera( TSubModel const *Sub ) {
if( Sub == nullptr ) { return false; }
if( ( Sub->b_Anim == TAnimType::at_Billboard ) || ( Sub->b_aAnim == TAnimType::at_Billboard ) ) { return true; }
if( submodel_tree_faces_camera( Sub->Child ) ) { return true; }
if( submodel_tree_faces_camera( Sub->Next ) ) { return true; }
return false;
}
} // anonymous namespace
int TAnimModel::s_instanceable_total = 0;
@@ -530,6 +540,7 @@ void TAnimModel::update_instanceable_flag() {
// refs are intentionally allowed — they're either passed per-instance via
// Material() or share global state (season) across all instances.
m_instanceable = false;
m_cameraindependent = ( pModel != nullptr ) && ( false == submodel_tree_faces_camera( pModel->Root ) );
++s_classified_total;
if( pModel == nullptr ) { ++s_rejected_no_pmodel; return; }
if( iNumLights != 0 ) { ++s_rejected_lights; return; }

View File

@@ -228,6 +228,10 @@ public:
// no lights, no submodel animations, no replacable skins, no seasonal variants.
// computed once at end of Load() so the renderer can simply test the flag.
bool m_instanceable { false };
// true if the walk of the submodel tree gives the same submodel-local transforms whatever modelview it starts from
// (no billboards turned to the camera): an instance drawn on its own can then be culled on the gpu like the instanced
// ones, its tree walked from the origin of the instance, which the culling places in view
bool m_cameraindependent { false };
// helper: evaluates current state and updates m_instanceable accordingly.
void update_instanceable_flag();
// helper: assigns the model and the replacable skin to the instance, and binds light and variant submodels of the model