Easy3D 2.6.1
Loading...
Searching...
No Matches
dual_depth_peeling.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_DUAL_DEPTH_PEELING_H
28#define EASY3D_RENDERER_DUAL_DEPTH_PEELING_H
29
30#include <vector>
31#include <easy3d/renderer/transparency.h>
32
33
34namespace easy3d {
35
36 class Camera;
39
81 {
82 public:
87 explicit DualDepthPeeling(Camera* cam);
91 ~DualDepthPeeling() override;
92
98 void set_max_peels(int n) { max_peels_ = n; }
99
104 int max_peels() const { return max_peels_; }
105
110 void draw(const std::vector<TrianglesDrawable*>& surfaces) override;
111
112 protected:
113
114 // Allocate and configure FBOs, initialize variables, query, etc.
115 void init(int w, int h);
116
117 // Initialize Min - Max Depth Buffer
118 void init_depth_buffers(const std::vector<TrianglesDrawable*>& surfaces);
119
120 // Render the opaque pass geometry.
121 void geometry_pass(const std::vector<TrianglesDrawable*>& surfaces);
122
123 // Render the scene to produce the next set of peels.
124 void peel(const std::vector<TrianglesDrawable*>& surfaces);
125
126 // Blends the final image.
127 void blend_final_image();
128
129 // Swap the src/dest render targets:
130 void swap_targets();
131
132 // Checks if the peeling is done.
133 bool peeling_done() const;
134
135 // Initializes the occlusion query.
136 void init_occlusion_query();
137 // Deletes the occlusion query ID.
138 void delete_occlusion_query_id();
139
140 // Starts the occlusion query.
141 void start_occlusion_query() const;
142 // Ends the occlusion query.
143 void end_occlusion_query();
144
145 // Release all FBOs, shader programs.
146 void clear();
147
148 private:
149 Camera* camera_;
150
151 int width_;
152 int height_;
153
154 // Defines the maximum number of peeling layers. Initial value is 4.
155 // A special value of 0 means no maximum limit. It has to be a positive value.
156 int max_peels_;
157
158 // The stages of this multi-pass DualDepthPeeling pass
159 enum DualDepthPeelingStage {
160 DDP_InitDepth,
161 DDP_Peel,
162 DDP_Blend,
163 DDP_Inactive = -1,
164 };
165 DualDepthPeelingStage stage_;
166
167 FramebufferObject* fbo_;
168
169 // Name the textures used by this render pass. These are indexes into this->Textures
170 enum TextureName {
171 DepthA = 0, // RG32F min-max depth buffer
172 DepthB, // RG32F min-max depth buffer
173 BackTemp, // RGBA8 back-to-front peeling buffer
174 Back, // RGBA8 back-to-front accumulation buffer
175 FrontA, // RGBA8 front-to-back peeling buffer
176 FrontB // RGBA8 front-to-back accumulation buffer
177 };
178 TextureName front_source_; // The current front source buffer
179 TextureName front_destination_; // The current front destination buffer
180 TextureName depth_source_; // The current depth source buffer
181 TextureName depth_destination_; // The current depth destination buffer
182
183 int current_peel_;
184 int num_geom_passes_; // Debug info, counts number of geometry passes.
185
186 bool use_occlusion_query_;
187 unsigned int occlusion_query_Id_;
188 unsigned int num_written_pixels_;
189 unsigned int occlusion_threshold_;
190
191 float bkg_color_[4];
192
193 private:
194
195 /* Methods to block default compiler methods.
196 * The compiler automatically generates the following methods.
197 * Since the default compiler implementation is generally not what
198 * you want (for all but the most simple classes), we usually
199 * put the declarations of these methods in the private section
200 * and never implement them. This prevents the compiler from
201 * implementing an incorrect "default" behavior without us
202 * knowing. (See Scott Meyers book, "Effective C++")
203 */
204 //copying disabled
206 DualDepthPeeling& operator=(const DualDepthPeeling&);
207 };
208
209}
210
211
212#endif // EASY3D_RENDERER_DUAL_DEPTH_PEELING_H
A perspective or orthographic camera.
Definition camera.h:113
int max_peels() const
Returns the maximum number of peeling layers.
Definition dual_depth_peeling.h:104
void draw(const std::vector< TrianglesDrawable * > &surfaces) override
Renders the scene (a set of surfaces) with transparency effect.
Definition dual_depth_peeling.cpp:313
void set_max_peels(int n)
Sets the maximum number of peeling layers.
Definition dual_depth_peeling.h:98
~DualDepthPeeling() override
Destructor.
Definition dual_depth_peeling.cpp:69
DualDepthPeeling(Camera *cam)
Constructor.
Definition dual_depth_peeling.cpp:48
An implementation of framebuffer object (FBO).
Definition framebuffer_object.h:122
Transparency()=default
Default constructor for Transparency.
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition drawable_triangles.h:46
Definition collider.cpp:182