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
|
## 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
|
To build the project **you'll need to have GLFW already installed
|
||||||
system-wide**, the rest of the dependencies are already included.
|
system-wide**, the rest of the dependencies are already included.
|
||||||
@@ -48,6 +48,7 @@ flowchart TB
|
|||||||
Indices
|
Indices
|
||||||
Shader
|
Shader
|
||||||
Texture
|
Texture
|
||||||
|
UniformBuffer
|
||||||
DirectionalLight
|
DirectionalLight
|
||||||
PointLight
|
PointLight
|
||||||
SpotLight
|
SpotLight
|
||||||
@@ -68,6 +69,7 @@ flowchart TB
|
|||||||
|
|
||||||
Renderer --> Scene
|
Renderer --> Scene
|
||||||
Renderer --> Camera
|
Renderer --> Camera
|
||||||
|
Renderer --> UniformBuffer
|
||||||
|
|
||||||
Scene --> Entity
|
Scene --> Entity
|
||||||
Scene --> LightEnvironment
|
Scene --> LightEnvironment
|
||||||
@@ -81,6 +83,7 @@ flowchart TB
|
|||||||
|
|
||||||
Material --> Shader
|
Material --> Shader
|
||||||
Material --> Texture
|
Material --> Texture
|
||||||
|
Shader --> UniformBuffer
|
||||||
|
|
||||||
LightEnvironment --> DirectionalLight
|
LightEnvironment --> DirectionalLight
|
||||||
LightEnvironment --> PointLight
|
LightEnvironment --> PointLight
|
||||||
@@ -103,7 +106,7 @@ flowchart TB
|
|||||||
|
|
||||||
class Renderer,Scene,Camera,Framebuffer application
|
class Renderer,Scene,Camera,Framebuffer application
|
||||||
class Entity,Transform,Mesh,Material,LightEnvironment world
|
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 Loader,tinyobjloader,stb_image loading
|
||||||
class Window,GLFW,glad,ImGui platform
|
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 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 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 backpack = load_obj("./assets/backpack/backpack.obj", shader);
|
||||||
|
|
||||||
auto cube_mesh = Mesh::create(get_cube_vertices());
|
auto cube_mesh = Mesh::create(get_cube_vertices());
|
||||||
@@ -91,6 +93,19 @@ int main()
|
|||||||
|
|
||||||
/******************** Scene construction ********************/
|
/******************** 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
|
// Backpack scene
|
||||||
Rc<Scene> backpack_scene = make_rc<Scene>();
|
Rc<Scene> backpack_scene = make_rc<Scene>();
|
||||||
user_data.scenes.push_back(backpack_scene);
|
user_data.scenes.push_back(backpack_scene);
|
||||||
@@ -105,12 +120,12 @@ int main()
|
|||||||
floor.transform.scale = {20.0f, 1.0f, 20.0f};
|
floor.transform.scale = {20.0f, 1.0f, 20.0f};
|
||||||
backpack_scene->add_entity(floor);
|
backpack_scene->add_entity(floor);
|
||||||
|
|
||||||
PointLight light_white;
|
PointLight light_white2;
|
||||||
light_white.position = glm::vec3(0.0f, 3.0f, 3.0f);
|
light_white2.position = glm::vec3(0.0f, 3.0f, 3.0f);
|
||||||
light_white.diffuse = glm::vec3(2.0f, 2.0f, 2.0f); // Bright white
|
light_white2.diffuse = glm::vec3(2.0f, 2.0f, 2.0f); // Bright white
|
||||||
light_white.specular = glm::vec3(2.0f, 2.0f, 2.0f); // White highlights
|
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
|
// Cubes scene
|
||||||
Rc<Scene> cubes_scene = make_rc<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<Shader>& debug_shader,
|
||||||
const Rc<Mesh>& default_mesh)
|
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);
|
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());
|
debug_shader->set_mat4("u_model", entity.transform.get_model_matrix());
|
||||||
|
mesh->draw();
|
||||||
|
}
|
||||||
|
|
||||||
if (entity.mesh) {
|
// Draw point lights (yellow)
|
||||||
entity.mesh->draw();
|
debug_shader->set_vec3("u_color", glm::vec3(0.7f, 0.7f, 0.0f));
|
||||||
} else {
|
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();
|
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);
|
set_wireframe(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user