Fix debug wireframe renderer
This commit is contained in:
@@ -10,7 +10,7 @@ A minimal 3D renderer written in C++ and OpenGL 3.3 Core.
|
||||
|
||||
## Building
|
||||
|
||||
The only tested platform at the moment is **Linux** (x86-64).
|
||||
The only tested platform at the moment is **GNU/Linux** (x86_64).
|
||||
|
||||
To build the project **you'll need to have GLFW already installed
|
||||
system-wide**, the rest of the dependencies are already included.
|
||||
@@ -48,6 +48,7 @@ flowchart TB
|
||||
Indices
|
||||
Shader
|
||||
Texture
|
||||
UniformBuffer
|
||||
DirectionalLight
|
||||
PointLight
|
||||
SpotLight
|
||||
@@ -68,6 +69,7 @@ flowchart TB
|
||||
|
||||
Renderer --> Scene
|
||||
Renderer --> Camera
|
||||
Renderer --> UniformBuffer
|
||||
|
||||
Scene --> Entity
|
||||
Scene --> LightEnvironment
|
||||
@@ -81,6 +83,7 @@ flowchart TB
|
||||
|
||||
Material --> Shader
|
||||
Material --> Texture
|
||||
Shader --> UniformBuffer
|
||||
|
||||
LightEnvironment --> DirectionalLight
|
||||
LightEnvironment --> PointLight
|
||||
@@ -103,7 +106,7 @@ flowchart TB
|
||||
|
||||
class Renderer,Scene,Camera,Framebuffer application
|
||||
class Entity,Transform,Mesh,Material,LightEnvironment world
|
||||
class Vertices,Indices,Shader,Texture,DirectionalLight,PointLight,SpotLight data
|
||||
class Vertices,Indices,Shader,Texture,UniformBuffer,DirectionalLight,PointLight,SpotLight data
|
||||
class Loader,tinyobjloader,stb_image loading
|
||||
class Window,GLFW,glad,ImGui platform
|
||||
```
|
||||
|
||||
25
src/main.cpp
25
src/main.cpp
@@ -71,6 +71,8 @@ int main()
|
||||
auto shader = Shader::create("./src/shaders/default.vert", "./src/shaders/default.frag");
|
||||
auto debug_shader = Shader::create("./src/shaders/debug.vert", "./src/shaders/debug.frag", false);
|
||||
|
||||
// auto car = load_obj("./assets/AudiR8Spyder_2017/3D Models/Audi_R8_2017.obj", shader);
|
||||
|
||||
auto backpack = load_obj("./assets/backpack/backpack.obj", shader);
|
||||
|
||||
auto cube_mesh = Mesh::create(get_cube_vertices());
|
||||
@@ -91,6 +93,19 @@ int main()
|
||||
|
||||
/******************** Scene construction ********************/
|
||||
|
||||
// Car scene
|
||||
// Rc<Scene> car_scene = make_rc<Scene>();
|
||||
// user_data.scenes.push_back(car_scene);
|
||||
//
|
||||
// car_scene->add_entity(*car);
|
||||
//
|
||||
// PointLight light_white1;
|
||||
// light_white1.position = glm::vec3(0.0f, 3.0f, 3.0f);
|
||||
// light_white1.diffuse = glm::vec3(2.0f, 2.0f, 2.0f); // Bright white
|
||||
// light_white1.specular = glm::vec3(2.0f, 2.0f, 2.0f); // White highlights
|
||||
//
|
||||
// car_scene->light_environment.point_lights.push_back(light_white1);
|
||||
|
||||
// Backpack scene
|
||||
Rc<Scene> backpack_scene = make_rc<Scene>();
|
||||
user_data.scenes.push_back(backpack_scene);
|
||||
@@ -105,12 +120,12 @@ int main()
|
||||
floor.transform.scale = {20.0f, 1.0f, 20.0f};
|
||||
backpack_scene->add_entity(floor);
|
||||
|
||||
PointLight light_white;
|
||||
light_white.position = glm::vec3(0.0f, 3.0f, 3.0f);
|
||||
light_white.diffuse = glm::vec3(2.0f, 2.0f, 2.0f); // Bright white
|
||||
light_white.specular = glm::vec3(2.0f, 2.0f, 2.0f); // White highlights
|
||||
PointLight light_white2;
|
||||
light_white2.position = glm::vec3(0.0f, 3.0f, 3.0f);
|
||||
light_white2.diffuse = glm::vec3(2.0f, 2.0f, 2.0f); // Bright white
|
||||
light_white2.specular = glm::vec3(2.0f, 2.0f, 2.0f); // White highlights
|
||||
|
||||
backpack_scene->light_environment.point_lights.push_back(light_white);
|
||||
backpack_scene->light_environment.point_lights.push_back(light_white2);
|
||||
|
||||
// Cubes scene
|
||||
Rc<Scene> cubes_scene = make_rc<Scene>();
|
||||
|
||||
@@ -84,21 +84,42 @@ void Renderer::draw_debug_wireframes(const Scene& scene, const Camera& camera,
|
||||
const Rc<Shader>& debug_shader,
|
||||
const Rc<Mesh>& default_mesh)
|
||||
{
|
||||
update_global_data(scene, camera, screen_width, screen_height);
|
||||
debug_shader->bind();
|
||||
debug_shader->set_mat4("u_view_projection", camera.get_view_projection_matrix(screen_width, screen_height));
|
||||
|
||||
set_wireframe(true);
|
||||
debug_shader->bind();
|
||||
|
||||
for (const auto& entity : scene.get_entities()) {
|
||||
// Draw all standard entities (green)
|
||||
debug_shader->set_vec3("u_color", glm::vec3(0.0f, 0.7f, 0.0f));
|
||||
for (const Entity& entity : scene.get_entities()) {
|
||||
// If an entity has no mesh, use the default debug mesh
|
||||
auto mesh = entity.mesh ? entity.mesh : default_mesh;
|
||||
|
||||
debug_shader->set_mat4("u_model", entity.transform.get_model_matrix());
|
||||
mesh->draw();
|
||||
}
|
||||
|
||||
if (entity.mesh) {
|
||||
entity.mesh->draw();
|
||||
} else {
|
||||
// Draw point lights (yellow)
|
||||
debug_shader->set_vec3("u_color", glm::vec3(0.7f, 0.7f, 0.0f));
|
||||
for (const PointLight& light : scene.light_environment.point_lights) {
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), light.position);
|
||||
model = glm::scale(model, glm::vec3(0.2f));
|
||||
|
||||
debug_shader->set_mat4("u_model", model);
|
||||
default_mesh->draw();
|
||||
}
|
||||
|
||||
// Draw spot lights (cyan)
|
||||
debug_shader->set_vec3("u_color", glm::vec3(0.0f, 0.7f, 0.7f));
|
||||
for (const SpotLight& light : scene.light_environment.spot_lights) {
|
||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), light.position);
|
||||
model = glm::scale(model, glm::vec3(0.2f));
|
||||
|
||||
debug_shader->set_mat4("u_model", model);
|
||||
default_mesh->draw();
|
||||
}
|
||||
|
||||
// Restore state
|
||||
set_wireframe(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user