18#define POOLSTL_STD_SUPPLEMENT 1
19#include <poolstl/poolstl.hpp>
27 prefilter_pass_.init(ctx);
29 atmospheric_pass_.init(ctx);
30 atmospheric_pass_perez_.init(ctx);
31 atmospheric_pass_skybox_.init(ctx);
33 tonemapping_pass_.init(ctx);
34 assao_pass_.init(ctx);
40 auto load_program = [&](
const std::string& vs,
const std::string&
fs)
42 auto vs_shader = am.get_asset<
gfx::shader>(
"engine:/data/shaders/" + vs +
".sc");
43 auto fs_shadfer = am.get_asset<
gfx::shader>(
"engine:/data/shaders/" +
fs +
".sc");
45 return std::make_unique<gpu_program>(vs_shader, fs_shadfer);
48 particle_program_ = load_program(
"particles/vs_particle",
"particles/fs_particle");
49 particle_program_instanced_ = load_program(
"particles/instanced/vs_particle_instanced",
"particles/instanced/fs_particle_instanced");
69 std::for_each( view.begin(), view.end(),
72 auto&& [transform_comp, model_comp, layer_comp, active_comp] = view.get(entity);
75 auto entity_layer = layer_comp.layers;
78 if(!model_comp.is_enabled())
82 if((query & visibility_query::is_static) && !model_comp.is_static())
86 if((query & visibility_query::is_reflection_caster) && !model_comp.casts_reflection())
90 if((query & visibility_query::is_shadow_caster) && !model_comp.casts_shadow())
96 if((entity_layer.mask & render_mask.mask) == 0)
101 bool is_visible =
true;
105 const auto& world_transform = transform_comp.get_transform_global();
106 const auto& local_bounds = model_comp.get_local_bounds();
109 is_visible = frustum->test_obb(local_bounds, world_transform);
117 result.emplace_back(scn.create_handle(entity));
135 params.params = assao_comp->settings;
146 params.config = tonemapping_comp->settings;
176 params.settings = ssr_comp->settings;
190 auto& fbo = rview.
fbo_get(
"OBUFFER_DEPTH");
194 pass.
bind(fbo.get());
198 [&](
auto e,
auto&& transform_comp,
auto&& text_comp,
auto&& active)
200 const auto& world_transform = transform_comp.get_transform_global();
201 auto bbox = text_comp.get_bounds();
208 text_comp.submit(pass.
id, world_transform, BGFX_STATE_DEPTH_TEST_LESS);
219 auto lbuffer_depth = rview.
fbo_get(
"LBUFFER_DEPTH");
223 pass.
bind(lbuffer_depth.get());
229 stats_.drawn_particles = 0;
230 stats_.drawn_particles_batches = 0;
232 if(particle_program_instanced_ && particle_program_instanced_->begin())
244 hpp::small_vector<sort_key, 16> particle_emitters;
249 [&](
auto e,
auto&& transform_comp,
auto&& particle_emitter_comp,
auto&& active)
251 const auto& bounds = particle_emitter_comp.get_world_bounds();
257 auto distance = math::distance(bounds.get_center(), cam_pos);
258 particle_emitters.emplace_back(sort_key{&particle_emitter_comp,
distance});
265 std::sort(particle_emitters.begin(), particle_emitters.end(), [](
const sort_key&
a,
const sort_key&
b)
267 return a.distance < b.distance;
273 APP_SCOPE_PERF(
"Rendering/Particle Pass/Group Emitters by Texture");
277 hpp::small_vector<EmitterHandle, 16> current_batch;
280 for(
const auto& particle_emitter : particle_emitters)
283 if(current_texture != particle_emitter.component->get_texture())
286 if(!current_batch.empty())
288 auto texture = current_texture.
get()->native_handle();
289 stats_.drawn_particles +=
psRenderEmitterBatch(current_batch.data(),
static_cast<uint32_t
>(current_batch.size()),
290 pass.
id, particle_program_instanced_->native_handle(),
291 cam_view, cam_pos, texture);
292 stats_.drawn_particles_batches++;
296 current_batch.clear();
297 current_texture = particle_emitter.component->get_texture();
301 if(particle_emitter.component->is_enabled())
303 auto emitter_handle = particle_emitter.component->get_emitter_handle();
306 current_batch.push_back(emitter_handle);
312 if(!current_batch.empty() && current_texture.
is_valid())
314 auto texture = current_texture.
get()->native_handle();
315 stats_.drawn_particles +=
psRenderEmitterBatch(current_batch.data(),
static_cast<uint32_t
>(current_batch.size()),
316 pass.
id, particle_program_instanced_->native_handle(),
317 cam_view, cam_pos, texture);
318 stats_.drawn_particles_batches++;
322 particle_program_instanced_->end();
329 batching_stats.total_batches += stats.total_batches;
330 batching_stats.total_instances += stats.total_instances;
331 batching_stats.collection_time_ms += stats.collection_time_ms;
332 batching_stats.preparation_time_ms += stats.preparation_time_ms;
333 batching_stats.submission_time_ms += stats.submission_time_ms;
334 batching_stats.instance_buffer_memory_used += stats.instance_buffer_memory_used;
335 batching_stats.split_batches += stats.split_batches;
338 batching_stats.calculate_derived_stats();
std::shared_ptr< frame_buffer > ptr
auto fbo_get(const hpp::string_view &id) const -> const frame_buffer::ptr &
Storage for frustum planes / values and wraps up common functionality.
bool enabled
Whether ASSAO is enabled.
Manages assets, including loading, unloading, and storage.
Class representing a camera. Contains functionality for manipulating and updating a camera....
auto test_obb(const math::bbox &bounds, const math::transform &t) const -> bool
Tests if the specified OBB is within the frustum.
auto get_projection() const -> const math::transform &
Retrieves the current projection matrix.
auto get_view() const -> const math::transform &
Retrieves the current view matrix.
auto test_aabb(const math::bbox &bounds) const -> bool
Tests if the specified AABB is within the frustum.
auto get_position() const -> const math::vec3 &
Retrieves the current position of the camera.
bool enabled
Whether FXAA is enabled.
Class that contains core data for meshes.
Component that wraps particle system emitter functionality.
virtual auto init(rtti::context &ctx) -> bool
virtual auto gather_visible_models(scene &scn, const math::frustum *frustum, visibility_flags query, const layer_mask &render_mask) -> visibility_set_models_t
Gathers visible models from the scene based on the given query.
uint32_t visibility_flags
Type alias for visibility flags.
bool enabled
Whether SSR is enabled.
bool enabled
Whether tonemapping is enabled.
void discard(uint8_t _flags)
hpp::small_vector< entt::handle > visibility_set_models_t
uint32_t psRenderEmitterBatch(const EmitterHandle *_handles, uint32_t _count, uint8_t _view, bgfx::ProgramHandle _program, const float *_mtxView, const math::vec3 &_eye, bgfx::TextureHandle _texture)
#define APP_SCOPE_PERF(name)
Create a scoped performance timer that only accepts string literals.
Represents a handle to an asset, providing access and management functions.
auto is_valid() const -> bool
Checks if the handle is valid.
auto get(bool wait=true) const -> std::shared_ptr< T >
Gets the shared pointer to the asset.
void set_view_proj(const float *v, const float *p)
void bind(const frame_buffer *fb=nullptr) const
Statistics for batch collection and rendering performance.
Component that provides a layer mask for an entity.
std::function< void(assao_pass::run_params ¶ms)> fill_assao_params
std::function< void(ssr_pass::run_params ¶ms)> fill_ssr_params
std::function< void(tonemapping_pass::run_params ¶ms)> fill_hdr_params
std::function< void(fxaa_pass::run_params ¶ms)> fill_fxaa_params
Represents a scene in the ACE framework, managing entities and their relationships.
std::unique_ptr< entt::registry > registry
The registry that manages all entities in the scene.
bool isValid(SpriteHandle _handle)