Easy3D 3.0.0
Loading...
Searching...
No Matches
Tutorial_505_EyeDomeLighting

Rendering a point cloud without normals using Eye Dome Lighting (EDL) for depth perception.

Overview

This tutorial renders a raw point cloud that has no normal information, yet still conveys shape and depth clearly, by adding Eye Dome Lighting to the standard Easy3D Viewer. It uses the familiar effect pattern (see Tutorial_501_AmbientOcclusion): subclass Viewer, install a RenderSettings in init(), and replace it to toggle the effect. The entry point loads the bunny point cloud, gives it a uniform color and a visible point size, and runs the custom viewer; the EDL logic lives in the TutorialEyeDomeLighting class (shown after this file).

The technique

A point cloud has no connectivity and often no normals, so classical lighting (Lambert, Phong) cannot be evaluated — a flat-colored cloud looks like a confusing blob of dots. Eye Dome Lighting (Boucheny, 2009; popularized by CloudCompare and Potree) is an image-space shading trick that needs only the depth buffer: the cloud is first rendered normally into color and depth buffers, then a full-screen post-process compares each pixel's depth with the depths of a few neighbors at a small screen-space offset. If the neighbors are consistently closer to the camera, the pixel lies on the "far side" of a depth discontinuity (a silhouette or crease) and is darkened; pixels on flat, front-facing regions stay bright. The darkened contours act like a shading cue and make silhouettes, overlaps, and surface relief pop out, even though no surface or normal was ever computed. It is cheap (one extra pass), works on any point set, and complements ambient occlusion for meshes (Tutorial_501). See the renderer's EDL pass for the implementation.

Easy3D API

Running it

Press 'space' to toggle Eye Dome Lighting on/off (the state is printed to the console) and compare how much easier the shape is to read with the contours darkened. Standard Viewer navigation (mouse drag to rotate, wheel to zoom) applies.

1
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
87using namespace easy3d;
88
89int main(int argc, char **argv) {
90 // Bootstrap Easy3D (logging, resource directory, ...). Must come first.
91 initialize();
92
93 // The Stanford bunny as a raw point cloud (Easy3D's binary format): positions only,
94 // no connectivity and no normals — exactly the case EDL is designed for.
95 const std::string file = resource::directory() + "/data/bunny.bin";
96
97 // Create our custom viewer (a Viewer subclass that applies Eye Dome Lighting).
98 TutorialEyeDomeLighting viewer(EXAMPLE_TITLE);
99
100 // Load the point cloud and add it to the viewer. add_model() creates the model's
101 // renderer; the second argument (true) centers and scales the model to fit the scene.
102 auto model = viewer.add_model(file, true);
103 if (!model) {
104 std::cerr << "failed to load model. Please make sure the file exists and format is correct" << std::endl;
105 return EXIT_FAILURE;
106 }
107
108 // "vertices" is the standard points drawable of a point cloud. A single uniform color
109 // means all shading variation comes from EDL, and 5-pixel splats are large enough to
110 // fill the surface so the depth buffer has few holes for the EDL pass to sample.
111 auto drawable = model->renderer()->get_points_drawable("vertices");
112 drawable->set_uniform_coloring(vec4(0.6f, 0.6f, 1.0f, 1.0f));
113 drawable->set_point_size(5.0f);
114
115 // Enter the interactive loop (returns when the window is closed).
116 return viewer.run();
117}
Definition collider.cpp:182

The header file of the viewer class:

1
27#ifndef EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
28#define EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
29
30#include <easy3d/viewer/viewer.h>
31
41class TutorialEyeDomeLighting : public easy3d::Viewer {
42public:
43 // Builds the viewer; the EDL setting is installed in init().
44 explicit TutorialEyeDomeLighting(const std::string &title = "");
45
46protected:
47 // Installs the initial RenderSettings after the viewer's device is ready.
48 void init() override;
49 // Handles 'space' (toggle); forwards other keys to Viewer.
50 bool key_press_event(int key, int modifiers) override;
51};
52
53#endif // EASY3D_TUTORIAL_EYE_DOME_LIGHTING_H
The default viewer implementation for both OpenGL and Vulkan backends.
Definition viewer.h:143

The source file of the viewer class:

1
27#include "viewer.h"
28#include <easy3d/core/point_cloud.h>
29#include <easy3d/renderer/camera.h>
30#include <easy3d/renderer/render_settings.h>
31
32using namespace easy3d;
33
34// The implementation is reproduced on the example page via \include in main.cpp, so we hide
35// it from Doxygen's separate symbol documentation to avoid documenting it twice.
36// \cond
37
38TutorialEyeDomeLighting::TutorialEyeDomeLighting(const std::string &title) : Viewer(title) {
39 // A conventional viewing setup for the bunny: y up, looking down -z, framed on the scene.
40 camera()->set_up_vector(vec3(0, 1, 0));
41 camera()->set_view_direction(vec3(0, 0, -1));
42 camera_->show_entire_scene();
43
44 // hint_ is shown in the viewer HUD; it tells the user which key controls the effect.
45 hint_ = "Press 'space' to toggle Eye Dome Lighting";
46}
47
48void TutorialEyeDomeLighting::init() {
49 Viewer::init();
50
51 // Effects are declarative: the viewer applies these settings to every frame,
52 // including file snapshots. Start with EDL visible so the depth cues are obvious.
53 RenderSettings settings;
54 settings.eye_dome_lighting = true;
55 set_render_settings(settings);
56}
57
58// Interactive control of the effect. Returning true marks the key as handled; any key we do
59// not recognize is forwarded to the base Viewer so navigation and other shortcuts still work.
60bool TutorialEyeDomeLighting::key_press_event(int key, int modifiers) {
61 if (key == KEY_SPACE) {
62 // Replace the settings to toggle EDL, report the new state, and request a redraw.
63 RenderSettings settings = render_settings();
64 settings.eye_dome_lighting = !settings.eye_dome_lighting;
65 set_render_settings(settings);
66 std::cout << "Eye Dome Lighting "
67 << (settings.eye_dome_lighting ? "enabled" : "disabled") << std::endl;
68 update();
69 return true;
70 } else
71 return Viewer::key_press_event(key, modifiers);
72}
73
74// \endcond
Declarative effect settings shared by all rendering hosts.
Definition render_settings.h:80
See also
RenderSettings, Viewer, PointCloud, DrawablePoints, Tutorial_501_AmbientOcclusion