This example shows how to render a point cloud without normal information (but still be able to perceive the depth) using the Eye Dome Lighting technique.
27#ifndef EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
28#define EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
30#include <easy3d/viewer/viewer.h>
37 class EyeDomeLighting;
43 explicit TutorialEyeDomeLighting(
const std::string& title =
"");
44 ~TutorialEyeDomeLighting()
override;
47 bool key_press_event(
int key,
int modifiers)
override;
49 void draw()
const override;
An implementation of the Eye Dome Lighting (EDL) technique.
Definition eye_dome_lighting.h:60
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182
28#include <easy3d/core/point_cloud.h>
29#include <easy3d/renderer/opengl.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/renderer/camera.h>
32#include <easy3d/renderer/shader_manager.h>
33#include <easy3d/renderer/shader_program.h>
34#include <easy3d/renderer/eye_dome_lighting.h>
35#include <easy3d/renderer/renderer.h>
36#include <easy3d/util/setting.h>
43TutorialEyeDomeLighting::TutorialEyeDomeLighting(
const std::string& title) :
Viewer(title) {
44 camera()->setUpVector(
vec3(0, 1, 0));
45 camera()->setViewDirection(
vec3(0, 0, -1));
46 camera_->showEntireScene();
51 hint_ =
"Press 'space' to toggle Eye Dome Lighting";
55TutorialEyeDomeLighting::~TutorialEyeDomeLighting() {
63bool TutorialEyeDomeLighting::key_press_event(
int key,
int modifiers) {
64 if (key == KEY_SPACE) {
65 edl_enabled_ = !edl_enabled_;
66 std::cout <<
"Eye Dome Lighting " << (edl_enabled_ ?
"enabled" :
"disabled") << std::endl;
71 return Viewer::key_press_event(key, modifiers);
75void TutorialEyeDomeLighting::draw()
const {
76 if (!current_model()) {
81 const mat4& MVP = camera_->modelViewProjectionMatrix();
83 const vec3& wCamPos = camera_->position();
86 const mat4& MV = camera_->modelViewMatrix();
87 const vec4& wLightPos =
inverse(MV) * setting::light_position;
89 ShaderProgram* program = ShaderManager::get_program(
"points/points_plain_color");
91 std::vector<ShaderProgram::Attribute> attributes;
95 program = ShaderManager::create_program_from_files(
"points/points_plain_color", attributes);
100 auto drawable = current_model()->renderer()->get_points_drawable(
"vertices");
101 float point_size = drawable->point_size();
102 glPointSize(point_size);
109 program->
set_uniform(
"lighting", drawable->normal_buffer());
110 program->
set_uniform(
"per_vertex_color", drawable->coloring_method() != State::UNIFORM_COLOR && drawable->color_buffer());
111 program->
set_uniform(
"default_color", drawable->color());
OpenGL Shader Compilation.
Definition shader_program.h:75
void bind() const
Start using the program.
Definition shader_program.cpp:678
ShaderProgram * set_uniform(const std::string &name, const void *value)
Set the uniform to value.
Definition shader_program.cpp:436
void release() const
End using the program.
Definition shader_program.cpp:689
std::pair< AttribType, std::string > Attribute
Attribute: a pair of attribute type and attribute name.
Definition shader_program.h:85
Mat< N, N, T > inverse(const Mat< N, N, T > &m)
Returns the inverse of an N x N (square) matrix.
Definition mat.h:1190
28#include <easy3d/core/model.h>
29#include <easy3d/renderer/drawable_points.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
49int main(
int argc,
char **argv) {
53 const std::string file = resource::directory() +
"/data/bunny.bin";
56 TutorialEyeDomeLighting viewer(EXAMPLE_TITLE);
59 auto model = viewer.add_model(file,
true);
61 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
65 auto drawable = model->renderer()->get_points_drawable(
"vertices");
66 drawable->set_uniform_coloring(
vec4(0.6f, 0.6f, 1.0f, 1.0f));
67 drawable->set_point_size(5.0f);