Blender
V4.5
source
blender
draw
engines
eevee
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
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_shader_shared.hh
"
44
#include "
eevee_sync.hh
"
45
46
namespace
blender::eevee
{
47
48
class
Instance
;
49
class
VolumePipeline;
50
class
WorldVolumePipeline;
51
52
class
VolumeModule
{
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
129
~VolumeModule
()
130
{
131
GPU_BATCH_DISCARD_SAFE
(cube_batch_);
132
}
133
134
bool
needs_shadow_tagging
()
const
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
148
int3
grid_size
()
149
{
150
return
data_.
tex_size
;
151
}
152
153
gpu::Batch *
unit_cube_batch_get
()
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_
);
184
pass.bind_texture(
VOLUME_TRANSMITTANCE_TEX_SLOT
, &
transmittance_tx_
);
185
}
186
}
result
;
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
{
200
pass.bind_image(
VOLUME_PROP_SCATTERING_IMG_SLOT
, &
scattering_tx_
);
201
pass.bind_image(
VOLUME_PROP_EXTINCTION_IMG_SLOT
, &extinction_tx_);
202
pass.bind_image(
VOLUME_PROP_EMISSION_IMG_SLOT
, &
emission_tx_
);
203
pass.bind_image(
VOLUME_PROP_PHASE_IMG_SLOT
, &
phase_tx_
);
204
pass.bind_image(
VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT
, &
phase_weight_tx_
);
205
pass.bind_image(
VOLUME_OCCUPANCY_SLOT
, &occupancy_tx_);
206
}
207
}
properties
;
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
}
222
}
occupancy
;
223
};
224
}
// namespace blender::eevee
BLI_set.hh
data
std::string data
Definition
BLI_set_test.cc:632
DRW_gpu_wrapper.hh
view
static AppView * view
Definition
FRS_freestyle.cpp:59
GPU_BATCH_DISCARD_SAFE
#define GPU_BATCH_DISCARD_SAFE(batch)
Definition
GPU_batch.hh:204
GPU_batch_utils.hh
GPU_batch_unit_cube
blender::gpu::Batch * GPU_batch_unit_cube() ATTR_WARN_UNUSED_RESULT
Definition
gpu_batch_utils.cc:222
GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_SHADER_READ
Definition
GPU_texture.hh:769
GPU_RGBA8
@ GPU_RGBA8
Definition
GPU_texture.hh:653
blender::Set
Definition
BLI_set.hh:106
blender::draw::Framebuffer
Definition
DRW_gpu_wrapper.hh:1199
blender::draw::SwapChain
Definition
DRW_gpu_wrapper.hh:1290
blender::draw::Texture
Definition
DRW_gpu_wrapper.hh:525
blender::draw::Texture::ensure_3d
bool ensure_3d(eGPUTextureFormat format, int3 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
Definition
DRW_gpu_wrapper.hh:708
blender::draw::View
Definition
draw_view.hh:37
blender::draw::detail::Pass< command::DrawCommandBuf >
blender::eevee::Instance
A running instance of the engine.
Definition
eevee_instance.hh:75
blender::eevee::VolumeModule
Definition
eevee_volume.hh:52
blender::eevee::VolumeModule::unit_cube_batch_get
gpu::Batch * unit_cube_batch_get()
Definition
eevee_volume.hh:153
blender::eevee::VolumeModule::phase_weight_tx_
GPUTexture * phase_weight_tx_
Definition
eevee_volume.hh:195
blender::eevee::VolumeModule::transmittance_tx_
GPUTexture * transmittance_tx_
Definition
eevee_volume.hh:179
blender::eevee::VolumeModule::enabled
bool enabled() const
Definition
eevee_volume.hh:143
blender::eevee::VolumeModule::end_sync
void end_sync()
Definition
eevee_volume.cc:108
blender::eevee::VolumeModule::begin_sync
void begin_sync()
Definition
eevee_volume.cc:72
blender::eevee::VolumeModule::object_sync
void object_sync(const ObjectHandle &ob_handle)
Definition
eevee_volume.cc:89
blender::eevee::VolumeModule::properties
struct blender::eevee::VolumeModule::@180 properties
blender::eevee::VolumeModule::~VolumeModule
~VolumeModule()
Definition
eevee_volume.hh:129
blender::eevee::VolumeModule::phase_tx_
GPUTexture * phase_tx_
Definition
eevee_volume.hh:194
blender::eevee::VolumeModule::emission_tx_
GPUTexture * emission_tx_
Definition
eevee_volume.hh:193
blender::eevee::VolumeModule::init
void init()
Definition
eevee_volume.cc:24
blender::eevee::VolumeModule::needs_shadow_tagging
bool needs_shadow_tagging() const
Definition
eevee_volume.hh:134
blender::eevee::VolumeModule::world_sync
void world_sync(const WorldHandle &world_handle)
Definition
eevee_volume.cc:78
blender::eevee::VolumeModule::occupancy
struct blender::eevee::VolumeModule::@181 occupancy
blender::eevee::VolumeModule::grid_size
int3 grid_size()
Definition
eevee_volume.hh:148
blender::eevee::VolumeModule::result
struct blender::eevee::VolumeModule::@179 result
blender::eevee::VolumeModule::draw_resolve
void draw_resolve(View &view)
Definition
eevee_volume.cc:470
blender::eevee::VolumeModule::will_enable
bool will_enable() const
Definition
eevee_volume.cc:102
blender::eevee::VolumeModule::VolumeModule
VolumeModule(Instance &inst, VolumesInfoData &data)
Definition
eevee_volume.hh:123
blender::eevee::VolumeModule::draw_compute
void draw_compute(View &main_view, int2 extent)
Definition
eevee_volume.cc:438
blender::eevee::VolumeModule::scattering_tx_
GPUTexture * scattering_tx_
Definition
eevee_volume.hh:178
blender::eevee::VolumeModule::draw_prepass
void draw_prepass(View &main_view)
Definition
eevee_volume.cc:322
blender::eevee::VolumePipeline
Definition
eevee_pipeline.hh:484
blender::eevee::WorldVolumePipeline
Definition
eevee_pipeline.hh:86
VOLUME_PROP_SCATTERING_IMG_SLOT
#define VOLUME_PROP_SCATTERING_IMG_SLOT
Definition
eevee_defines.hh:226
VOLUME_HIT_DEPTH_SLOT
#define VOLUME_HIT_DEPTH_SLOT
Definition
eevee_defines.hh:233
VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT
#define VOLUME_PROP_PHASE_WEIGHT_IMG_SLOT
Definition
eevee_defines.hh:230
VOLUME_HIT_COUNT_SLOT
#define VOLUME_HIT_COUNT_SLOT
Definition
eevee_defines.hh:234
VOLUME_OCCUPANCY_SLOT
#define VOLUME_OCCUPANCY_SLOT
Definition
eevee_defines.hh:231
VOLUME_TRANSMITTANCE_TEX_SLOT
#define VOLUME_TRANSMITTANCE_TEX_SLOT
Definition
eevee_defines.hh:207
VOLUME_PROP_EXTINCTION_IMG_SLOT
#define VOLUME_PROP_EXTINCTION_IMG_SLOT
Definition
eevee_defines.hh:227
VOLUME_PROP_PHASE_IMG_SLOT
#define VOLUME_PROP_PHASE_IMG_SLOT
Definition
eevee_defines.hh:229
VOLUME_SCATTERING_TEX_SLOT
#define VOLUME_SCATTERING_TEX_SLOT
Definition
eevee_defines.hh:206
VOLUME_PROP_EMISSION_IMG_SLOT
#define VOLUME_PROP_EMISSION_IMG_SLOT
Definition
eevee_defines.hh:228
eevee_shader_shared.hh
eevee_sync.hh
PassType
PassType
Definition
kernel/types.h:488
blender::bke::AttrDomain::Instance
@ Instance
blender::eevee
Definition
eevee_ambient_occlusion.cc:29
blender::float4
VecBase< float, 4 > float4
Definition
BLI_math_vector_types.hh:620
blender::int3
VecBase< int32_t, 3 > int3
Definition
BLI_math_vector_types.hh:602
blender::MatBase< float, 4, 4 >
blender::MatBase< float, 4, 4 >::zero
static MatBase zero()
Definition
BLI_math_matrix_types.hh:455
blender::VecBase< int32_t, 3 >
blender::eevee::ObjectHandle
Definition
eevee_sync.hh:116
blender::eevee::VolumesInfoData
Definition
eevee_shader_shared.hh:658
blender::eevee::VolumesInfoData::tex_size
packed_int3 tex_size
Definition
eevee_shader_shared.hh:672
blender::eevee::WorldHandle
Definition
eevee_sync.hh:120
Generated on Fri Apr 3 2026 06:33:18 for Blender by
doxygen
1.11.0