2#include <engine/engine_export.h>
14#include <hpp/small_vector.hpp>
101 template<
typename SubmeshIndices>
102 auto add_transform(
const SubmeshIndices& submesh_indices,
const math::mat4& transform,
bool active) -> uint32_t
108 for(uint32_t submesh_index : submesh_indices)
110 map_submesh(submesh_index, trans_index, active,
true);
123 uint32_t trans_index =
static_cast<uint32_t
>(
transforms.size());
135 void map_submesh(uint32_t submesh_index, uint32_t trans_index,
bool active,
bool casts_shadow)
164 auto get_transform(uint32_t submesh_index,
size_t instance_index)
const ->
const math::mat4*
169 if(instance_index <
indices.size())
203 if(instance_index <
indices.size())
205 return indices[instance_index].active;
222 if(instance_index <
indices.size())
224 return indices[instance_index].casts_shadow;
460 uint32_t submesh_index,
462 const
math::mat4& world_matrix,
463 const
camera& cam) const -> uint32_t;
474 uint32_t submesh_index,
476 const
math::bbox& world_bounds,
477 const
camera& cam) const -> uint32_t;
554 bool preserve_state{};
581 void submit(
const math::mat4& world_transform,
584 const std::vector<pose_mat4>& skinning_transforms,
659 const std::vector<pose_mat4>& skinning_transforms,
681 const math::mat4& world_transform,
684 float lod_param = 0.0f,
695 uint8_t cascade_count,
696 const math::mat4& world_transform,
697 const submesh_pose_mat4& submesh_transforms,
701 bool nested_cascades,
702 const model_submit_extras& extras = {})
const ->
bool;
729 auto select_submesh_lod_for_sphere(
const mesh& m,
730 uint32_t submesh_index,
733 const camera& cam)
const -> uint32_t;
736 std::vector<asset_handle<material>> materials_;
738 std::vector<material::sptr> material_instances_;
741 std::vector<asset_handle<mesh>> mesh_lods_;
744 bool lod_override_enabled_{
false};
746 uint32_t lod_override_level_{0};
748 float lod_selection_bias_{0.0f};
750 float lod_hysteresis_{0.02f};
754 std::vector<float> lod_screen_sizes_;
Provides storage for common representation of spherical bounding volume, and wraps up common function...
Storage for frustum planes / values and wraps up common functionality.
Class representing a camera. Contains functionality for manipulating and updating a camera....
Base class for materials used in rendering.
Main class representing a 3D mesh with support for different LODs, submeshes, and skinning.
Structure describing a LOD group (set of meshes), LOD transitions, and their materials.
void submit_for_vertex_pulling(const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, const std::vector< pose_mat4 > &skinning_transforms, unsigned int lod, const submit_vertex_pulling_callbacks &callbacks, const math::frustum *frustum=nullptr, const camera *view=nullptr, const model_submit_extras &extras={}) const
Submits the model using vertex-pulling rendering.
auto get_material(uint32_t index) const -> asset_handle< material >
Gets the material for the specified index.
void set_lod_override_enabled(bool enabled)
Sets whether LOD override is enabled.
auto calculate_submesh_lod(const mesh &m, uint32_t submesh_index, uint32_t base_lod, const math::mat4 &world_matrix, const camera &cam) const -> uint32_t
Selects a LOD for a specific submesh based on its own screen size.
auto get_lod_screen_size_min() const -> float
Gets the minimum screen size used by the screen-radius-squared LOD and culling method.
auto get_lod(uint32_t lod) const -> asset_handle< mesh >
Gets the LOD (Level of Detail) mesh for the specified level.
void set_lod_transition_time(seconds_t time)
Sets the LOD transition time in seconds.
auto calculate_submesh_lod_from_world_bounds(const mesh &m, uint32_t submesh_index, uint32_t base_lod, const math::bbox &world_bounds, const camera &cam) const -> uint32_t
Selects a LOD for a submesh from an already-known world-space AABB.
static auto fallback_material() -> asset_handle< material > &
Gets the fallback material.
void set_material(asset_handle< material > material, uint32_t index)
Sets the material for the specified index.
auto get_lod_override_level() const -> uint32_t
Gets the LOD override level.
void set_lod_screen_sizes(const std::vector< float > &sizes)
Sets the per-LOD screen size table used by the screen-radius-squared method.
auto is_valid() const -> bool
Checks if the model is valid.
void set_materials(const std::vector< asset_handle< material > > &materials)
Sets the materials.
void set_material_instances(const std::vector< material::sptr > &materials)
static auto default_material() -> asset_handle< material > &
Gets the default material.
void submit(const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, const pose_mat4 &bone_transforms, const std::vector< pose_mat4 > &skinning_transforms, unsigned int lod, const submit_callbacks &callbacks, const math::frustum *frustum=nullptr, const camera *view=nullptr, const model_submit_extras &extras={}) const
Submits the model for rendering.
void submit_for_batching(batch_collector &collector, const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, uint32_t lod_index, float lod_param=0.0f, const math::frustum *frustum=nullptr, const camera *view=nullptr, const model_submit_extras &extras={}) const
Collects this model into a batch collector for instanced rendering.
auto get_material_instance(uint32_t index) const -> material::sptr
void set_lod_auto_screen_size_power_base(float value)
Sets the auto LOD screen size power base (used for generating a screen-size table).
void set_lod_screen_size_min(float value)
Sets the minimum screen size used by the screen-radius-squared LOD and culling method.
auto get_lod_selection_bias() const -> float
Gets the LOD selection bias.
auto get_material_instances() const -> const std::vector< material::sptr > &
void set_lod_hysteresis(float hysteresis)
Sets the LOD hysteresis factor.
std::chrono::duration< float > seconds_t
void set_lod_selection_bias(float bias)
Sets the LOD selection bias.
auto get_lod_override_enabled() const -> bool
Gets whether LOD override is enabled.
auto submit_for_shadow_batching_cascaded(std::vector< shadow_batch_collector > &collectors, uint8_t cascade_count, const math::mat4 &world_transform, const submesh_pose_mat4 &submesh_transforms, uint32_t lod_index, float lod_param, const math::frustum *frustums, bool nested_cascades, const model_submit_extras &extras={}) const -> bool
Collects shadow-map geometry into per-cascade shadow batch collectors. Batches by mesh/lod/submesh/cu...
void set_material_instance(material::sptr material, uint32_t index)
void set_lods(const std::vector< asset_handle< mesh > > &lods)
Sets the LOD meshes.
auto calculate_lod_data(lod_data &data, const math::bbox &world_bounds, const camera &cam, float dt) const -> bool
Calculates the LOD data for the model using distance-based hysteresis with time-based transitions....
auto get_lods_count() const -> uint32_t
Gets the number of LOD levels available. If there is only one explicit mesh, returns the internal LOD...
auto get_lod_screen_sizes() const -> const std::vector< float > &
Gets the per-LOD screen size table used by the screen-radius-squared method.
void set_lod_override_level(uint32_t level)
Sets the LOD override level.
auto get_or_emplace_material_instance(uint32_t index) -> material::sptr
void recalulate_lod_screen_size_limits(uint32_t lod_count)
Recalculates the screen-size LOD thresholds for the provided LOD count. This is a separate mechanism ...
void set_lod(asset_handle< mesh > mesh, uint32_t lod)
Sets the LOD (Level of Detail) mesh for the specified level.
auto get_lod_auto_screen_size_power_base() const -> float
Gets the auto LOD screen size power base (used for generating a screen-size table).
auto get_materials() const -> const std::vector< asset_handle< material > > &
Gets all the materials.
auto get_lod_hysteresis() const -> float
Gets the LOD hysteresis factor used to prevent rapid LOD switching.
auto get_lods() const -> const std::vector< asset_handle< mesh > > &
Gets all the LOD meshes.
auto get_lod_transition_time() const -> seconds_t
Gets the LOD transition time in seconds.
auto compute_lod_index(const math::bbox &world_bounds, const camera &cam, float extra_bias=0.0f) const -> uint32_t
Computes a LOD index for this model without hysteresis, transitions or visibility culling.
Hash specialization for batch_key to enable use in std::unordered_map.
std::vector< uint32_t > indices
Thread-safe handle to an asset.
Contains level of detail (LOD) data for an entity per view. Uses distance-based hysteresis for stable...
float current_time
Current time in the LOD transition.
std::uint32_t target_lod_index
Target LOD index to transition to.
void calculate_screen_rect(const camera &cam)
irect32_t rect
Screen rectangle of the model.
float percent
Percentage of the model visible (0.0 to 100.0).
float transition_time
Total time for the LOD transition.
math::vec3 center
Center of the model in world space.
std::uint32_t current_lod_index
Current LOD index being rendered.
Parameters for the submit callbacks.
Callbacks for submitting the model for rendering.
std::function< void(const params &info, const material &)> setup_params_per_submesh
Callback for setting up per submesh.
std::function< void(const params &info)> setup_begin
Callback for setup begin.
std::function< void(const params &info)> setup_params_per_instance
Callback for setting up per instance.
std::function< void(const params &info)> setup_end
Callback for setup end.
Per-invocation information for a vertex-pulling submesh submit.
uint32_t position_offset_floats
Byte offset of the position attribute converted to floats.
uint32_t index_count
Number of indices making up the submesh.
bool preserve_state
Hint: mirror submit_callbacks::params::preserve_state.
uint32_t vertex_stride_floats
Vertex stride expressed in float-sized elements.
uint32_t indices_offset_floats
Byte offset of the bone indices attribute converted to floats.
uint32_t submesh_index
Submesh index within the LOD mesh.
bool skinned
True during the skinned pass, false during non-skinned.
uint32_t index_start
Starting index of the submesh in the index buffer (in indices).
uint32_t weight_offset_floats
Byte offset of the bone weight attribute converted to floats.
Callbacks for submitting the model using vertex-pulling rendering.
std::function< void(const params &info)> setup_params_per_instance
Called once per pass after setup_begin. Typically used to set instance-level uniforms.
std::function< void(const params &info)> setup_params_per_submesh
Called once per submesh instance after u_world and the raw VB/IB have been bound.
std::function< void(const params &info)> setup_begin
Called once per pass (once for non-skinned, once for skinned). Typically used to bind the program.
std::function< void(const params &info)> setup_end
Called once per pass at the end. Typically used to end the program.
Tracks LOD state and last access frame for a specific view (camera).
std::uint64_t last_access_frame
Last frame this view accessed this state.
lod_data data
LOD state for this camera.
std::vector< math::mat4 > transforms
Vector of bone transforms.
auto has_transforms(uint32_t submesh_index) const -> bool
Checks if a submesh has any transforms.
auto get_transform_casts_shadow(uint32_t submesh_index, size_t instance_index) const -> bool
Checks if an instance casts shadows.
void reserve(size_t count)
Reserves space for submeshes.
auto add_transform(const math::mat4 &transform) -> uint32_t
Adds a transform to the shared pool without mapping any submesh to it.
auto add_transform(const SubmeshIndices &submesh_indices, const math::mat4 &transform, bool active) -> uint32_t
Adds a transform and maps multiple submesh indices to it. All submesh indices in the vector will refe...
auto get_transform_active(uint32_t submesh_index, size_t instance_index) const -> bool
Checks if a transform is active.
auto get_transform(uint32_t submesh_index, size_t instance_index) const -> const math::mat4 *
Gets a specific transform for a submesh by its instance index.
hpp::small_vector< hpp::small_vector< transform_index > > submesh_to_transform_indices
std::vector< math::mat4 > transforms
Shared pool of unique transforms. Multiple submeshes can reference the same transform by index.
auto get_transform_count(uint32_t submesh_index) const -> size_t
Gets the number of transform instances for a specific submesh.
void map_submesh(uint32_t submesh_index, uint32_t trans_index, bool active, bool casts_shadow)
Maps a single submesh index to a pooled transform with per-instance flags.
void clear()
Clears all data.
Retained per-model render proxy data used by the culling/LOD code.