Blender V5.3
eevee_volume.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
35
36#pragma once
37
38#include "BLI_set.hh"
39
40#include "DRW_gpu_wrapper.hh"
41#include "GPU_batch_utils.hh"
42
43#include "eevee_sync.hh"
45
46namespace blender::eevee {
47
48class Instance;
49class VolumePipeline;
51
53 friend VolumePipeline;
54 friend WorldVolumePipeline;
55
56 private:
57 Instance &inst_;
58
59 bool enabled_;
60 bool viewport_sampling_is_reset_ = false;
61 bool use_reprojection_;
62 bool use_lights_;
63
64 /* Track added/removed volume objects to reset the accumulation history. */
65 Set<ObjectKey> previous_objects_;
66 Set<ObjectKey> current_objects_;
67
68 VolumesInfoData &data_;
69
75 Texture occupancy_tx_ = {"occupancy_tx"};
81 Texture hit_count_tx_ = {"hit_count_tx"};
82 Texture hit_depth_tx_ = {"hit_depth_tx"};
83 Texture front_depth_tx_ = {"front_depth_tx"};
84 Framebuffer occupancy_fb_ = {"occupancy_fb"};
85
86 /* Material Parameters */
87 Texture prop_scattering_tx_;
88 Texture prop_extinction_tx_;
89 Texture prop_emission_tx_;
90 Texture prop_phase_tx_;
91 Texture prop_phase_weight_tx_;
92
93 /* Light Scattering. */
94 PassSimple scatter_ps_ = {"Volumes.Scatter"};
95 SwapChain<Texture, 2> scatter_tx_;
96 SwapChain<Texture, 2> extinction_tx_;
97
98 /* Volume Integration */
99 PassSimple integration_ps_ = {"Volumes.Integration"};
100 Texture integrated_scatter_tx_;
101 Texture integrated_transmit_tx_;
102
103 /* Full-screen Resolve */
104 PassSimple resolve_ps_ = {"Volumes.Resolve"};
105 Framebuffer resolve_fb_;
106
107 Texture dummy_scatter_tx_;
108 Texture dummy_transmit_tx_;
109
110 View volume_view = {"Volume View"};
111
112 float4x4 history_viewmat_ = float4x4::zero();
113 /* Number of re-projected frame into the volume history.
114 * Allows continuous integration between interactive and static mode. */
115 int history_frame_count_ = 0;
116 /* Used to detect change in camera projection type. */
117 bool history_camera_is_perspective_ = false;
118 /* Must be set to false on every event that makes the history invalid to sample. */
119 bool valid_history_ = false;
120
121 gpu::Batch *cube_batch_ = GPU_batch_unit_cube();
122
123 public:
124 VolumeModule(Instance &inst, VolumesInfoData &data) : inst_(inst), data_(data)
125 {
126 dummy_scatter_tx_.ensure_3d(
127 gpu::TextureFormat::UNORM_8_8_8_8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(0.0f));
128 dummy_transmit_tx_.ensure_3d(
129 gpu::TextureFormat::UNORM_8_8_8_8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(1.0f));
130 };
131
133 {
134 GPU_BATCH_DISCARD_SAFE(cube_batch_);
135 }
136
138 {
139 return enabled_ && use_lights_;
140 }
141
142 /* Return the future value of enabled() that will only be available after end_sync(). */
143 bool will_enable() const;
144
145 /* Returns the state of the module. */
146 bool enabled() const
147 {
148 return enabled_;
149 }
150
152 {
153 return data_.tex_size;
154 }
155
157 {
158 return cube_batch_;
159 }
160
161 void init();
162
163 void begin_sync();
164
165 void world_sync(const WorldHandle &world_handle);
166
167 void object_sync(const ObjectHandle &ob_handle);
168
169 void end_sync();
170
171 void set_view(View &main_view, int2 render_extent);
172
173 /* Render material properties. Needs to be called after `set_view`. */
174 void draw_prepass(View &main_view);
175 /* Compute scattering and integration. */
176 void draw_compute(View &main_view, int2 extent);
177 /* Final image compositing. */
178 void draw_resolve(View &view);
179
180 /* Final occupancy after resolve. Used by object volume material evaluation. */
181 struct {
183 gpu::Texture *scattering_tx_ = nullptr;
185
186 template<typename PassType> void bind_resources(PassType &pass)
187 {
188 pass.bind_texture(VOLUME_SCATTERING_TEX_SLOT, &scattering_tx_);
190 }
192
193 /* Volume property buffers that are populated by objects or world volume shaders. */
194 struct {
196 gpu::Texture *scattering_tx_ = nullptr;
197 gpu::Texture *extinction_tx_ = nullptr;
198 gpu::Texture *emission_tx_ = nullptr;
199 gpu::Texture *phase_tx_ = nullptr;
201 gpu::Texture *occupancy_tx_ = nullptr;
202
203 template<typename PassType> void bind_resources(PassType &pass)
204 {
208 pass.bind_image(VOLUME_PROP_PHASE_IMG_SLOT, &phase_tx_);
210 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
211 }
213
214 /* Textures used for object volume occupancy computation. */
215 struct {
217 gpu::Texture *occupancy_tx_ = nullptr;
218 gpu::Texture *hit_depth_tx_ = nullptr;
219 gpu::Texture *hit_count_tx_ = nullptr;
220
221 template<typename PassType> void bind_resources(PassType &pass)
222 {
223 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
224 pass.bind_image(VOLUME_HIT_DEPTH_SLOT, &hit_depth_tx_);
225 pass.bind_image(VOLUME_HIT_COUNT_SLOT, &hit_count_tx_);
226 }
228};
229} // namespace blender::eevee
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition GPU_batch.hh:199
A running instance of the engine.
void object_sync(const ObjectHandle &ob_handle)
void set_view(View &main_view, int2 render_extent)
void world_sync(const WorldHandle &world_handle)
struct blender::eevee::VolumeModule::@105155100155224106113172003277040034221247060352 properties
VolumeModule(Instance &inst, VolumesInfoData &data)
void draw_compute(View &main_view, int2 extent)
void draw_prepass(View &main_view)
#define VOLUME_PROP_SCATTERING_IMG_SLOT
#define VOLUME_HIT_DEPTH_SLOT
#define VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT
#define VOLUME_HIT_COUNT_SLOT
#define VOLUME_OCCUPANCY_SLOT
#define VOLUME_TRANSMITTANCE_TEX_SLOT
#define VOLUME_PROP_EXTINCTION_IMG_SLOT
#define VOLUME_PROP_PHASE_IMG_SLOT
#define VOLUME_SCATTERING_TEX_SLOT
#define VOLUME_PROP_EMISSION_IMG_SLOT
PassType
detail::Pass< command::DrawCommandBuf > PassSimple
gpu::Batch * GPU_batch_unit_cube() ATTR_WARN_UNUSED_RESULT
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
@ GPU_TEXTURE_USAGE_SHADER_READ
BMesh const char void * data