2#include "glm/ext/scalar_integer.hpp"
41 if(!depth || (depth && depth->get_size() != viewport_size))
43 depth = std::make_shared<gfx::texture>(viewport_size.
width,
47 gfx::texture_format::D32F,
57 if(!hiz || (hiz && hiz->get_size() != viewport_size))
60 hiz = std::make_shared<gfx::texture>(viewport_size.
width,
64 gfx::texture_format::R32F,
66 BGFX_TEXTURE_COMPUTE_WRITE |
67 BGFX_SAMPLER_MIN_POINT |
68 BGFX_SAMPLER_MAG_POINT |
69 BGFX_SAMPLER_MIP_POINT |
70 BGFX_SAMPLER_U_CLAMP |
82 auto& depth = create_or_resize_d_buffer(rview, viewport_size, params);
85 if(!fbo || (fbo && fbo->get_size() != viewport_size))
87 auto format = params.
fill_hdr_params ? gfx::texture_format::RGBA16F : gfx::texture_format::RGBA8;
89 auto tex0 = std::make_shared<gfx::texture>(viewport_size.
width,
93 gfx::texture_format::RGBA8,
94 BGFX_TEXTURE_COMPUTE_WRITE | BGFX_TEXTURE_RT);
96 auto tex1 = std::make_shared<gfx::texture>(viewport_size.
width,
103 auto tex2 = std::make_shared<gfx::texture>(viewport_size.
width,
107 gfx::texture_format::RGBA8,
110 auto tex3 = std::make_shared<gfx::texture>(viewport_size.
width,
114 gfx::texture_format::RGBA8,
117 fbo = std::make_shared<gfx::frame_buffer>();
118 fbo->populate({tex0, tex1, tex2, tex3, depth});
128 auto& depth = create_or_resize_d_buffer(rview, viewport_size, params);
131 if(!fbo || (fbo && fbo->get_size() != viewport_size))
133 auto format = params.
fill_hdr_params ? gfx::texture_format::RGBA16F : gfx::texture_format::RGBA8;
135 auto tex = std::make_shared<gfx::texture>(viewport_size.
width,
142 fbo = std::make_shared<gfx::frame_buffer>();
143 fbo->populate({tex});
146 fbo_depth = std::make_shared<gfx::frame_buffer>();
147 fbo_depth->populate({tex, depth});
158 if(!fbo || (fbo && fbo->get_size() != viewport_size))
160 auto format = params.
fill_hdr_params ? gfx::texture_format::RGBA16F : gfx::texture_format::RGBA8;
162 auto tex = std::make_shared<gfx::texture>(viewport_size.
width,
167 BGFX_TEXTURE_RT | BGFX_TEXTURE_COMPUTE_WRITE);
169 fbo = std::make_shared<gfx::frame_buffer>();
170 fbo->populate({tex});
179 auto& depth = create_or_resize_d_buffer(rview, viewport_size, params);
182 tex = std::make_shared<gfx::texture>(viewport_size.
width,
186 gfx::texture_format::RGBA8,
187 BGFX_TEXTURE_COMPUTE_WRITE | BGFX_TEXTURE_RT);
191 if(!fbo || (fbo && fbo->get_size() != viewport_size))
193 fbo = std::make_shared<gfx::frame_buffer>();
194 fbo->populate({tex, depth});
199 if(!fbo || (fbo && fbo->get_size() != viewport_size))
201 fbo = std::make_shared<gfx::frame_buffer>();
202 fbo->populate({tex});
209 const std::vector<urange32_t>& lod_limits,
210 std::size_t total_lods,
211 float transition_time,
215 const camera& cam) ->
bool
226 float percent = math::clamp((
float(
rect.
height()) /
float(viewport.height)) * 100.0f, 0.0f, 100.0f);
229 for(
size_t i = 0; i < lod_limits.size(); ++i)
231 const auto&
range = lod_limits[i];
238 lod = math::clamp<std::size_t>(lod, 0, total_lods - 1);
264 auto light_world_bounds =
math::bbox::mul(light_bounds, light_transform);
265 for(
const auto& element : visibility_set)
269 const auto& model_world_bounds = model_comp_ref.get_world_bounds();
271 bool result = light_world_bounds.intersect(model_world_bounds);
281auto deferred::get_light_program(
const light& l)
const ->
const color_lighting&
283 return color_lighting_[uint8_t(l.type)][uint8_t(l.shadow_params.depth)][uint8_t(l.shadow_params.type)];
286auto deferred::get_light_program_no_shadows(
const light& l)
const ->
const color_lighting&
288 return color_lighting_no_shadow_[uint8_t(l.type)];
291void deferred::submit_pbr_material(geom_program& program,
const pbr_material& mat)
300 const auto& albedo = color_map ? color_map : mat.default_color_map();
301 const auto&
normal = normal_map ? normal_map : mat.default_normal_map();
302 const auto& roughness = roughness_map ? roughness_map : mat.default_color_map();
303 const auto& metalness = metalness_map ? metalness_map : mat.default_color_map();
304 const auto& ao = ao_map ? ao_map : mat.default_color_map();
305 const auto& emissive = emissive_map ? emissive_map : mat.default_color_map();
330 auto state = mat.get_render_states(
true,
true,
true);
340 [&](
auto e,
auto&& transform_comp,
auto&& reflection_probe_comp,
auto&& active)
342 if(reflection_probe_comp.already_generated())
349 const auto& world_transform = transform_comp.get_transform_global();
351 const auto& bounds = reflection_probe_comp.get_bounds();
357 const auto&
probe = reflection_probe_comp.get_probe();
364 for(std::uint32_t face = 0; face < 6; ++face)
366 if(reflection_probe_comp.already_generated(face))
375 auto& rview = reflection_probe_comp.get_render_view(face);
376 const auto& cubemap_fbo = reflection_probe_comp.get_cubemap_fbo(face);
391 params.vflags = vflags;
396 auto env_cube = reflection_probe_comp.get_cubemap();
397 auto env_cube_prefiltered = reflection_probe_comp.get_cubemap_prefiltered();
402 prefilter_params.
apply_prefilter = reflection_probe_comp.get_apply_prefilter();
404 for(std::uint32_t face = 0; face < 6; ++face)
406 const auto& cubemap_fbo = reflection_probe_comp.get_cubemap_fbo(face);
407 prefilter_params.
input_faces[face] = cubemap_fbo->get_texture();
427 bool queried =
false;
435 [&](
auto e,
auto&& transform_comp,
auto&& light_comp)
437 const auto&
light = light_comp.get_light();
441 bool camera_dependant = is_directional || has_render_mask;
444 auto&
generator = light_comp.get_shadowmap_generator();
446 generator.set_altitude_scale_factor(0.4f);
447 if(!camera_dependant &&
generator.already_updated())
454 auto world_transform = transform_comp.get_transform_global();
455 world_transform.reset_scale();
456 const auto& light_direction = world_transform.z_unit_axis();
465 const auto& bounds = light_comp.get_bounds_precise(light_direction);
482 bool should_rebuild = should_rebuild_shadows(dirty_models,
light, bounds, world_transform);
488 APP_SCOPE_PERF(
"Rendering/Shadow Generation Pass Per Light After Cull");
490 generator.generate_shadowmaps(dirty_models);
502 const auto& obuffer = create_or_resize_o_buffer(rview, viewport_size, params);
504 run_pipeline_impl(obuffer, scn,
camera, rview, dt, params, pipeline_steps::full, render_mask);
520 pass_params.
input = obuffer;
521 pass_params.
output = output;
552 if(apply_reflecitons)
563 create_or_resize_d_buffer(rview, viewport_size, params);
564 create_or_resize_g_buffer(rview, viewport_size, params);
565 create_or_resize_l_buffer(rview, viewport_size, params);
566 create_or_resize_r_buffer(rview, viewport_size, params);
579 if(apply_reflecitons)
619 const auto& gbuffer = rview.
fbo_get(
"GBUFFER");
624 pass.
bind(gbuffer.get());
627 batch_collector_.
clear();
629 for(
const auto& e : visibility_set)
634 const auto&
model = model_comp.get_model();
642 const auto transition_time = 0.0f;
650 if(!update_lod_data(lod_runtime_data,
660 const auto current_time = lod_runtime_data.current_time;
661 const auto current_lod_index = lod_runtime_data.current_lod_index;
662 const auto target_lod_index = lod_runtime_data.target_lod_index;
664 const auto params = math::vec3{0.0f, -1.0f, (transition_time - current_time) / transition_time};
666 const auto params_inv = math::vec3{1.0f, 1.0f, current_time / transition_time};
668 const auto& submesh_transforms = model_comp.get_submesh_transforms();
669 const auto& bone_transforms = model_comp.get_bone_transforms();
670 const auto& skinning_matrices = model_comp.get_skinning_transforms();
681 geom_program& prog = submit_params.skinned ? geom_program_skinned_ : geom_program_;
683 prog.program->begin();
690 geom_program& prog = submit_params.skinned ? geom_program_skinned_ : geom_program_;
697 geom_program& prog = submit_params.
skinned ? geom_program_skinned_ : geom_program_;
699 bool submitted = mat.submit(prog.program.get());
704 const auto& pbr =
static_cast<const pbr_material&
>(mat);
705 submit_pbr_material(prog, pbr);
713 geom_program& prog = submit_params.
skinned ? geom_program_skinned_ : geom_program_;
721 const bool is_skinned = !skinning_matrices.empty();
727 collect_model_for_batching(
model, world_transform, submesh_transforms, current_lod_index, params.x);
730 if(math::epsilonNotEqual(current_time, 0.0f, math::epsilon<float>()))
732 collect_model_for_batching(
model, world_transform, submesh_transforms, target_lod_index, params_inv.x);
744 if(math::epsilonNotEqual(current_time, 0.0f, math::epsilon<float>()))
748 geom_program& prog = submit_params.
skinned ? geom_program_skinned_ : geom_program_;
766 submit_batched_geometry(pass,
camera);
771void deferred::collect_model_for_batching(
const model& model_asset,
772 const math::mat4& world_transform,
778 const auto& lods = model_asset.
get_lods();
779 if (lod_index >= lods.size())
784 const auto& mesh_asset = lods[lod_index];
791 const auto submesh_count = mesh_asset.get()->get_data_groups_count();
794 for (uint32_t submesh_index = 0; submesh_index < submesh_count; ++submesh_index)
804 const math::mat4* transform_ptr =
nullptr;
805 if (submesh_index < submesh_transforms.
transforms.size())
808 transform_ptr = &submesh_transforms.
transforms[submesh_index];
813 transform_ptr = &world_transform;
817 batch_key
key(mesh_asset.get(), material_ptr, lod_index, submesh_index);
824 batch_instance instance(transform_ptr);
825 instance.lod_params.x = lod_param;
832void deferred::submit_batched_geometry(
gfx::render_pass& pass,
const camera& camera)
837 submit_context context;
838 context.view_id = pass.
id;
839 context.camera_position = camera.get_position();
840 context.enable_distance_sorting =
false;
841 context.max_instances_per_batch = 1024;
842 context.enable_profiling =
true;
847 if (prepared_batches.empty())
853 const auto camera_pos = camera.get_position();
854 const auto clip_planes = math::vec2(camera.get_near_clip(), camera.get_far_clip());
856 geom_program_instanced_.program->begin();
858 gfx::set_uniform(geom_program_instanced_.u_camera_clip_planes, clip_planes);
861 for (
const auto* batch : prepared_batches)
863 if (!batch->is_valid() || batch->instances.empty())
871 const auto& mesh_ptr = batch->key.mesh_ptr;
872 const auto& material_ptr = batch->key.material_ptr;
873 const auto lod_index = batch->key.lod_index;
874 const auto submesh_index = batch->key.submesh_index;
876 if (!mesh_ptr || !material_ptr)
881 const auto submesh = mesh_ptr->get_submesh(submesh_index);
888 const auto instance_count =
static_cast<uint32_t
>(batch->instances.size());
892 bgfx::InstanceDataBuffer instance_buffer;
893 bgfx::allocInstanceDataBuffer(&instance_buffer, instance_count, instance_data_size);
894 if (!instance_buffer.data)
902 mesh_ptr->bind_render_buffers_for_submesh(submesh);
905 auto* buffer_data =
reinterpret_cast<instance_vertex_data*
>(instance_buffer.data);
906 for (
size_t i = 0;
i < batch->instances.size(); ++
i)
908 buffer_data[
i] = instance_vertex_data(batch->instances[i]);
912 bgfx::setInstanceDataBuffer(&instance_buffer);
915 bool material_submitted = material_ptr->submit(geom_program_instanced_.program.get());
916 if (!material_submitted)
918 if (material_ptr->is<pbr_material>())
920 const auto& pbr =
static_cast<const pbr_material&
>(*material_ptr);
921 submit_pbr_material(geom_program_instanced_, pbr);
926 const auto lod_params = math::vec3{0.0f, -1.0f, 1.0f};
930 gfx::submit(pass.
id, geom_program_instanced_.program->native_handle(), 0,
false);
933 geom_program_instanced_.program->end();
936 const auto& batch_stats = batch_collector_.
get_stats();
940 batch_collector_.
clear();
955 const auto& gbuffer = rview.
fbo_get(
"GBUFFER");
957 auto color_ao = gbuffer->get_texture(0);
958 auto normal = gbuffer->get_texture(1);
959 auto depth = gbuffer->get_texture(4);
962 params.
depth = depth.get();
985 const auto& gbuffer = rview.fbo_get(
"GBUFFER");
986 const auto& rbuffer = rview.fbo_safe_get(
"RBUFFER");
987 const auto& lbuffer = rview.fbo_get(
"LBUFFER");
989 const auto buffer_size = lbuffer->get_size();
992 pass.
bind(lbuffer.get());
994 pass.
clear(BGFX_CLEAR_COLOR, 0, 0.0f, 0);
997 [&](
auto e,
auto&& transform_comp_ref,
auto&& light_comp_ref,
auto&& active)
999 const auto&
light = light_comp_ref.get_light();
1000 const auto&
generator = light_comp_ref.get_shadowmap_generator();
1001 auto world_transform = transform_comp_ref.get_transform_global();
1002 world_transform.reset_scale();
1003 const auto& light_position = world_transform.get_position();
1004 const auto& light_direction = world_transform.z_unit_axis();
1006 const auto& bounds = light_comp_ref.get_bounds_precise(light_direction);
1014 .compute_projected_sphere_rect(
rect, light_position, light_direction, camera_pos, view, proj) == 0)
1022 stats_.drawn_lights++;
1023 stats_.drawn_lights_casting_shadows += uint32_t(has_shadows);
1025 const auto& lprogram = has_shadows ? get_light_program(
light) : get_light_program_no_shadows(
light);
1027 lprogram.program->begin();
1068 for(; i < gbuffer->get_attachment_count(); ++i)
1083 gfx::set_state(topology | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ADD);
1087 lprogram.program->end();
1104 const auto& gbuffer = rview.
fbo_get(
"GBUFFER");
1105 const auto& rbuffer = rview.
fbo_get(
"RBUFFER");
1107 const auto buffer_size = rbuffer->get_size();
1110 pass.
bind(rbuffer.get());
1112 pass.
clear(BGFX_CLEAR_COLOR, 0, 0.0f, 0);
1113 std::vector<entt::entity> sorted_probes;
1117 [&](
auto e,
auto&& transform_comp_ref,
auto&& probe_comp_ref,
auto&& active)
1119 sorted_probes.emplace_back(e);
1123 std::sort(std::begin(sorted_probes),
1124 std::end(sorted_probes),
1125 [&](
const auto& lhs,
const auto& rhs)
1128 const auto& lhs_probe = lhs_comp.
get_probe();
1131 const auto& rhs_probe = rhs_comp.
get_probe();
1134 if(lhs_probe.method != rhs_probe.method)
1136 return lhs_probe.method < rhs_probe.method;
1140 return lhs_probe.get_max_range() > rhs_probe.get_max_range();
1144 for(
const auto& e : sorted_probes)
1149 const auto&
probe = probe_comp_ref.get_probe();
1151 const auto& probe_position = world_transform.get_position();
1152 const auto& probe_scale = world_transform.get_scale();
1155 if(probe_comp_ref.compute_projected_sphere_rect(
rect, probe_position, probe_scale, camera_pos, view, proj) == 0)
1160 const auto& cubemap = probe_comp_ref.get_cubemap_prefiltered();
1162 ref_probe_program* ref_probe_program =
nullptr;
1163 float influence_radius = 0.0f;
1166 ref_probe_program = &sphere_ref_probe_program_;
1168 math::max(probe_scale.x, math::max(probe_scale.y, probe_scale.z)) *
probe.sphere_data.range;
1174 t.scale(
probe.box_data.extents);
1176 float data2[4] = {
probe.box_data.extents.x,
1177 probe.box_data.extents.y,
1178 probe.box_data.extents.z,
1179 probe.box_data.transition_distance};
1181 ref_probe_program = &box_ref_probe_program_;
1186 influence_radius = math::length(t.get_scale() +
probe.box_data.transition_distance);
1189 if(ref_probe_program)
1191 float mips = cubemap ? float(cubemap->info.numMips) : 1.0f;
1199 float data1[4] = {mips,
probe.intensity, 0.0f, 0.0f};
1204 for(
size_t i = 0; i < gbuffer->get_attachment_count(); ++i)
1213 gfx::set_state(topology | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_BLEND_ALPHA);
1215 ref_probe_program->program->begin();
1216 gfx::submit(pass.
id, ref_probe_program->program->native_handle());
1218 ref_probe_program->program->end();
1237 bool found_sun =
false;
1241 [&](
auto e,
auto&& transform_comp_ref,
auto&& light_comp_ref,
auto&& active)
1243 auto entity = scn.create_handle(e);
1247 APPLOG_WARNING(
"[{}] More than one entity with this component. Others are ignored.",
"Skylight");
1250 const auto& cubemap = light_comp_ref.get_cubemap();
1251 auto cubemap_texture = cubemap.get();
1254 if(cubemap_texture->info.cubeMap)
1256 params_skybox.
cubemap = cubemap;
1260 mode = light_comp_ref.get_mode();
1262 if(
auto light_comp =
entity.template try_get<light_component>())
1264 const auto&
light = light_comp->get_light();
1268 const auto& world_transform = transform_comp_ref.get_transform_global();
1270 params.
turbidity = light_comp_ref.get_turbidity();
1273 params_perez.
turbidity = light_comp_ref.get_turbidity();
1287 auto lbuffer_depth = rview.fbo_get(
"LBUFFER_DEPTH");
1292 atmospheric_pass_perez_.run(lbuffer_depth, c, rview, dt, params_perez);
1295 atmospheric_pass_.run(lbuffer_depth, c, rview, dt, params);
1298 atmospheric_pass_skybox_.run(lbuffer_depth, c, rview, dt, params_skybox);
1310 if(!rparams.fill_ssr_params)
1317 ssr_params.
output = rview.fbo_get(
"RBUFFER");
1318 ssr_params.
g_buffer = rview.fbo_get(
"GBUFFER");
1320 ssr_params.
previous_frame = rview.fbo_get(
"LBUFFER")->get_texture();
1324 if(rparams.fill_ssr_params)
1326 rparams.fill_ssr_params(ssr_params);
1333 ssr_params.
hiz_buffer = rview.tex_get(
"HIZBUFFER");
1339 return ssr_pass_.run(rview, ssr_params);
1347 if(!rparams.fill_fxaa_params)
1358 rparams.fill_fxaa_params(params);
1360 return fxaa_pass_.run(rview, params);
1368 if(!rparams.fill_hdr_params)
1377 if(!rparams.fill_fxaa_params)
1382 rparams.fill_hdr_params(params);
1384 return tonemapping_pass_.run(rview, params);
1393 const auto& gbuffer = rview.
fbo_get(
"GBUFFER");
1398 pass.
bind(output.get());
1402 const auto output_size = output->get_size();
1404 debug_visualization_program_.program->begin();
1406 float u_params[4] = {float(debug_pass_), 0.0f, 0.0f, 0.0f};
1411 for(; i < gbuffer->get_attachment_count(); ++i)
1413 gfx::set_texture(debug_visualization_program_.s_tex[i], i, gbuffer->get_texture(i));
1420 gfx::set_state(topology | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
1421 gfx::submit(pass.
id, debug_visualization_program_.program->native_handle());
1423 debug_visualization_program_.program->end();
1432 auto& gbuffer = rview.fbo_get(
"GBUFFER");
1440 params.
output_hiz = rview.tex_get(
"HIZBUFFER");
1443 hiz_pass_.run(rview, params);
1461 auto load_program = [&](
const std::string& vs,
const std::string&
fs)
1463 auto vs_shader = am.get_asset<
gfx::shader>(
"engine:/data/shaders/" + vs +
".sc");
1464 auto fs_shadfer = am.get_asset<
gfx::shader>(
"engine:/data/shaders/" +
fs +
".sc");
1466 return std::make_unique<gpu_program>(vs_shader, fs_shadfer);
1469 geom_program_.program = load_program(
"vs_deferred_geom",
"fs_deferred_geom");
1470 geom_program_.cache_uniforms();
1472 geom_program_skinned_.program = load_program(
"vs_deferred_geom_skinned",
"fs_deferred_geom");
1473 geom_program_skinned_.cache_uniforms();
1475 geom_program_instanced_.program = load_program(
"vs_deferred_geom_instanced",
"fs_deferred_geom");
1476 geom_program_instanced_.cache_uniforms();
1478 sphere_ref_probe_program_.program = load_program(
"vs_clip_quad_ex",
"reflection_probe/fs_sphere_reflection_probe");
1479 sphere_ref_probe_program_.cache_uniforms();
1481 box_ref_probe_program_.program = load_program(
"vs_clip_quad_ex",
"reflection_probe/fs_box_reflection_probe");
1482 box_ref_probe_program_.cache_uniforms();
1484 debug_visualization_program_.program = load_program(
"vs_clip_quad",
"gbuffer/fs_gbuffer_visualize");
1485 debug_visualization_program_.cache_uniforms();
1490 color_lighting_no_shadow_[uint8_t(
light_type::spot)].program = load_program(
"vs_clip_quad",
"fs_deferred_spot_light");
1503 color_lighting_no_shadow_[uint8_t(
light_type::point)].program = load_program(
"vs_clip_quad",
"fs_deferred_point_light");
1516 color_lighting_no_shadow_[uint8_t(
light_type::directional)].program = load_program(
"vs_clip_quad",
"fs_deferred_directional_light");
1530 for(
auto& byLightType : color_lighting_no_shadow_)
1532 if(byLightType.program)
1534 byLightType.cache_uniforms();
1537 for(
auto& byLightType : color_lighting_)
1539 for(
auto& byDepthType : byLightType)
1541 for(
auto& bySmImpl : byDepthType)
1543 if(bySmImpl.program)
1545 bySmImpl.cache_uniforms();
1551 ibl_brdf_lut_ = am.get_asset<
gfx::texture>(
"engine:/data/textures/ibl_brdf_lut.png");
std::shared_ptr< texture > ptr
auto fbo_safe_get(const hpp::string_view &id) const -> const frame_buffer::ptr &
auto fbo_get_or_emplace(const hpp::string_view &id) -> frame_buffer::ptr &
auto fbo_get(const hpp::string_view &id) const -> const frame_buffer::ptr &
auto tex_get_or_emplace(const hpp::string_view &id) -> texture::ptr &
void run(const camera &camera, gfx::render_view &rview, const run_params ¶ms)
Manages assets, including loading, unloading, and storage.
void clear()
Clear all collected data and reset for next frame.
auto get_stats() const -> const batch_stats &
Get current statistics.
void prepare_batches(const submit_context &context)
Prepare batches for rendering (sort, split, optimize)
static auto is_static_mesh_batching_enabled() -> bool
Check if static mesh batching is enabled globally.
void collect_renderable(const batch_key &key, const batch_instance &instance)
Collect a renderable object for batching.
auto get_prepared_batches() const -> const batch_list_t &
Get prepared batches for rendering.
auto run(const run_params ¶ms) -> gfx::frame_buffer::ptr
Executes the blit: copies params.input → params.output. Returns the actual output framebuffer.
Class representing a camera. Contains functionality for manipulating and updating a camera....
auto get_far_clip() const -> float
Retrieves the distance from the camera to the far clip plane.
auto test_obb(const math::bbox &bounds, const math::transform &t) const -> bool
Tests if the specified OBB is within the frustum.
auto get_viewport_size() const -> const usize32_t &
Retrieves the size of the viewport.
auto get_projection() const -> const math::transform &
Retrieves the current projection matrix.
static auto get_face_camera(std::uint32_t face, const math::transform &transform) -> camera
Retrieves a camera for one of six cube faces.
auto get_view() const -> const math::transform &
Retrieves the current view matrix.
void set_far_clip(float distance)
Sets the far plane distance.
auto get_position() const -> const math::vec3 &
Retrieves the current position of the camera.
void set_viewport_size(const usize32_t &viewportSize)
Sets the size of the viewport.
auto get_frustum() const -> const math::frustum &
Retrieves the current camera object frustum.
auto get_near_clip() const -> float
Retrieves the distance from the camera to the near clip plane.
Class that contains core light data, used for rendering and other purposes.
Base class for materials used in rendering.
Main class representing a 3D mesh with support for different LODs, submeshes, and skinning.
auto calculate_screen_rect(const math::transform &world, const camera &cam) const -> irect32_t
Calculates the screen rectangle of the mesh based on its world transform and the camera.
Class that contains core data for meshes.
Structure describing a LOD group (set of meshes), LOD transitions, and their materials.
auto get_lod(uint32_t lod) const -> asset_handle< mesh >
Gets the LOD (Level of Detail) mesh for the specified level.
auto is_valid() const -> bool
Checks if the model is valid.
auto get_lod_limits() const -> const std::vector< urange32_t > &
Gets the LOD limits.
void submit(const math::mat4 &world_transform, const pose_mat4 &submesh_transforms, const pose_mat4 &bone_transforms, const std::vector< pose_mat4 > &skinning_matrices, unsigned int lod, const submit_callbacks &callbacks) const
Submits the model for rendering.
auto get_material_instance(uint32_t index) const -> material::sptr
auto get_lods() const -> const std::vector< asset_handle< mesh > > &
Gets all the LOD meshes.
Class for physically-based rendering (PBR) materials.
auto get_surface_data2() const -> math::vec4
Gets additional surface data for the material.
auto get_dither_threshold() const -> const math::vec2 &
Gets the dither threshold of the material.
auto get_emissive_map() const -> const asset_handle< gfx::texture > &
Gets the emissive map of the material.
auto get_subsurface_color() const -> const math::color &
Gets the subsurface color of the material.
auto get_color_map() const -> const asset_handle< gfx::texture > &
Gets the color map of the material.
auto get_surface_data() const -> const math::vec4 &
Gets the surface data of the material.
auto get_roughness_map() const -> const asset_handle< gfx::texture > &
Gets the roughness map of the material.
auto get_metalness_map() const -> const asset_handle< gfx::texture > &
Gets the metalness map of the material.
auto get_tiling() const -> const math::vec2 &
Gets the tiling factor of the material.
auto get_normal_map() const -> const asset_handle< gfx::texture > &
Gets the normal map of the material.
auto get_base_color() const -> const math::color &
Gets the base color of the material.
auto get_emissive_color() const -> const math::color &
Gets the emissive color of the material.
auto get_ao_map() const -> const asset_handle< gfx::texture > &
Gets the ambient occlusion map of the material.
auto run(const run_params ¶ms) -> gfx::texture::ptr
Execute prefilter. Returns the filtered cubemap (output_cube or created internally).
Class that contains core reflection probe data, used for rendering and other purposes.
auto get_probe() const -> const reflection_probe &
Gets the reflection probe object.
auto deinit(rtti::context &ctx) -> bool
void set_debug_pass(int pass) override
void build_shadows(scene &scn, const camera &camera, visibility_flags query=visibility_query::not_specified, layer_mask render_mask=layer_mask{layer_reserved::everything_layer})
void run_assao_pass(const visibility_set_models_t &visibility_set, const camera &camera, gfx::render_view &rview, delta_t dt, const run_params &rparams)
void run_reflection_probe_pass(scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt)
auto run_lighting_pass(scene &scn, const camera &camera, gfx::render_view &rview, bool apply_shadows, delta_t dt) -> gfx::frame_buffer::ptr
void run_debug_visualization_pass(const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output)
auto run_ssr_pass(const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output, const run_params &rparams) -> gfx::frame_buffer::ptr
void build_reflections(scene &scn, const camera &camera, delta_t dt)
auto run_fxaa_pass(gfx::render_view &rview, const gfx::frame_buffer::ptr &input, const gfx::frame_buffer::ptr &output, const run_params &rparams) -> gfx::frame_buffer::ptr
void run_g_buffer_pass(const visibility_set_models_t &visibility_set, const camera &camera, gfx::render_view &rview, delta_t dt)
auto run_atmospherics_pass(gfx::frame_buffer::ptr input, scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt) -> gfx::frame_buffer::ptr
auto run_tonemapping_pass(gfx::render_view &rview, const gfx::frame_buffer::ptr &input, const gfx::frame_buffer::ptr &output, const run_params &rparams) -> gfx::frame_buffer::ptr
auto run_hiz_pass(const camera &camera, gfx::render_view &rview, delta_t dt) -> gfx::texture::ptr
auto init(rtti::context &ctx) -> bool override
auto run_pipeline(scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt, const run_params ¶ms, layer_mask render_mask=layer_mask{layer_reserved::everything_layer}) -> gfx::frame_buffer::ptr override
Renders the entire scene from the camera's perspective.
void run_pipeline_impl(const gfx::frame_buffer::ptr &output, scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt, const run_params ¶ms, pipeline_flags pflags, layer_mask render_mask=layer_mask{layer_reserved::everything_layer})
virtual void particle_pass(scene &scn, const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output)
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.
@ not_specified
No specific visibility query.
@ is_dirty
Query for dirty entities.
@ is_reflection_caster
Query for reflection casting entities.
@ is_shadow_caster
Query for shadow casting entities.
prefilter_pass prefilter_pass_
virtual void ui_pass(scene &scn, const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output)
uint32_t visibility_flags
Type alias for visibility flags.
virtual auto create_run_params(entt::handle camera_ent) const -> rendering::pipeline::run_params
Class that contains sky light data.
sky_mode
Enumeration for sky modes.
@ standard
Standard sky mode.
size< std::uint32_t > usize32_t
std::chrono::duration< float > delta_t
#define APPLOG_WARNING(...)
void submit(view_id _id, program_handle _handle, int32_t _depth, bool _preserveState)
uint16_t set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height)
void set_state(uint64_t _state, uint32_t _rgba)
void discard(uint8_t _flags)
void set_uniform(uniform_handle _handle, const void *_value, uint16_t _num)
uint32_t get_render_frame()
auto clip_quad(float depth, float width, float height) -> uint64_t
void set_texture(uint8_t _stage, uniform_handle _sampler, texture_handle _handle, uint32_t _flags)
auto inverse(transform_t< T, Q > const &t) noexcept -> transform_t< T, Q >
hpp::small_vector< entt::handle > visibility_set_models_t
@ sphere
Sphere type reflection probe.
@ box
Box type reflection probe.
@ environment
Environment reflection method.
#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.
void set_view_proj(const float *v, const float *p)
void clear(uint16_t _flags, uint32_t _rgba=0x000000ff, float _depth=1.0f, uint8_t _stencil=0) const
static void push_scope(const char *name)
void bind(const frame_buffer *fb=nullptr) const
Storage for box vector values and wraps up common functionality.
bbox & mul(const transform &t)
Transforms an axis aligned bounding box by the specified matrix.
bool contains(const T &val) const
math::vec3 light_direction
math::vec3 light_direction
asset_handle< gfx::texture > cubemap
gfx::frame_buffer::ptr input
Source framebuffer (must have a color texture).
gfx::frame_buffer::ptr output
Optional destination framebuffer. If null, will be created to match input.
static auto context() -> rtti::context &
gfx::frame_buffer::ptr output
gfx::frame_buffer::ptr input
gfx::texture::ptr depth_buffer
Source depth buffer.
const camera * cam
Camera for near/far plane information.
gfx::texture::ptr output_hiz
Output Hi-Z texture (must be R32F or R16F format with mips)
static auto packed_size() -> size_t
float range
The range of the point light.
float exponent_falloff
The exponent falloff for the point light.
float get_range() const
Gets the range of the spot light.
float get_outer_angle() const
Gets the outer angle of the spot light.
float get_inner_angle() const
Gets the inner angle of the spot light.
Struct representing a light.
bool casts_shadows
Whether the light casts shadows.
float intensity
The intensity of the light.
light_type type
The type of the light.
math::color color
The color of the light.
point point_data
Data specific to point lights.
float ambient_intensity
The ambient intensity of the light.
spot spot_data
Data specific to spot lights.
Parameters for the submit callbacks.
bool skinned
Indicates if the model is skinned.
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.
std::vector< math::mat4 > transforms
Vector of bone transforms.
std::array< gfx::texture::ptr, 6 > input_faces
gfx::texture::ptr output_cube_prefiltered
Optional destination cubemap (will be created if null).
gfx::texture::ptr output_cube
Optional destination cubemap (will be created if null).
bool apply_prefilter
If false, copies mips from input to output.
Contains level of detail (LOD) data for an entity.
float current_time
Current time for LOD transition.
std::uint32_t target_lod_index
Target LOD index.
std::uint32_t current_lod_index
Current LOD index.
std::function< void(assao_pass::run_params ¶ms)> fill_assao_params
std::function< void(tonemapping_pass::run_params ¶ms)> fill_hdr_params
void add_batch_stats(const batch_stats &stats)
Add batch statistics to the pipeline stats.
uint32_t drawn_skinned_models
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.
auto create_handle(entt::entity e) -> entt::handle
Creates an entity in the scene.
bool enable_cone_tracing
Enable cone tracing for glossy reflections.
gfx::frame_buffer::ptr output
Optional output buffer.
gfx::texture::ptr previous_frame
Previous frame color for reflection sampling.
gfx::frame_buffer::ptr g_buffer
G-buffer containing normals.
gfx::texture::ptr hiz_buffer
Hi-Z buffer texture.
fidelityfx_ssr_settings fidelityfx
FidelityFX SSR settings.
gfx::frame_buffer::ptr input
gfx::frame_buffer::ptr output