17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-06 16:18:35 +01:00

Cull instances by compact records and draw them from a shader storage buffer

This commit is contained in:
2026-10-16 00:37:54 +02:00
parent fd98d4eea5
commit 9277c28805
13 changed files with 269 additions and 228 deletions

View File

@@ -237,19 +237,31 @@ public:
}
};
using instance_bucket_map = std::unordered_map< instance_bucket_key, std::vector<TAnimModel *>, instance_bucket_key_hash >;
// what it takes to tell that an instance is out of sight, copied from the instance.
// what it takes to cull and place an instance, copied from the instance.
// a cell can hold thousands of instances, each of them large and placed wherever the memory was free, and a render
// pass rejects most of them. the renderer makes the copies and goes by them, to fetch only the instances it may draw
struct instance_bounds {
glm::vec3 center { 0.f }; // location of the instance, in the precision the frustum test takes it
// pass rejects most of them. the renderer makes the copies and goes by them, and reads the instance itself only
// for the first one of a batch drawn. the layout follows std430, for the copies to be handed to the gpu as they are
struct instance_record {
glm::vec3 position { 0.f }; // location of the instance, relative to the origin of the records of its bucket
float radius { 0.f };
float rangesquaredmax { 0.f }; // past it the instance isn't drawn: by its own range, or the lod stages of its model
float rangesquaredmin { 0.f }; // visibility range of the instance
float rangesquaredmax { 0.f };
std::uint32_t flags { 0 }; // instance_record_flags
std::uint32_t pad { 0 };
glm::vec4 rotationscale[ 3 ] {}; // columns of rotation and scale of the instance, w unused
};
static_assert( sizeof( instance_record ) == 80, "instance_record has to keep its std430 layout" );
enum instance_record_flags : std::uint32_t {
instance_visible = 1 << 0,
instance_instanceable = 1 << 1, // false once an event gave the instance animations or a skin of its own
};
struct instance_bucket {
std::vector<TAnimModel *> instances;
// caches owned by the renderer; emptied whenever the content of the bucket changes
mutable std::vector<instance_bounds> bounds; // copies for the instances, in the same order
mutable unsigned int boundsversion { 0 };
mutable std::vector<instance_record> records; // copies for the instances, in the same order
mutable glm::dvec3 recordorigin { 0.0 }; // the records hold locations relative to it
mutable float lodrangesquared { 0.f }; // past it no submodel of the model of the bucket is drawn
mutable unsigned int recordsversion { 0 };
};
using instance_bucketdata_map = std::unordered_map< instance_bucket_key, instance_bucket, instance_bucket_key_hash >;
using sound_sequence = std::vector<sound_source *>;