Blender V4.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
36#pragma once
37
38#include "BLI_set.hh"
40
41namespace blender::eevee {
42
43class Instance;
44class VolumePipeline;
45class WorldVolumePipeline;
46
48 friend VolumePipeline;
50
51 private:
52 Instance &inst_;
53
54 bool enabled_;
55 bool use_reprojection_;
56 bool use_lights_;
57
58 /* Track added/removed volume objects to reset the accumulation history. */
59 Set<ObjectKey> previous_objects_;
60 Set<ObjectKey> current_objects_;
61
62 VolumesInfoData &data_;
63
69 Texture occupancy_tx_ = {"occupancy_tx"};
75 Texture hit_count_tx_ = {"hit_count_tx"};
76 Texture hit_depth_tx_ = {"hit_depth_tx"};
77 Texture front_depth_tx_ = {"front_depth_tx"};
78 Framebuffer occupancy_fb_ = {"occupancy_fb"};
79
80 /* Material Parameters */
81 Texture prop_scattering_tx_;
82 Texture prop_extinction_tx_;
83 Texture prop_emission_tx_;
84 Texture prop_phase_tx_;
85 Texture prop_phase_weight_tx_;
86
87 /* Light Scattering. */
88 PassSimple scatter_ps_ = {"Volumes.Scatter"};
89 SwapChain<Texture, 2> scatter_tx_;
90 SwapChain<Texture, 2> extinction_tx_;
91
92 /* Volume Integration */
93 PassSimple integration_ps_ = {"Volumes.Integration"};
94 Texture integrated_scatter_tx_;
95 Texture integrated_transmit_tx_;
96
97 /* Full-screen Resolve */
98 PassSimple resolve_ps_ = {"Volumes.Resolve"};
99 Framebuffer resolve_fb_;
100
101 Texture dummy_scatter_tx_;
102 Texture dummy_transmit_tx_;
103
104 View volume_view = {"Volume View"};
105
106 float4x4 history_viewmat_ = float4x4::zero();
107 /* Number of re-projected frame into the volume history.
108 * Allows continuous integration between interactive and static mode. */
109 int history_frame_count_ = 0;
110 /* Used to detect change in camera projection type. */
111 bool history_camera_is_perspective_ = false;
112 /* Must be set to false on every event that makes the history invalid to sample. */
113 bool valid_history_ = false;
114
115 public:
116 VolumeModule(Instance &inst, VolumesInfoData &data) : inst_(inst), data_(data)
117 {
118 dummy_scatter_tx_.ensure_3d(GPU_RGBA8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(0.0f));
119 dummy_transmit_tx_.ensure_3d(GPU_RGBA8, int3(1), GPU_TEXTURE_USAGE_SHADER_READ, float4(1.0f));
120 };
121
123
125 {
126 return enabled_ && use_lights_;
127 }
128
129 bool enabled() const
130 {
131 return enabled_;
132 }
133
135 {
136 return data_.tex_size;
137 }
138
139 void init();
140
141 void begin_sync();
142
143 void world_sync(const WorldHandle &world_handle);
144
145 void object_sync(const ObjectHandle &ob_handle);
146
147 void end_sync();
148
149 /* Render material properties. */
150 void draw_prepass(View &main_view);
151 /* Compute scattering and integration. */
152 void draw_compute(View &main_view, int2 extent);
153 /* Final image compositing. */
154 void draw_resolve(View &view);
155
156 /* Final occupancy after resolve. Used by object volume material evaluation. */
157 struct {
159 GPUTexture *scattering_tx_ = nullptr;
160 GPUTexture *transmittance_tx_ = nullptr;
161
162 template<typename PassType> void bind_resources(PassType &pass)
163 {
164 pass.bind_texture(VOLUME_SCATTERING_TEX_SLOT, &scattering_tx_);
166 }
168
169 /* Volume property buffers that are populated by objects or world volume shaders. */
170 struct {
172 GPUTexture *scattering_tx_ = nullptr;
173 GPUTexture *extinction_tx_ = nullptr;
174 GPUTexture *emission_tx_ = nullptr;
175 GPUTexture *phase_tx_ = nullptr;
176 GPUTexture *phase_weight_tx_ = nullptr;
177 GPUTexture *occupancy_tx_ = nullptr;
178
179 template<typename PassType> void bind_resources(PassType &pass)
180 {
182 pass.bind_image(VOLUME_PROP_EXTINCTION_IMG_SLOT, &extinction_tx_);
184 pass.bind_image(VOLUME_PROP_PHASE_IMG_SLOT, &phase_tx_);
186 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
187 }
189
190 /* Textures used for object volume occupancy computation. */
191 struct {
193 GPUTexture *occupancy_tx_ = nullptr;
194 GPUTexture *hit_depth_tx_ = nullptr;
195 GPUTexture *hit_count_tx_ = nullptr;
196
197 template<typename PassType> void bind_resources(PassType &pass)
198 {
199 pass.bind_image(VOLUME_OCCUPANCY_SLOT, &occupancy_tx_);
200 pass.bind_image(VOLUME_HIT_DEPTH_SLOT, &hit_depth_tx_);
201 pass.bind_image(VOLUME_HIT_COUNT_SLOT, &hit_count_tx_);
202 }
204};
205} // namespace blender::eevee
@ GPU_TEXTURE_USAGE_SHADER_READ
bool ensure_3d(eGPUTextureFormat format, int3 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
A running instance of the engine.
struct blender::eevee::VolumeModule::@197 properties
void object_sync(const ObjectHandle &ob_handle)
struct blender::eevee::VolumeModule::@198 occupancy
void world_sync(const WorldHandle &world_handle)
struct blender::eevee::VolumeModule::@196 result
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
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
PassType
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3