Blender V5.0
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 use_reprojection_;
61 bool use_lights_;
62
63 /* Track added/removed volume objects to reset the accumulation history. */
64 Set<ObjectKey> previous_objects_;
65 Set<ObjectKey> current_objects_;
66
67 VolumesInfoData &data_;
68
74 Texture occupancy_tx_ = {"occupancy_tx"};
80 Texture hit_count_tx_ = {"hit_count_tx"};
81 Texture hit_depth_tx_ = {"hit_depth_tx"};
82 Texture front_depth_tx_ = {"front_depth_tx"};
83 Framebuffer occupancy_fb_ = {"occupancy_fb"};
84
85 /* Material Parameters */
86 Texture prop_scattering_tx_;
87 Texture prop_extinction_tx_;
88 Texture prop_emission_tx_;
89 Texture prop_phase_tx_;
90 Texture prop_phase_weight_tx_;
91
92 /* Light Scattering. */
93 PassSimple scatter_ps_ = {"Volumes.Scatter"};
94 SwapChain<Texture, 2> scatter_tx_;
95 SwapChain<Texture, 2> extinction_tx_;
96
97 /* Volume Integration */
98 PassSimple integration_ps_ = {"Volumes.Integration"};
99 Texture integrated_scatter_tx_;
100 Texture integrated_transmit_tx_;
101
102 /* Full-screen Resolve */
103 PassSimple resolve_ps_ = {"Volumes.Resolve"};
104 Framebuffer resolve_fb_;
105
106 Texture dummy_scatter_tx_;
107 Texture dummy_transmit_tx_;
108
109 View volume_view = {"Volume View"};
110
111 float4x4 history_viewmat_ = float4x4::zero();
112 /* Number of re-projected frame into the volume history.
113 * Allows continuous integration between interactive and static mode. */
114 int history_frame_count_ = 0;
115 /* Used to detect change in camera projection type. */
116 bool history_camera_is_perspective_ = false;
117 /* Must be set to false on every event that makes the history invalid to sample. */
118 bool valid_history_ = false;
119
120 gpu::Batch *cube_batch_ = GPU_batch_unit_cube();
121
122 public:
123 VolumeModule(Instance &inst, VolumesInfoData &data) : inst_(inst), data_(data)
124 {
125 dummy_scatter_tx_.ensure_3d(
126 gpu::TextureFormat::UNORM_8_8_8_8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(0.0f));
127 dummy_transmit_tx_.ensure_3d(
128 gpu::TextureFormat::UNORM_8_8_8_8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(1.0f));
129 };
130
132 {
133 GPU_BATCH_DISCARD_SAFE(cube_batch_);
134 }
135
137 {
138 return enabled_ && use_lights_;
139 }
140
141 /* Return the future value of enabled() that will only be available after end_sync(). */
142 bool will_enable() const;
143
144 /* Returns the state of the module. */
145 bool enabled() const
146 {
147 return enabled_;
148 }
149
151 {
152 return data_.tex_size;
153 }
154
156 {
157 return cube_batch_;
158 }
159
160 void init();
161
162 void begin_sync();
163
164 void world_sync(const WorldHandle &world_handle);
165
166 void object_sync(const ObjectHandle &ob_handle);
167
168 void end_sync();
169
170 /* Render material properties. */
171 void draw_prepass(View &main_view);
172 /* Compute scattering and integration. */
173 void draw_compute(View &main_view, int2 extent);
174 /* Final image compositing. */
175 void draw_resolve(View &view);
176
177 /* Final occupancy after resolve. Used by object volume material evaluation. */
178 struct {
182
183 template<typename PassType> void bind_resources(PassType &pass)
184 {
185 pass.bind_texture(VOLUME_SCATTERING_TEX_SLOT, &scattering_tx_);
187 }
189
190 /* Volume property buffers that are populated by objects or world volume shaders. */
191 struct {
193 gpu::Texture *scattering_tx_ = nullptr;
194 gpu::Texture *extinction_tx_ = nullptr;
198 gpu::Texture *occupancy_tx_ = nullptr;
199
200 template<typename PassType> void bind_resources(PassType &pass)
201 {
203 pass.bind_image(VOLUME_PROP_EXTINCTION_IMG_SLOT, &extinction_tx_);
205 pass.bind_image(VOLUME_PROP_PHASE_IMG_SLOT, &phase_tx_);
207 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
208 }
210
211 /* Textures used for object volume occupancy computation. */
212 struct {
214 gpu::Texture *occupancy_tx_ = nullptr;
215 gpu::Texture *hit_depth_tx_ = nullptr;
216 gpu::Texture *hit_count_tx_ = nullptr;
217
218 template<typename PassType> void bind_resources(PassType &pass)
219 {
220 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
221 pass.bind_image(VOLUME_HIT_DEPTH_SLOT, &hit_depth_tx_);
222 pass.bind_image(VOLUME_HIT_COUNT_SLOT, &hit_count_tx_);
223 }
225};
226} // namespace blender::eevee
static AppView * view
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition GPU_batch.hh:197
blender::gpu::Batch * GPU_batch_unit_cube() ATTR_WARN_UNUSED_RESULT
@ GPU_TEXTURE_USAGE_SHADER_READ
BMesh const char void * data
A running instance of the engine.
void object_sync(const ObjectHandle &ob_handle)
struct blender::eevee::VolumeModule::@272214251307377361251017233276127374325055261337 properties
void world_sync(const WorldHandle &world_handle)
struct blender::eevee::VolumeModule::@126173222355251033261272350101304070110072204326 occupancy
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
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3