Easy3D 2.5.3
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
84 class Camera;
85 class TrianglesDrawable;
86 class FramebufferObject;
87
89 {
90 public:
93 explicit DualDepthPeeling(Camera* cam);
94 ~DualDepthPeeling() override;
95
98 void set_max_peels(int n) { max_peels_ = n; }
99
101 int max_peels() const { return max_peels_; }
102
104 void draw(const std::vector<TrianglesDrawable*>& surfaces) override;
105
106
107 protected:
108
109 // Allocate and configure FBOs, initialize variables, query, etc.
110 void init(int w, int h);
111
112 // Initialize Min - Max Depth Buffer
113 void init_depth_buffers(const std::vector<TrianglesDrawable*>& surfaces);
114
115 // Render the opaque pass geometry.
116 void geometry_pass(const std::vector<TrianglesDrawable*>& surfaces);
117
118 // Render the scene to produce the next set of peels.
119 void peel(const std::vector<TrianglesDrawable*>& surfaces);
120
121 void blend_final_image();
122
123 // Swap the src/dest render targets:
124 void swap_targets();
125
126 bool peeling_done() const;
127
128 void init_occlusion_query();
129 void delete_occlusion_query_id();
130
131 void start_occlusion_query() const;
132 void end_occlusion_query();
133
134 // Release all FBOs, shader programs.
135 void clear();
136
137 private:
138 Camera* camera_;
139
140 int width_;
141 int height_;
142
143 // Defines the maximum number of peeling layers. Initial value is 4.
144 // A special value of 0 means no maximum limit. It has to be a positive value.
145 int max_peels_;
146
147 // The stages of this multi-pass DualDepthPeeling pass
148 enum DualDepthPeelingStage {
149 DDP_InitDepth,
150 DDP_Peel,
151 DDP_Blend,
152 DDP_Inactive = -1,
153 };
154 DualDepthPeelingStage stage_;
155
156 FramebufferObject* fbo_;
157
158 // Name the textures used by this render pass. These are indexes into this->Textures
159 enum TextureName {
160 DepthA = 0, // RG32F min-max depth buffer
161 DepthB, // RG32F min-max depth buffer
162 BackTemp, // RGBA8 back-to-front peeling buffer
163 Back, // RGBA8 back-to-front accumulation buffer
164 FrontA, // RGBA8 front-to-back peeling buffer
165 FrontB // RGBA8 front-to-back accumulation buffer
166 };
167 TextureName front_source_; // The current front source buffer
168 TextureName front_destination_; // The current front destination buffer
169 TextureName depth_source_; // The current depth source buffer
170 TextureName depth_destination_; // The current depth destination buffer
171
172 int current_peel_;
173 int num_geom_passes_; // Debug info, counts number of geometry passes.
174
175 bool use_occlusion_query_;
176 unsigned int occlusion_query_Id_;
177 unsigned int num_written_pixels_;
178 unsigned int occlusion_threshold_;
179
180 float bkg_color_[4];
181
182 private:
183
184 /* Methods to block default compiler methods.
185 * The compiler automatically generates the following methods.
186 * Since the default compiler implementation is generally not what
187 * you want (for all but the most simple classes), we usually
188 * put the declarations of these methods in the private section
189 * and never implement them. This prevents the compiler from
190 * implementing an incorrect "default" behavior without us
191 * knowing. (See Scott Meyers book, "Effective C++")
192 */
193 //copying disabled
195 DualDepthPeeling& operator=(const DualDepthPeeling&);
196 };
197
198}
199
200
201#endif // EASY3D_RENDERER_DUAL_DEPTH_PEELING_H
A perspective or orthographic camera.
Definition: camera.h:116
Transparency effect using dual depth peeling.
Definition: dual_depth_peeling.h:89
int max_peels() const
Returns the maximum number of peeling layers.
Definition: dual_depth_peeling.h:101
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(Camera *cam)
Constructor.
Definition: dual_depth_peeling.cpp:48
Base class for rendering with transparency.
Definition: transparency.h:44
Definition: collider.cpp:182