Loading...
Searching...
No Matches
Renderer.cpp
Go to the documentation of this file.
1//
2// Simplified Renderer.cpp
3//
4#include "Renderer.h"
5#include "GL/glew.h"
6#include <algorithm>
7
8
9#include "hellfire/core/Application.h"
10#include "hellfire/core/Time.h"
11#include "hellfire/ecs/CameraComponent.h"
12#include "hellfire/ecs/InstancedRenderableComponent.h"
13#include "hellfire/ecs/LightComponent.h"
14#include "hellfire/ecs/components/MeshComponent.h"
15#include "hellfire/graphics/renderer/SkyboxRenderer.h"
16#include "hellfire/scene/Scene.h"
17
18namespace hellfire {
22 context_ = std::make_unique<OGLRendererContext>();
23 context_->shader_handle = 0;
24 }
25
26 void Renderer::init() {
27 // Enable debugging for OpenGL
28 glEnable(GL_DEBUG_OUTPUT);
29 glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); // Makes errors appear immediately
30 glDebugMessageCallback([](GLenum source, GLenum type, GLuint id,
31 GLenum severity, GLsizei length,
32 const GLchar *message, const void *userParam) {
33 if (type == GL_DEBUG_TYPE_ERROR) {
34 std::cerr << "GL ERROR: " << message << std::endl;
35 __debugbreak();
36 }
37 }, nullptr);
38
39
40 // Setup shadow pass shader
41 shadow_material_ = MaterialBuilder::create_custom("Shadow Material", "assets/shaders/shadow.vert",
42 "assets/shaders/shadow.frag");
43
45 }
46
47 void Renderer::render(Scene &scene, const Entity *camera_override = nullptr) {
48 const Entity *camera_entity = camera_override;
49 if (!camera_entity) {
50 const EntityID camera_id = scene.get_default_camera_entity_id();
51 camera_entity = scene.get_entity(camera_id);
52 }
53
54 if (!camera_entity) {
55 std::cerr << "No active camera in scene!" << std::endl;
56 return;
57 }
58
59 const auto camera_comp = camera_entity->get_component<CameraComponent>();
60
61 if (!camera_comp) {
62 std::cerr << "Camera entity missing CameraComponent" << std::endl;
63 }
64
65 render_frame(scene, *camera_comp);
66 }
67
69 glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
70 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
71 }
72
74 opaque_objects_.clear();
75 transparent_objects_.clear();
76 opaque_instanced_objects_.clear();
77 transparent_instanced_objects_.clear();
78 }
79
82
83 glEnable(GL_DEPTH_TEST);
84 glDepthMask(GL_TRUE);
85 glDepthFunc(GL_LESS);
86
88 }
89
91 glFlush();
92 }
93
94 void Renderer::store_lights_in_context(const std::vector<Entity *> &light_entities, CameraComponent &camera) {
95 if (!context_) return;
96
97 // Separate lights by type
98 std::vector<Entity *> directional_lights;
99 std::vector<Entity *> point_lights;
100
101 for (Entity *entity: light_entities) {
102 const auto *light = entity->get_component<LightComponent>();
103 if (!light) continue;
104
105 // Sort lights into their respective vectors
106 switch (light->get_light_type()) {
107 case LightComponent::LightType::DIRECTIONAL:
108 if (directional_lights.size() < 4) {
109 directional_lights.push_back(entity);
110 }
111 break;
112 case LightComponent::LightType::POINT:
113 if (point_lights.size() < 8) {
114 point_lights.push_back(entity);
115 }
116 break;
117 case LightComponent::LightType::SPOT:
118 // TODO: Handle spot lights
119 break;
120 }
121 }
122
123 // Store light counts
124 context_->num_directional_lights = static_cast<int>(directional_lights.size());
125 context_->num_point_lights = static_cast<int>(point_lights.size());
126
127 // Store light entities
128 for (int i = 0; i < context_->num_directional_lights; i++) {
129 context_->directional_light_entities[i] = directional_lights[i];
130 }
131
132 for (int i = 0; i < context_->num_point_lights; i++) {
133 context_->point_light_entities[i] = point_lights[i];
134 }
135
136 // Store camera component
137 context_->camera_component = &camera;
138 }
139
140 void Renderer::collect_geometry_from_scene(Scene &scene, const glm::vec3 camera_pos) {
141 for (const EntityID root_id: scene.get_root_entities()) {
142 collect_render_commands_recursive(root_id, camera_pos);
143 }
144 }
145
146 void Renderer::collect_render_commands_recursive(EntityID entity_id, const glm::vec3 &camera_pos) {
147 const Entity *entity = scene_->get_entity(entity_id);
148 if (!entity) return;
149
150 // Check for renderable + mesh components
151 const auto *renderable = entity->get_component<RenderableComponent>();
152 const auto *mesh_comp = entity->get_component<MeshComponent>();
153 const auto *transform = entity->get_component<TransformComponent>();
154
155 // Need all three to render
156 if (renderable && mesh_comp && transform) {
157 const auto mesh = mesh_comp->get_mesh();
158 const auto material = renderable->get_material();
159
160 if (mesh && material) {
161 const glm::vec3 object_pos = transform->get_world_position();
162 const float distance = glm::length(camera_pos - object_pos);
163 const bool is_transparent = material->is_transparent();
164
165 const RenderCommand cmd = {entity_id, mesh, material, distance, is_transparent};
166
167 if (is_transparent) {
168 transparent_objects_.push_back(cmd);
169 } else {
170 opaque_objects_.push_back(cmd);
171 }
172 }
173 }
174
175 // If the entity has an Instancing component setup the render commands
176 if (auto *instanced = entity->get_component<InstancedRenderableComponent>()) {
177 if (transform && instanced->has_mesh() && instanced->get_instance_count() > 0) {
178 if (const auto material = instanced->get_material()) {
179 const glm::vec3 object_pos = transform->get_world_position();
180 const float distance = glm::length(camera_pos - object_pos);
181 const bool is_transparent = material->is_transparent();
182
183 const InstancedRenderCommand cmd = {entity_id, instanced, material, distance, is_transparent};
184
185 if (is_transparent) {
186 transparent_instanced_objects_.push_back(cmd);
187 } else {
188 opaque_instanced_objects_.push_back(cmd);
189 }
190 }
191 }
192 }
193
194 // Recurse through children using scene hierarchy
195 for (const EntityID child_id: scene_->get_children(entity_id)) {
196 collect_render_commands_recursive(child_id, camera_pos);
197 }
198 }
199
200 void Renderer::ensure_shadow_map(Entity *light_entity, const LightComponent &light) {
201 if (!shadow_maps_.contains(light_entity)) {
202 auto shadow_map = std::make_unique<Framebuffer>();
204 settings.width = 4096;
205 settings.height = 4096;
206
207 settings.min_filter = GL_NEAREST;
208 settings.mag_filter = GL_NEAREST;
209 settings.wrap_s = GL_CLAMP_TO_BORDER;
210 settings.wrap_t = GL_CLAMP_TO_BORDER;
211 shadow_map->attach_depth_texture(settings);
212
213 glBindTexture(GL_TEXTURE_2D, shadow_map->get_depth_attachment());
214 const float border_color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
215 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color);
216 glBindTexture(GL_TEXTURE_2D, 0);
217 shadow_maps_[light_entity] = {std::move(shadow_map), glm::mat4(1.0f)};
218 }
219 }
220
221 void Renderer::draw_render_command(const RenderCommand &cmd, const glm::mat4 &view, const glm::mat4 &projection) {
222 const Entity *entity = scene_->get_entity(cmd.entity_id);
223 if (!entity) return;
224
225 const auto *transform = entity->get_component<TransformComponent>();
226 if (!transform) return;
227
228 Shader &shader = get_shader_for_material(cmd.material);
229 shader.use();
230
231 // Upload lights
232 if (context_) {
233 RenderingUtils::upload_lights_to_shader(shader, *context_);
234
235 // Bind shadow maps for directional lights
236 for (int i = 0; i < context_->num_directional_lights; i++) {
237 Entity* light_entity = context_->directional_light_entities[i];
238
239 if (shadow_maps_.contains(light_entity)) {
240 auto& shadow_data = shadow_maps_[light_entity];
241
242 // Bind depth texture to texture unit
243 const int texture_unit = 10 + i; // Start at unit 10 to avoid conflicts
244 glActiveTexture(GL_TEXTURE0 + texture_unit);
245 glBindTexture(GL_TEXTURE_2D, shadow_data.framebuffer->get_depth_attachment());
246
247 // Set shader uniforms
248 shader.set_int("uShadowMap[" + std::to_string(i) + "]", texture_unit);
249 shader.set_mat4("uLightSpaceMatrix[" + std::to_string(i) + "]", shadow_data.light_view_proj);
250 shader.set_float("uShadowBias", shadow_settings_.bias);
251 }
252 }
253 }
254
255 shader.set_vec3("uAmbientLight", scene_->environment()->get_ambient_light());
256
257 shader.set_uint("uObjectID", cmd.entity_id);
258
259 // Upload default uniforms
260 RenderingUtils::set_standard_uniforms(shader, transform->get_world_matrix(), view, projection);
261
262 // Bind material and draw mesh
263 cmd.material->bind();
264 cmd.mesh->draw();
265 cmd.material->unbind();
266 }
267
268 void Renderer::draw_instanced_command(const InstancedRenderCommand &cmd, const glm::mat4 &view,
269 const glm::mat4 &projection) {
270 if (const Entity *entity = scene_->get_entity(cmd.entity_id); !entity) return;
271
272 Shader &shader = get_shader_for_material(cmd.material);
273 shader.use();
274
275 // Upload light data as uniforms to shader
276 if (context_) {
277 RenderingUtils::upload_lights_to_shader(shader, *context_);
278 }
279
280 // Upload the standard uniform data to the shader (Model, View, Projection, Time)
281 RenderingUtils::set_standard_uniforms(shader, glm::mat4(1.0f), view, projection, Time::current_time);
282
283 // Prepare instanced data
285
286 // Bind material and draw
287 cmd.material->bind();
288
289 const auto mesh = cmd.instanced_renderable->get_mesh();
290 if (mesh) {
291 mesh->bind();
293 mesh->draw_instanced(cmd.instanced_renderable->get_instance_count());
294 mesh->unbind();
295 }
296
297 cmd.material->unbind();
298 }
299
300 void Renderer::execute_skybox_pass(Scene *scene, const glm::mat4 &view, const glm::mat4 &projection,
301 CameraComponent *camera_comp) const {
302 if (!scene || !scene->environment()->has_skybox()) return;
303
304 glDisable(GL_CULL_FACE);
305
306 if (camera_comp) {
308 }
309 }
310
311
313 const std::vector<EntityID> light_entity_ids = scene.find_entities_with_component<LightComponent>();
314 std::vector<Entity *> light_entities;
315 for (const EntityID id: light_entity_ids) {
316 if (Entity *e = scene.get_entity(id)) {
317 light_entities.push_back(e);
318 }
319 }
320 store_lights_in_context(light_entities, camera);
321 }
322
325 scene_ = &scene;
326
327
328 // Gather lights and geometry
330 collect_geometry_from_scene(scene, camera.get_owner().transform()->get_position());
331
332 // Execute rendering passes
333 const glm::mat4 view = camera.get_view_matrix();
334 const glm::mat4 projection = camera.get_projection_matrix();
335
336 execute_geometry_pass(view, projection);
337 execute_skybox_pass(&scene, view, projection, &camera);
338 execute_transparency_pass(view, projection);
339 }
340
341
342
344 // Gather all lights that cast shadows
345 const std::vector<EntityID> light_entity_ids = scene.find_entities_with_component<LightComponent>();
346
347 std::vector<Entity*> shadow_casting_lights;
348 for (const EntityID id : light_entity_ids) {
349 Entity* entity = scene.get_entity(id);
350 if (!entity) continue;
351
352 const auto* light = entity->get_component<LightComponent>();
353 if (light && light->should_cast_shadows()) {
354 shadow_casting_lights.push_back(entity);
355 }
356 }
357
359 scene_ = &scene;
360 const glm::vec3 dummy_camera_pos(0.0f); // Distance doesn't matter for shadows
361 for (const EntityID root_id : scene.get_root_entities()) {
362 collect_render_commands_recursive(root_id, dummy_camera_pos);
363 }
364
365 // Render each light's shadow map
366 for (Entity* light_entity : shadow_casting_lights) {
367 auto* light = light_entity->get_component<LightComponent>();
368 if (!light) continue;
369
370 ensure_shadow_map(light_entity, *light);
371
372 auto& shadow_data = shadow_maps_[light_entity];
373 shadow_data.framebuffer->bind();
374
375 glViewport(0, 0, 4096, 4096);
376 glClear(GL_DEPTH_BUFFER_BIT);
377 glEnable(GL_DEPTH_TEST);
378 glDepthFunc(GL_LESS);
379
380 glEnable(GL_CULL_FACE);
381 glCullFace(GL_FRONT);
382
383 // Use light's view-projection matrix
384 shadow_data.light_view_proj = calculate_light_view_proj(light_entity, light, camera); // Store for main pass
385
386 // glEnable(GL_POLYGON_OFFSET_FILL);
387 // glPolygonOffset(1.5f, 2.0f);
388
389 // Render geometry to depth texture
390 draw_shadow_geometry(shadow_data.light_view_proj);
391
392 shadow_data.framebuffer->unbind();
393 }
394 // glDisable(GL_POLYGON_OFFSET_FILL);
395 glCullFace(GL_BACK);
396 glViewport(0, 0, framebuffer_width_, framebuffer_height_);
397 }
398
399 void Renderer::draw_shadow_geometry(const glm::mat4 &light_view_proj) {
400 const Shader& shadow_shader = get_shader_for_material(shadow_material_);
401 shadow_shader.use();
402 shadow_shader.set_mat4("uLightViewProjMatrix", light_view_proj);
403
404 shadow_material_->bind();
405
406 for (const auto &cmd : opaque_objects_) {
407 const Entity *entity = scene_->get_entity(cmd.entity_id);
408 if (!entity) continue;
409
410 const auto* transform = entity->get_component<TransformComponent>();
411 if (!transform) continue;
412
413 // Set model matrix for this object
414 shadow_shader.set_mat4("uModelMatrix", transform->get_world_matrix());
415
416 cmd.mesh->draw();
417 }
418
419 shadow_material_->unbind();
420 }
421
423 const glm::vec3 light_dir = glm::normalize(light->get_direction());
424
425 // Center shadow map on camera position
426 const glm::vec3 camera_pos = camera.get_owner().transform()->get_position();
427
428 const float ortho_size = 100.0f;
429 const float texel_size = (ortho_size * 2.0f) / 4096.0f;
430
431 glm::vec3 look_at;
432 look_at.x = floor(camera_pos.x / texel_size) * texel_size;
433 look_at.y = 0.0f;
434 look_at.z = float(camera_pos.z / texel_size) * texel_size;
435
436 const glm::vec3 light_pos = look_at - light_dir * 30.0f;
437
438 glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
439 if (glm::abs(glm::dot(light_dir, up)) > 0.99f) {
440 up = glm::vec3(1.0f, 0.0f, 0.0f);
441 }
442
443 const glm::mat4 light_projection = glm::ortho(
444 -ortho_size, ortho_size,
445 -ortho_size, ortho_size,
446 1.0f, 60.0f);
447
448 const glm::mat4 light_view = glm::lookAt(light_pos, look_at, up);
449
450 return light_projection * light_view;
451 }
452
453 void Renderer::execute_geometry_pass(const glm::mat4 &view, const glm::mat4 &proj) {
454 glEnable(GL_DEPTH_TEST);
455 glDepthMask(GL_TRUE);
456 glDepthFunc(GL_LESS);
457 glDisable(GL_BLEND);
458
459
460 glEnable(GL_CULL_FACE);
461 glCullFace(GL_BACK);
462 glFrontFace(GL_CCW);
463
464 glEnable(GL_STENCIL_TEST);
465 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
466
467 std::ranges::sort(opaque_objects_,
468 [](const RenderCommand &a, const RenderCommand &b) {
469 return a.distance_to_camera < b.distance_to_camera;
470 });
471
472 for (const auto &cmd: opaque_objects_) {
473 draw_render_command(cmd, view, proj);
474 }
475
476 for (const auto &cmd: opaque_instanced_objects_) {
477 draw_instanced_command(cmd, view, proj);
478 }
479 }
480
481 void Renderer::execute_transparency_pass(const glm::mat4 &view, const glm::mat4 &proj) {
482 // Configure blending: enable for color input, disable for object ID output
483 glEnablei(GL_BLEND, 0); // Enable blending for fragColor (location 0)
484 glDisablei(GL_BLEND, 1); // Disable blending for objectID (location 1)
485 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
486
487 // Sort the transparent objects from back-to-front relative to camera
488 // This ensures proper blending order between different objects
489 std::ranges::sort(transparent_objects_,
490 [](const RenderCommand &a, const RenderCommand &b) {
491 return a.distance_to_camera > b.distance_to_camera;
492 });
493
494 // Render non-instanced transparent objects with two-pass rendering
495 glDisable(GL_CULL_FACE);
496 for (const auto &cmd: transparent_objects_) {
497 // Pass 1: Draw back faces, to depth buffer
498 glCullFace(GL_FRONT);
499 glDepthMask(GL_TRUE);
500 glEnable(GL_POLYGON_OFFSET_FILL);
501 glPolygonOffset(2.0f, 2.0f);
502 draw_render_command(cmd, view, proj);
503 glDisable(GL_POLYGON_OFFSET_FILL);
504
505 // Pass 2: Draw front faces, don't write to depth buffer
506 glCullFace(GL_BACK);
507 glDepthMask(GL_FALSE);
508 draw_render_command(cmd, view, proj);
509 }
510
511 // Render instanced transparent objects with two-pass rendering
512 for (const auto &cmd: transparent_instanced_objects_) {
513 // Pass 1: Draw back faces, to depth buffer
514 glCullFace(GL_FRONT);
515 glDepthMask(GL_TRUE);
516 draw_instanced_command(cmd, view, proj);
517
518 // Pass 2: Draw front faces, don't write to depth buffer
519 glCullFace(GL_BACK);
520 glDepthMask(GL_FALSE);
521 draw_instanced_command(cmd, view, proj);
522 }
523
524 // Restore depth writing
525 glDepthMask(GL_TRUE);
526 }
527
528 void Renderer::create_main_framebuffer(uint32_t width, uint32_t height) {
529 framebuffer_width_ = width;
530 framebuffer_height_ = height;
531
532 // General Settings
534 settings.width = width;
535 settings.height = height;
536
537 // ObjectId specific settings
538 FrameBufferAttachmentSettings object_id_attachment_settings = settings;
539 object_id_attachment_settings.format = GL_RED_INTEGER;
540 object_id_attachment_settings.internal_format = GL_R32UI;
541 object_id_attachment_settings.type = GL_UNSIGNED_INT;
542 scene_framebuffers_[SCREEN_TEXTURE_1] = std::make_unique<Framebuffer>();
543 scene_framebuffers_[SCREEN_TEXTURE_1]->attach_color_texture(settings);
544 scene_framebuffers_[SCREEN_TEXTURE_1]->attach_color_texture(object_id_attachment_settings);
545 scene_framebuffers_[SCREEN_TEXTURE_1]->attach_depth_texture(settings);
546
547 scene_framebuffers_[SCREEN_TEXTURE_2] = std::make_unique<Framebuffer>();
548 scene_framebuffers_[SCREEN_TEXTURE_2]->attach_color_texture(settings);
549 scene_framebuffers_[SCREEN_TEXTURE_2]->attach_color_texture(object_id_attachment_settings);
550 scene_framebuffers_[SCREEN_TEXTURE_2]->attach_depth_texture(settings);
551 }
552
553 void Renderer::resize_main_framebuffer(uint32_t width, uint32_t height) {
554 framebuffer_width_ = width;
555 framebuffer_height_ = height;
556
557 // Resize only the current render buffer immediately.
558 // The display buffer will be lazily resized on the next frame
559 // to avoid showing cleared/incomplete frames during a window resize.
560 if (scene_framebuffers_[0]) {
561 scene_framebuffers_[current_fb_index_]->resize(width, height);
562 }
563 }
564
566 const int display_index = 1 - current_fb_index_;
567 if (scene_framebuffers_[display_index]) {
568 return scene_framebuffers_[display_index]->get_color_attachment(0);
569 }
570 return 0;
571 }
572
573 uint32_t Renderer::get_object_id_texture() const {
574 const int display_index = 1 - current_fb_index_;
575 if (scene_framebuffers_[display_index]->get_color_attachment(1) != 0) {
576 return scene_framebuffers_[display_index]->get_color_attachment(1);
577 }
578 return 0;
579 }
580
582 if (!scene_framebuffers_[SCREEN_TEXTURE_1]) {
584 }
585
586 // Check if the OTHER buffer (display buffer) needs resizing
587 const int display_index = 1 - current_fb_index_;
588 if (scene_framebuffers_[display_index] &&
589 (scene_framebuffers_[display_index]->get_width() != framebuffer_width_ ||
590 scene_framebuffers_[display_index]->get_height() != framebuffer_height_)) {
591 scene_framebuffers_[display_index]->resize(framebuffer_width_, framebuffer_height_);
592 }
593
594 execute_shadow_passes(scene, camera);
595
596 scene_framebuffers_[current_fb_index_]->bind();
598
599 // Clear the object ID buffer (color attachment 1) to 0
600 constexpr GLuint clear_value = 0;
601 glClearBufferuiv(GL_COLOR, 1, &clear_value);
602
603 execute_main_pass(scene, camera);
604 scene_framebuffers_[current_fb_index_]->unbind();
605 glFlush();
606
607 // Swap for next frame
609 }
610
611 void Renderer::set_fallback_shader(Shader &fallback_shader) {
612 fallback_shader_ = &fallback_shader;
613
614 if (context_) {
615 context_->shader_handle = fallback_shader.get_program_id();
616 }
617 }
618
619 Shader &Renderer::get_shader_for_material(const std::shared_ptr<Material> &material) {
620 if (!material) {
621 return *fallback_shader_;
622 }
623
624 // Check if material has a compiled shader ID
625 if (const uint32_t material_shader_id = material->get_compiled_shader_id(); material_shader_id != 0) {
626 // Get shader wrapper from the ID
627 if (Shader *material_shader = shader_registry_.get_shader_from_id(material_shader_id)) {
628 return *material_shader;
629 }
630 }
631
632 // Check if material needs compilation
633 if (material->has_custom_shader()) {
634 // Try to compile the material's shader
635 if (const uint32_t compiled_id = compile_material_shader(material); compiled_id != 0) {
636 material->set_compiled_shader_id(compiled_id);
637 const auto shader = shader_registry_.get_shader_from_id(compiled_id);
638 return *shader;
639 }
640 }
641
642 // Fall back to default shader
643 return *fallback_shader_;
644 }
645
646 uint32_t Renderer::compile_material_shader(std::shared_ptr<Material> material) {
647 if (!material || !material->has_custom_shader()) {
648 return 0;
649 }
650
651 const Material::ShaderInfo *shader_info = material->get_shader_info();
652 if (!shader_info) {
653 return 0;
654 }
655
656 // Create shader variant with material's settings
658 variant.vertex_path = shader_info->vertex_path;
659 variant.fragment_path = shader_info->fragment_path;
660 variant.defines = shader_info->defines;
661
662 // Add automatic defines based on material properties
663 shader_manager_.add_automatic_defines(*material, variant.defines);
664
665 // Compile using shader manager
666 return shader_manager_.load_shader(variant);
667 }
668}
void use() const
Definition Shader.h:39
void set_float(const std::string &name, const float value) const
Definition Shader.h:61
void set_int(const std::string &name, const int value) const
Definition Shader.h:53
void set_vec3(const std::string &name, const float x, const float y, const float z) const
Definition Shader.h:78
void set_uint(const std::string &name, const uint32_t value) const
Definition Shader.h:57
void draw_render_command(const RenderCommand &cmd, const glm::mat4 &view, const glm::mat4 &projection)
Definition Renderer.cpp:221
void ensure_shadow_map(Entity *light_entity, const LightComponent &light)
Definition Renderer.cpp:200
Shader & get_shader_for_material(const std::shared_ptr< Material > &material)
Definition Renderer.cpp:619
SkyboxRenderer skybox_renderer_
Definition Renderer.h:136
ShadowSettings shadow_settings_
Definition Renderer.h:134
bool render_to_framebuffer_
Definition Renderer.h:124
void execute_skybox_pass(Scene *scene, const glm::mat4 &view, const glm::mat4 &projection, CameraComponent *camera_comp) const
Definition Renderer.cpp:300
uint32_t get_object_id_texture() const
Definition Renderer.cpp:573
glm::mat4 calculate_light_view_proj(Entity *light_entity, LightComponent *light, const CameraComponent &camera)
Definition Renderer.cpp:422
void draw_instanced_command(const InstancedRenderCommand &cmd, const glm::mat4 &view, const glm::mat4 &projection)
Definition Renderer.cpp:268
void render(Scene &scene, const Entity *camera_override)
Definition Renderer.cpp:47
void collect_geometry_from_scene(Scene &scene, const glm::vec3 camera_pos)
Definition Renderer.cpp:140
void execute_shadow_passes(Scene &scene, CameraComponent &camera)
Definition Renderer.cpp:343
Shader * fallback_shader_
Definition Renderer.h:116
uint32_t fallback_program_
Definition Renderer.h:117
uint32_t get_main_output_texture() const
Definition Renderer.cpp:565
void resize_main_framebuffer(uint32_t width, uint32_t height)
Definition Renderer.cpp:553
void execute_transparency_pass(const glm::mat4 &view, const glm::mat4 &proj)
Definition Renderer.cpp:481
void reset_framebuffer_data()
Definition Renderer.cpp:68
void execute_main_pass(Scene &scene, CameraComponent &camera)
Definition Renderer.cpp:323
uint32_t framebuffer_width_
Definition Renderer.h:125
void render_frame(Scene &scene, CameraComponent &camera)
Definition Renderer.cpp:581
void execute_geometry_pass(const glm::mat4 &view, const glm::mat4 &proj)
Definition Renderer.cpp:453
void collect_lights_from_scene(Scene &scene, CameraComponent &camera)
Definition Renderer.cpp:312
void store_lights_in_context(const std::vector< Entity * > &light_entities, CameraComponent &camera)
Definition Renderer.cpp:94
uint32_t framebuffer_height_
Definition Renderer.h:126
void draw_shadow_geometry(const glm::mat4 &light_view_proj)
Definition Renderer.cpp:399
void set_fallback_shader(Shader &fallback_shader)
Definition Renderer.cpp:611
void collect_render_commands_recursive(EntityID entity_id, const glm::vec3 &camera_pos)
Definition Renderer.cpp:146
void create_main_framebuffer(uint32_t width, uint32_t height)
Definition Renderer.cpp:528
uint32_t compile_material_shader(std::shared_ptr< Material > material)
Definition Renderer.cpp:646
Manages a collection of entities and their hierarchical relationships.
Definition Scene.h:24
Entity * get_entity(EntityID id)
Retrieves an entity by its ID.
Definition Scene.cpp:81
EntityID get_default_camera_entity_id() const
Definition Scene.h:159
SceneEnvironment * environment() const
Definition Scene.h:181
void render(const Skybox &skybox, const CameraComponent *camera) const
InstancedRenderableComponent * instanced_renderable
Definition Renderer.h:39