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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
28#define EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
29
30#include <easy3d/viewer/viewer.h>
31
32
33
34
35
37 class EyeDomeLighting;
38}
39
41{
42public:
43 explicit TutorialEyeDomeLighting(const std::string& title = "");
44 ~TutorialEyeDomeLighting() override;
45
46protected:
47 bool key_press_event(int key, int modifiers) override;
48
49 void draw() const override;
50
51private:
53 bool edl_enabled_;
54};
55
56
57#endif
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "viewer.h"
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>
37
38
40
41
42
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();
47
49 edl_enabled_ = true;
50
51 hint_ = "Press 'space' to toggle Eye Dome Lighting";
52}
53
54
55TutorialEyeDomeLighting::~TutorialEyeDomeLighting() {
56 delete edl_;
57
58
59
60}
61
62
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;
67 update();
68 return true;
69 }
70 else
71 return Viewer::key_press_event(key, modifiers);
72}
73
74
75void TutorialEyeDomeLighting::draw() const {
76 if (!current_model()) {
77 return;
78 }
79
80 if (edl_enabled_) {
81 const mat4& MVP = camera_->modelViewProjectionMatrix();
82
83 const vec3& wCamPos = camera_->position();
84
85
86 const mat4& MV = camera_->modelViewMatrix();
88
90 if (!program) {
91 std::vector<ShaderProgram::Attribute> attributes;
96 }
97 if (!program)
98 return;
99
100 auto drawable = current_model()->renderer()->get_points_drawable("vertices");
101 float point_size = drawable->point_size();
102 glPointSize(point_size);
103
104 edl_->begin();
109 program->
set_uniform(
"lighting", drawable->normal_buffer());
111 program->
set_uniform(
"default_color", drawable->color());
112 drawable->gl_draw();
113
115 edl_->end();
116 }
117 else
118 Viewer::draw();
119}
120
121
static ShaderProgram * create_program_from_files(const std::string &file_base_name, const std::vector< ShaderProgram::Attribute > &attributes=std::vector< ShaderProgram::Attribute >(), const std::vector< std::string > &outputs=std::vector< std::string >(), bool geom_shader=false)
Create a shader program from shader source files specified by the shader file's base name.
Definition shader_manager.cpp:49
static ShaderProgram * get_program(const std::string &shader_name)
Get the shader program if it exists and is working.
Definition shader_manager.cpp:41
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
@ NORMAL
Normal.
Definition shader_program.h:81
@ COLOR
Color.
Definition shader_program.h:80
@ POSITION
Position.
Definition shader_program.h:79
std::pair< AttribType, std::string > Attribute
Attribute: a pair of attribute type and attribute name.
Definition shader_program.h:85
@ UNIFORM_COLOR
Uniformly colored.
Definition state.h:58
EASY3D_UTIL_EXPORT vec4 light_position
Default light position defined in the camera coordinate system.
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
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
Mat4< float > mat4
A 4 by 4 matrix of float type.
Definition types.h:67
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include "viewer.h"
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>
33
45
47
48
49int main(int argc, char **argv) {
50
52
54
55
56 TutorialEyeDomeLighting viewer(EXAMPLE_TITLE);
57
58
59 auto model = viewer.add_model(file, true);
60 if (!model) {
61 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
62 return EXIT_FAILURE;
63 }
64
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);
68
69
70 return viewer.run();
71}
72
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39