Blender  V3.3
eevee_volumes.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 Blender Foundation. */
3 
10 #include "DRW_render.h"
11 
12 #include "BLI_listbase.h"
13 #include "BLI_rand.h"
14 #include "BLI_string_utils.h"
15 
16 #include "DNA_fluid_types.h"
17 #include "DNA_object_force_types.h"
18 #include "DNA_volume_types.h"
19 #include "DNA_world_types.h"
20 
21 #include "BKE_fluid.h"
22 #include "BKE_global.h"
23 #include "BKE_mesh.h"
24 #include "BKE_modifier.h"
25 #include "BKE_volume.h"
26 #include "BKE_volume_render.h"
27 
28 #include "ED_screen.h"
29 
30 #include "DEG_depsgraph_query.h"
31 
32 #include "GPU_capabilities.h"
33 #include "GPU_material.h"
34 #include "GPU_texture.h"
35 #include "eevee_private.h"
36 
37 static struct {
39 
43 
46 } e_data = {NULL}; /* Engine data */
47 
48 void EEVEE_volumes_set_jitter(EEVEE_ViewLayerData *sldata, uint current_sample)
49 {
50  EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
51 
52  double ht_point[3];
53  double ht_offset[3] = {0.0, 0.0};
54  const uint ht_primes[3] = {3, 7, 2};
55 
56  BLI_halton_3d(ht_primes, ht_offset, current_sample, ht_point);
57 
58  common_data->vol_jitter[0] = (float)ht_point[0];
59  common_data->vol_jitter[1] = (float)ht_point[1];
60  common_data->vol_jitter[2] = (float)ht_point[2];
61 }
62 
64 {
65  EEVEE_StorageList *stl = vedata->stl;
66  EEVEE_FramebufferList *fbl = vedata->fbl;
67  EEVEE_TextureList *txl = vedata->txl;
68  EEVEE_EffectsInfo *effects = stl->effects;
69  EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
70 
71  const DRWContextState *draw_ctx = DRW_context_state_get();
72  const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph);
73 
74  const float *viewport_size = DRW_viewport_size_get();
75 
76  const int tile_size = scene_eval->eevee.volumetric_tile_size;
77 
78  /* Find Froxel Texture resolution. */
79  int tex_size[3];
80 
81  tex_size[0] = (int)ceilf(fmaxf(1.0f, viewport_size[0] / (float)tile_size));
82  tex_size[1] = (int)ceilf(fmaxf(1.0f, viewport_size[1] / (float)tile_size));
83  tex_size[2] = max_ii(scene_eval->eevee.volumetric_samples, 1);
84 
85  common_data->vol_coord_scale[0] = viewport_size[0] / (float)(tile_size * tex_size[0]);
86  common_data->vol_coord_scale[1] = viewport_size[1] / (float)(tile_size * tex_size[1]);
87  common_data->vol_coord_scale[2] = 1.0f / viewport_size[0];
88  common_data->vol_coord_scale[3] = 1.0f / viewport_size[1];
89 
90  /* TODO: compute snap to maxZBuffer for clustered rendering. */
91  if ((common_data->vol_tex_size[0] != tex_size[0]) ||
92  (common_data->vol_tex_size[1] != tex_size[1]) ||
93  (common_data->vol_tex_size[2] != tex_size[2])) {
102  GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_fb);
103  GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_scat_fb);
104  GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_integ_fb);
105  copy_v3_v3_int(common_data->vol_tex_size, tex_size);
106 
107  common_data->vol_inv_tex_size[0] = 1.0f / (float)(tex_size[0]);
108  common_data->vol_inv_tex_size[1] = 1.0f / (float)(tex_size[1]);
109  common_data->vol_inv_tex_size[2] = 1.0f / (float)(tex_size[2]);
110  }
111 
112  /* Like frostbite's paper, 5% blend of the new frame. */
113  common_data->vol_history_alpha = (txl->volume_prop_scattering == NULL) ? 0.0f : 0.95f;
114 
115  /* Temporal Super sampling jitter */
116  uint ht_primes[3] = {3, 7, 2};
117  uint current_sample = 0;
118 
119  /* If TAA is in use do not use the history buffer. */
120  bool do_taa = ((effects->enabled_effects & EFFECT_TAA) != 0);
121 
122  if (draw_ctx->evil_C != NULL) {
123  struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
124  do_taa = do_taa && (ED_screen_animation_no_scrub(wm) == NULL);
125  }
126 
127  if (do_taa) {
128  common_data->vol_history_alpha = 0.0f;
129  current_sample = effects->taa_current_sample - 1;
130  effects->volume_current_sample = -1;
131  }
132  else if (DRW_state_is_image_render()) {
133  const uint max_sample = (ht_primes[0] * ht_primes[1] * ht_primes[2]);
134  current_sample = effects->volume_current_sample = (effects->volume_current_sample + 1) %
135  max_sample;
136  if (current_sample != max_sample - 1) {
138  }
139  }
140 
141  EEVEE_volumes_set_jitter(sldata, current_sample);
142 
143  float integration_start = scene_eval->eevee.volumetric_start;
144  float integration_end = scene_eval->eevee.volumetric_end;
145  effects->volume_light_clamp = scene_eval->eevee.volumetric_light_clamp;
146  common_data->vol_shadow_steps = (float)scene_eval->eevee.volumetric_shadow_samples;
147  if ((scene_eval->eevee.flag & SCE_EEVEE_VOLUMETRIC_SHADOWS) == 0) {
148  common_data->vol_shadow_steps = 0;
149  }
150 
152  float sample_distribution = scene_eval->eevee.volumetric_sample_distribution;
153  sample_distribution = 4.0f * (max_ff(1.0f - sample_distribution, 1e-2f));
154 
155  const float clip_start = DRW_view_near_distance_get(NULL);
156  /* Negate */
157  float near = integration_start = min_ff(-integration_start, clip_start - 1e-4f);
158  float far = integration_end = min_ff(-integration_end, near - 1e-4f);
159 
160  common_data->vol_depth_param[0] = (far - near * exp2(1.0f / sample_distribution)) /
161  (far - near);
162  common_data->vol_depth_param[1] = (1.0f - common_data->vol_depth_param[0]) / near;
163  common_data->vol_depth_param[2] = sample_distribution;
164  }
165  else {
166  const float clip_start = DRW_view_near_distance_get(NULL);
167  const float clip_end = DRW_view_far_distance_get(NULL);
168  integration_start = min_ff(integration_end, clip_start);
169  integration_end = max_ff(-integration_end, clip_end);
170 
171  common_data->vol_depth_param[0] = integration_start;
172  common_data->vol_depth_param[1] = integration_end;
173  common_data->vol_depth_param[2] = 1.0f / (integration_end - integration_start);
174  }
175 
176  /* Disable clamp if equal to 0. */
177  if (effects->volume_light_clamp == 0.0) {
178  effects->volume_light_clamp = FLT_MAX;
179  }
180 
181  common_data->vol_use_lights = (scene_eval->eevee.flag & SCE_EEVEE_VOLUMETRIC_LIGHTS) != 0;
182  common_data->vol_use_soft_shadows = (scene_eval->eevee.flag & SCE_EEVEE_SHADOW_SOFT) != 0;
183 
184  if (!e_data.dummy_scatter) {
185  const float scatter[4] = {0.0f, 0.0f, 0.0f, 0.0f};
186  const float transmit[4] = {1.0f, 1.0f, 1.0f, 1.0f};
187  e_data.dummy_scatter = DRW_texture_create_3d(1, 1, 1, GPU_RGBA8, DRW_TEX_WRAP, scatter);
188  e_data.dummy_transmit = DRW_texture_create_3d(1, 1, 1, GPU_RGBA8, DRW_TEX_WRAP, transmit);
189  }
190 }
191 
193 {
194  EEVEE_PassList *psl = vedata->psl;
195  EEVEE_StorageList *stl = vedata->stl;
196  EEVEE_EffectsInfo *effects = stl->effects;
197  EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
198 
199  const DRWContextState *draw_ctx = DRW_context_state_get();
200  Scene *scene = draw_ctx->scene;
201  DRWShadingGroup *grp = NULL;
202 
203  /* Quick breakdown of the Volumetric rendering:
204  *
205  * The rendering is separated in 4 stages:
206  *
207  * - Material Parameters : we collect volume properties of
208  * all participating media in the scene and store them in
209  * a 3D texture aligned with the 3D frustum.
210  * This is done in 2 passes, one that clear the texture
211  * and/or evaluate the world volumes, and the 2nd one that
212  * additively render object volumes.
213  *
214  * - Light Scattering : the volume properties then are sampled
215  * and light scattering is evaluated for each cell of the
216  * volume texture. Temporal super-sampling (if enabled) occurs here.
217  *
218  * - Volume Integration : the scattered light and extinction is
219  * integrated (accumulated) along the view-rays. The result is stored
220  * for every cell in another texture.
221  *
222  * - Full-screen Resolve : From the previous stage, we get two
223  * 3D textures that contains integrated scattered light and extinction
224  * for "every" positions in the frustum. We only need to sample
225  * them and blend the scene color with those factors. This also
226  * work for alpha blended materials.
227  */
228 
229  /* World pass is not additive as it also clear the buffer. */
232 
233  /* World Volumetric */
234  struct World *wo = scene->world;
235  if (wo != NULL && wo->use_nodes && wo->nodetree &&
236  !LOOK_DEV_STUDIO_LIGHT_ENABLED(draw_ctx->v3d)) {
237  struct GPUMaterial *mat = EEVEE_material_get(vedata, scene, NULL, wo, VAR_MAT_VOLUME);
238 
239  if (mat && GPU_material_has_volume_output(mat)) {
241  }
242 
243  if (grp) {
244  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
245  /* TODO(fclem): remove those (need to clean the GLSL files). */
246  DRW_shgroup_uniform_block(grp, "grid_block", sldata->grid_ubo);
247  DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
248  DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
249  DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
250  DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
251  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
252 
253  /* Fix principle volumetric not working with world materials. */
254  grp = DRW_shgroup_volume_create_sub(NULL, NULL, grp, mat);
255 
257 
259  }
260  }
261 
262  if (grp == NULL) {
263  /* If no world or volume material is present just clear the buffer with this drawcall */
265  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
266  DRW_shgroup_uniform_block(grp, "grid_block", sldata->grid_ubo);
267  DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
268  DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
269  DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
270  DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
271  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
272 
274  }
275 }
276 
278  EEVEE_Data *vedata,
279  Scene *scene,
280  Object *ob)
281 {
283 
284  if (ma == NULL) {
285  if (ob->type == OB_VOLUME) {
287  }
288  else {
289  return;
290  }
291  }
292 
293  float size[3];
294  mat4_to_size(size, ob->obmat);
295  /* Check if any of the axes have 0 length. (see T69070) */
296  const float epsilon = 1e-8f;
297  if ((size[0] < epsilon) || (size[1] < epsilon) || (size[2] < epsilon)) {
298  return;
299  }
300 
301  int mat_options = VAR_MAT_VOLUME | VAR_MAT_MESH;
302  struct GPUMaterial *mat = EEVEE_material_get(vedata, scene, ma, NULL, mat_options);
303 
304  /* If shader failed to compile or is currently compiling. */
305  if (mat == NULL) {
306  return;
307  }
308 
310  if (sh == NULL) {
311  return;
312  }
313 
314  /* TODO(fclem): Reuse main shading group to avoid shading binding cost just like for surface
315  * shaders. */
317 
318  grp = DRW_shgroup_volume_create_sub(scene, ob, grp, mat);
319 
320  if (grp == NULL) {
321  return;
322  }
323 
325 
326  /* TODO(fclem): remove those "unnecessary" UBOs */
327  DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
328  DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
329  DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
330  DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
331  DRW_shgroup_uniform_block(grp, "grid_block", sldata->grid_ubo);
332  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
333  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
334  /* TODO: Reduce to number of slices intersecting. */
335  /* TODO: Preemptive culling. */
337 
339 }
340 
342 {
343  EEVEE_PassList *psl = vedata->psl;
344  EEVEE_TextureList *txl = vedata->txl;
345  EEVEE_EffectsInfo *effects = vedata->stl->effects;
346  LightCache *lcache = vedata->stl->g_data->light_cache;
347  EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
348 
349  if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
350  DRWShadingGroup *grp;
351  struct GPUShader *sh;
352 
357  DRW_shgroup_uniform_texture_ref(grp, "irradianceGrid", &lcache->grid_tx.tex);
358  DRW_shgroup_uniform_texture_ref(grp, "shadowCubeTexture", &sldata->shadow_cube_pool);
359  DRW_shgroup_uniform_texture_ref(grp, "shadowCascadeTexture", &sldata->shadow_cascade_pool);
360  DRW_shgroup_uniform_texture_ref(grp, "volumeScattering", &txl->volume_prop_scattering);
361  DRW_shgroup_uniform_texture_ref(grp, "volumeExtinction", &txl->volume_prop_extinction);
362  DRW_shgroup_uniform_texture_ref(grp, "volumeEmission", &txl->volume_prop_emission);
363  DRW_shgroup_uniform_texture_ref(grp, "volumePhase", &txl->volume_prop_phase);
364  DRW_shgroup_uniform_texture_ref(grp, "historyScattering", &txl->volume_scatter_history);
365  DRW_shgroup_uniform_texture_ref(grp, "historyTransmittance", &txl->volume_transmit_history);
366  DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
367  DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
368  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
369  DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
370  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
371 
373 
377  DRW_shgroup_uniform_texture_ref(grp, "volumeScattering", &txl->volume_scatter);
378  DRW_shgroup_uniform_texture_ref(grp, "volumeExtinction", &txl->volume_transmit);
379  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
380  DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
381  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
382  if (USE_VOLUME_OPTI) {
383  DRW_shgroup_uniform_image_ref(grp, "finalScattering_img", &txl->volume_scatter_history);
384  DRW_shgroup_uniform_image_ref(grp, "finalTransmittance_img", &txl->volume_transmit_history);
385  }
386 
388  grp, NULL, USE_VOLUME_OPTI ? 1 : common_data->vol_tex_size[2]);
389 
392  psl->volumetric_resolve_ps);
393  DRW_shgroup_uniform_texture_ref(grp, "inScattering", &txl->volume_scatter);
394  DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &txl->volume_transmit);
395  DRW_shgroup_uniform_texture_ref(grp, "inSceneDepth", &e_data.depth_src);
396  DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
397  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
398  DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
399  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
400  DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
401 
403  }
404 }
405 
407 {
408  EEVEE_FramebufferList *fbl = vedata->fbl;
409  EEVEE_TextureList *txl = vedata->txl;
410  EEVEE_EffectsInfo *effects = vedata->stl->effects;
411  EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
412 
413  if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
414  int *tex_size = common_data->vol_tex_size;
415 
416  if (txl->volume_prop_scattering == NULL) {
417  /* Volume properties: We evaluate all volumetric objects
418  * and store their final properties into each froxel */
420  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
422  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
424  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
426  tex_size[0], tex_size[1], tex_size[2], GPU_RG16F, DRW_TEX_FILTER, NULL);
427 
428  /* Volume scattering: We compute for each froxel the
429  * Scattered light towards the view. We also resolve temporal
430  * super sampling during this stage. */
432  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
434  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
435 
436  /* Final integration: We compute for each froxel the
437  * amount of scattered light and extinction coef at this
438  * given depth. We use these textures as double buffer
439  * for the volumetric history. */
441  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
443  tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
444  }
445 
446  GPU_framebuffer_ensure_config(&fbl->volumetric_fb,
447  {GPU_ATTACHMENT_NONE,
448  GPU_ATTACHMENT_TEXTURE(txl->volume_prop_scattering),
449  GPU_ATTACHMENT_TEXTURE(txl->volume_prop_extinction),
450  GPU_ATTACHMENT_TEXTURE(txl->volume_prop_emission),
451  GPU_ATTACHMENT_TEXTURE(txl->volume_prop_phase)});
452  GPU_framebuffer_ensure_config(&fbl->volumetric_scat_fb,
453  {GPU_ATTACHMENT_NONE,
454  GPU_ATTACHMENT_TEXTURE(txl->volume_scatter),
455  GPU_ATTACHMENT_TEXTURE(txl->volume_transmit)});
456  GPU_framebuffer_ensure_config(&fbl->volumetric_integ_fb,
457  {GPU_ATTACHMENT_NONE,
458  GPU_ATTACHMENT_TEXTURE(txl->volume_scatter_history),
459  GPU_ATTACHMENT_TEXTURE(txl->volume_transmit_history)});
460  }
461  else {
470  GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_fb);
471  GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_scat_fb);
472  GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_integ_fb);
473  }
474 
475  effects->volume_scatter = e_data.dummy_scatter;
476  effects->volume_transmit = e_data.dummy_transmit;
477 }
478 
480 {
481  EEVEE_PassList *psl = vedata->psl;
482  EEVEE_TextureList *txl = vedata->txl;
483  EEVEE_FramebufferList *fbl = vedata->fbl;
484  EEVEE_StorageList *stl = vedata->stl;
485  EEVEE_EffectsInfo *effects = stl->effects;
486  if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
487  DRW_stats_group_start("Volumetrics");
488 
489  /* We sample the shadow-maps using shadow sampler. We need to enable Comparison mode.
490  * TODO(fclem): avoid this by using sampler objects. */
493 
497 
500 
501  if (USE_VOLUME_OPTI) {
502  /* Avoid feedback loop assert. */
504  }
505  else {
507  }
508 
510 
514 
515  effects->volume_scatter = txl->volume_scatter;
516  effects->volume_transmit = txl->volume_transmit;
517 
518  /* Restore */
520 
522  }
523 }
524 
526 {
527  EEVEE_PassList *psl = vedata->psl;
528  EEVEE_FramebufferList *fbl = vedata->fbl;
529  EEVEE_StorageList *stl = vedata->stl;
530  EEVEE_EffectsInfo *effects = stl->effects;
531 
532  if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
534  e_data.depth_src = dtxl->depth;
535 
536  if (USE_VOLUME_OPTI) {
538  }
539 
540  /* Apply for opaque geometry. */
543 
544  /* Restore. */
546  }
547 }
548 
550 {
551  DRW_TEXTURE_FREE_SAFE(e_data.dummy_scatter);
552  DRW_TEXTURE_FREE_SAFE(e_data.dummy_transmit);
553 
554  DRW_TEXTURE_FREE_SAFE(e_data.dummy_zero);
555  DRW_TEXTURE_FREE_SAFE(e_data.dummy_one);
556  DRW_TEXTURE_FREE_SAFE(e_data.dummy_flame);
557 }
558 
559 /* -------------------------------------------------------------------- */
564 {
565  EEVEE_FramebufferList *fbl = vedata->fbl;
566  EEVEE_TextureList *txl = vedata->txl;
567  EEVEE_StorageList *stl = vedata->stl;
568  EEVEE_PassList *psl = vedata->psl;
569  EEVEE_EffectsInfo *effects = stl->effects;
570 
571  /* Create FrameBuffer. */
572 
573  /* Should be enough precision for many samples. */
574  const eGPUTextureFormat texture_format_accum = (tot_samples > 128) ? GPU_RGBA32F : GPU_RGBA16F;
575  DRW_texture_ensure_fullscreen_2d(&txl->volume_scatter_accum, texture_format_accum, 0);
576  DRW_texture_ensure_fullscreen_2d(&txl->volume_transmittance_accum, texture_format_accum, 0);
577 
578  GPU_framebuffer_ensure_config(&fbl->volumetric_accum_fb,
579  {GPU_ATTACHMENT_NONE,
580  GPU_ATTACHMENT_TEXTURE(txl->volume_scatter_accum),
581  GPU_ATTACHMENT_TEXTURE(txl->volume_transmittance_accum)});
582 
583  /* Create Pass and shgroup. */
585  DRWShadingGroup *grp = NULL;
586  if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
588  DRW_shgroup_uniform_texture_ref(grp, "inScattering", &txl->volume_scatter);
589  DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &txl->volume_transmit);
590  DRW_shgroup_uniform_texture_ref(grp, "inSceneDepth", &e_data.depth_src);
591  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
592  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
593  }
594  else {
595  /* There is no volumetrics in the scene. Use a shader to fill the accum textures with a default
596  * value. */
598  }
600 }
601 
603 {
604  EEVEE_FramebufferList *fbl = vedata->fbl;
605  EEVEE_PassList *psl = vedata->psl;
606  EEVEE_EffectsInfo *effects = vedata->stl->effects;
607 
608  if (fbl->volumetric_accum_fb != NULL) {
609  /* Accum pass */
611 
612  /* Clear texture. */
613  if (effects->taa_current_sample == 1) {
614  const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
615  GPU_framebuffer_clear_color(fbl->volumetric_accum_fb, clear);
616  }
617 
619 
620  /* Restore */
622  }
623 }
624 
typedef float(TangentPoint)[2]
struct wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct Material * BKE_object_material_get_eval(struct Object *ob, short act)
Definition: material.c:707
struct Material * BKE_material_default_volume(void)
Definition: material.c:2056
Volume data-block.
Volume data-block rendering and viewport drawing utilities.
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
void mat4_to_size(float size[3], const float M[4][4])
Definition: math_matrix.c:2138
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
Random number functions.
void BLI_halton_3d(const unsigned int prime[3], double offset[3], int n, double *r)
Definition: rand.cc:311
unsigned int uint
Definition: BLI_sys_types.h:67
#define SWAP(type, a, b)
#define UNUSED(x)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
@ OB_VOLUME
@ SCE_EEVEE_VOLUMETRIC_SHADOWS
@ SCE_EEVEE_SHADOW_SOFT
@ SCE_EEVEE_VOLUMETRIC_LIGHTS
@ DRW_TEX_WRAP
Definition: DRW_render.h:141
@ DRW_TEX_FILTER
Definition: DRW_render.h:140
@ DRW_STATE_BLEND_ADD
Definition: DRW_render.h:324
@ DRW_STATE_BLEND_ADD_FULL
Definition: DRW_render.h:326
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
@ DRW_STATE_BLEND_CUSTOM
Definition: DRW_render.h:336
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:690
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
Definition: DRW_render.h:651
#define DRW_shgroup_call(shgroup, geom, ob)
Definition: DRW_render.h:414
#define DRW_TEXTURE_FREE_SAFE(tex)
Definition: DRW_render.h:183
bScreen * ED_screen_animation_no_scrub(const struct wmWindowManager *wm)
struct GPUFrameBuffer GPUFrameBuffer
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUShader * GPU_material_get_shader(GPUMaterial *material)
Definition: gpu_material.c:191
bool GPU_material_has_volume_output(GPUMaterial *mat)
Definition: gpu_material.c:591
struct GPUShader GPUShader
Definition: GPU_shader.h:20
void GPU_memory_barrier(eGPUBarrier barrier)
Definition: gpu_state.cc:371
@ GPU_BARRIER_TEXTURE_FETCH
Definition: GPU_state.h:30
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
Definition: gpu_texture.cc:510
eGPUTextureFormat
Definition: GPU_texture.h:83
@ GPU_RG16F
Definition: GPU_texture.h:103
@ GPU_RGBA32F
Definition: GPU_texture.h:90
@ GPU_R11F_G11F_B10F
Definition: GPU_texture.h:118
@ GPU_RGBA8
Definition: GPU_texture.h:87
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
Scene scene
GPUBatch * DRW_cache_fullscreen_quad_get(void)
Definition: draw_cache.c:356
struct DRWShadingGroup * DRW_shgroup_volume_create_sub(struct Scene *scene, struct Object *ob, struct DRWShadingGroup *shgrp, struct GPUMaterial *gpu_material)
Definition: draw_volume.cc:260
const DRWContextState * DRW_context_state_get(void)
const float * DRW_viewport_size_get(void)
Definition: draw_manager.c:288
bool DRW_state_is_image_render(void)
void DRW_viewport_request_redraw(void)
Definition: draw_manager.c:643
DefaultTextureList * DRW_viewport_texture_list_get(void)
Definition: draw_manager.c:638
DRWShadingGroup * DRW_shgroup_material_create(struct GPUMaterial *material, DRWPass *pass)
float DRW_view_near_distance_get(const DRWView *view)
bool DRW_view_is_persp_get(const DRWView *view)
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, Object *ob, uint tri_count)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
float DRW_view_far_distance_get(const DRWView *view)
void DRW_shgroup_add_material_resources(DRWShadingGroup *grp, struct GPUMaterial *material)
void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
void DRW_shgroup_uniform_image_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
void DRW_draw_pass(DRWPass *pass)
void DRW_stats_group_start(const char *name)
void DRW_stats_group_end(void)
GPUTexture * DRW_texture_create_3d(int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
void DRW_texture_ensure_fullscreen_2d(GPUTexture **tex, eGPUTextureFormat format, DRWTextureFlag flags)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
@ VAR_MAT_VOLUME
@ VAR_MAT_MESH
#define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d)
struct GPUShader * EEVEE_shaders_volumes_scatter_sh_get(void)
struct GPUShader * EEVEE_shaders_volumes_integration_sh_get(void)
struct GPUShader * EEVEE_shaders_volumes_accum_sh_get(void)
@ EFFECT_POST_BUFFER
@ EFFECT_TAA
@ EFFECT_VOLUMETRIC
#define USE_VOLUME_OPTI
Definition: eevee_private.h:75
struct GPUMaterial * EEVEE_material_get(EEVEE_Data *vedata, struct Scene *scene, Material *ma, World *wo, int options)
struct GPUShader * EEVEE_shaders_volumes_scatter_with_lights_sh_get(void)
struct GPUShader * EEVEE_shaders_volumes_clear_sh_get(void)
struct GPUShader * EEVEE_shaders_volumes_resolve_sh_get(bool accum)
void EEVEE_volumes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
void EEVEE_volumes_set_jitter(EEVEE_ViewLayerData *sldata, uint current_sample)
Definition: eevee_volumes.c:48
void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
void EEVEE_volumes_free(void)
void EEVEE_volumes_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
static struct @215 e_data
GPUTexture * dummy_scatter
Definition: eevee_volumes.c:44
GPUTexture * depth_src
Definition: eevee_volumes.c:38
GPUTexture * dummy_zero
Definition: eevee_volumes.c:40
GPUTexture * dummy_one
Definition: eevee_volumes.c:41
void EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
Definition: eevee_volumes.c:63
void EEVEE_volumes_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples)
void EEVEE_volumes_resolve(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
GPUTexture * dummy_transmit
Definition: eevee_volumes.c:45
GPUTexture * dummy_flame
Definition: eevee_volumes.c:42
void EEVEE_volumes_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Scene *scene, Object *ob)
void EEVEE_volumes_draw_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
ccl_gpu_kernel_postfix ccl_global float int int int int sh
#define fmaxf(x, y)
Definition: metal/compat.h:228
#define ceilf(x)
Definition: metal/compat.h:225
static void clear(Message *msg)
Definition: msgfmt.c:278
static double epsilon
struct Scene * scene
Definition: DRW_render.h:979
const struct bContext * evil_C
Definition: DRW_render.h:997
struct Depsgraph * depsgraph
Definition: DRW_render.h:987
struct View3D * v3d
Definition: DRW_render.h:976
struct GPUTexture * depth
EEVEE_TextureList * txl
EEVEE_StorageList * stl
EEVEE_PassList * psl
EEVEE_FramebufferList * fbl
struct GPUTexture * volume_transmit
struct GPUTexture * volume_scatter
EEVEE_EffectsFlag enabled_effects
struct GPUFrameBuffer * volumetric_fb
struct GPUFrameBuffer * main_fb
struct GPUFrameBuffer * volumetric_scat_fb
struct GPUFrameBuffer * volumetric_integ_fb
struct GPUFrameBuffer * main_color_fb
struct GPUFrameBuffer * volumetric_accum_fb
struct DRWPass * volumetric_objects_ps
struct DRWPass * volumetric_integration_ps
struct DRWPass * volumetric_world_ps
struct DRWPass * volumetric_scatter_ps
struct DRWPass * volumetric_resolve_ps
struct DRWPass * volumetric_accum_ps
struct LightCache * light_cache
struct EEVEE_PrivateData * g_data
struct EEVEE_EffectsInfo * effects
struct GPUTexture * volume_scatter_history
struct GPUTexture * volume_prop_extinction
struct GPUTexture * volume_scatter_accum
struct GPUTexture * volume_transmittance_accum
struct GPUTexture * volume_prop_emission
struct GPUTexture * volume_transmit
struct GPUTexture * volume_transmit_history
struct GPUTexture * volume_prop_phase
struct GPUTexture * volume_prop_scattering
struct GPUTexture * volume_scatter
struct EEVEE_CommonUniformBuffer common_data
struct GPUTexture * shadow_cube_pool
struct GPUUniformBuf * combined
struct GPUUniformBuf * shadow_ubo
struct GPUUniformBuf * probe_ubo
struct GPUUniformBuf * grid_ubo
struct GPUUniformBuf * planar_ubo
struct EEVEE_ViewLayerData::@210 renderpass_ubo
struct GPUUniformBuf * common_ubo
struct GPUUniformBuf * light_ubo
struct GPUTexture * shadow_cascade_pool
Material * ma
Definition: gpu_material.c:71
struct GPUTexture * tex
LightCacheTexture grid_tx
float obmat[4][4]
float volumetric_light_clamp
float volumetric_start
float volumetric_end
float volumetric_sample_distribution
int volumetric_shadow_samples
int volumetric_tile_size
struct World * world
struct SceneEEVEE eevee
struct bNodeTree * nodetree
short use_nodes