Blender V4.5
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
44#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(GPU_RGBA8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(0.0f));
126 dummy_transmit_tx_.ensure_3d(GPU_RGBA8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(1.0f));
127 };
128
130 {
131 GPU_BATCH_DISCARD_SAFE(cube_batch_);
132 }
133
135 {
136 return enabled_ && use_lights_;
137 }
138
139 /* Return a the future value of enabled() that will only be available after end_sync(). */
140 bool will_enable() const;
141
142 /* Returns the state of the module. */
143 bool enabled() const
144 {
145 return enabled_;
146 }
147
149 {
150 return data_.tex_size;
151 }
152
154 {
155 return cube_batch_;
156 }
157
158 void init();
159
160 void begin_sync();
161
162 void world_sync(const WorldHandle &world_handle);
163
164 void object_sync(const ObjectHandle &ob_handle);
165
166 void end_sync();
167
168 /* Render material properties. */
169 void draw_prepass(View &main_view);
170 /* Compute scattering and integration. */
171 void draw_compute(View &main_view, int2 extent);
172 /* Final image compositing. */
173 void draw_resolve(View &view);
174
175 /* Final occupancy after resolve. Used by object volume material evaluation. */
176 struct {
178 GPUTexture *scattering_tx_ = nullptr;
179 GPUTexture *transmittance_tx_ = nullptr;
180
181 template<typename PassType> void bind_resources(PassType &pass)
182 {
183 pass.bind_texture(VOLUME_SCATTERING_TEX_SLOT, &scattering_tx_);
185 }
187
188 /* Volume property buffers that are populated by objects or world volume shaders. */
189 struct {
191 GPUTexture *scattering_tx_ = nullptr;
192 GPUTexture *extinction_tx_ = nullptr;
193 GPUTexture *emission_tx_ = nullptr;
194 GPUTexture *phase_tx_ = nullptr;
195 GPUTexture *phase_weight_tx_ = nullptr;
196 GPUTexture *occupancy_tx_ = nullptr;
197
198 template<typename PassType> void bind_resources(PassType &pass)
199 {
201 pass.bind_image(VOLUME_PROP_EXTINCTION_IMG_SLOT, &extinction_tx_);
203 pass.bind_image(VOLUME_PROP_PHASE_IMG_SLOT, &phase_tx_);
205 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
206 }
208
209 /* Textures used for object volume occupancy computation. */
210 struct {
212 GPUTexture *occupancy_tx_ = nullptr;
213 GPUTexture *hit_depth_tx_ = nullptr;
214 GPUTexture *hit_count_tx_ = nullptr;
215
216 template<typename PassType> void bind_resources(PassType &pass)
217 {
218 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
219 pass.bind_image(VOLUME_HIT_DEPTH_SLOT, &hit_depth_tx_);
220 pass.bind_image(VOLUME_HIT_COUNT_SLOT, &hit_count_tx_);
221 }
223};
224} // namespace blender::eevee
static AppView * view
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition GPU_batch.hh:204
blender::gpu::Batch * GPU_batch_unit_cube() ATTR_WARN_UNUSED_RESULT
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_RGBA8
BMesh const char void * data
A running instance of the engine.
void object_sync(const ObjectHandle &ob_handle)
void world_sync(const WorldHandle &world_handle)
struct blender::eevee::VolumeModule::@030347014150317244360374313350232105127012310334 properties
VolumeModule(Instance &inst, VolumesInfoData &data)
struct blender::eevee::VolumeModule::@140144253302200125303021230030333304124317361114 occupancy
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