Blender  V3.3
eevee_mist.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 Blender Foundation. */
3 
11 #include "DRW_engine.h"
12 #include "DRW_render.h"
13 
14 #include "DNA_world_types.h"
15 
16 #include "BLI_string_utils.h"
17 
18 #include "eevee_private.h"
19 
21 {
22  const DRWContextState *draw_ctx = DRW_context_state_get();
23  EEVEE_FramebufferList *fbl = vedata->fbl;
25  EEVEE_TextureList *txl = vedata->txl;
26  EEVEE_StorageList *stl = vedata->stl;
27  EEVEE_PassList *psl = vedata->psl;
29  Scene *scene = draw_ctx->scene;
30 
31  /* Create FrameBuffer. */
32  /* Should be enough precision for many samples. */
34 
35  GPU_framebuffer_ensure_config(&fbl->mist_accum_fb,
36  {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(txl->mist_accum)});
37 
38  /* Mist settings. */
39  if (scene && scene->world) {
40  g_data->mist_start = scene->world->miststa;
41  g_data->mist_inv_dist = (scene->world->mistdist > 0.0f) ? 1.0f / scene->world->mistdist : 0.0f;
42 
43  switch (scene->world->mistype) {
44  case WO_MIST_QUADRATIC:
45  g_data->mist_falloff = 2.0f;
46  break;
47  case WO_MIST_LINEAR:
48  g_data->mist_falloff = 1.0f;
49  break;
51  g_data->mist_falloff = 0.5f;
52  break;
53  }
54  }
55  else {
56  float near = DRW_view_near_distance_get(NULL);
57  float far = DRW_view_far_distance_get(NULL);
58  /* Fallback */
59  g_data->mist_start = near;
60  g_data->mist_inv_dist = 1.0f / fabsf(far - near);
61  g_data->mist_falloff = 1.0f;
62  }
63 
64  /* XXX ??!! WHY? If not it does not match cycles. */
65  g_data->mist_falloff *= 0.5f;
66 
67  /* Create Pass and shgroup. */
70  psl->mist_accum_ps);
71  DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
72  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
73  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
74  DRW_shgroup_uniform_vec3(grp, "mistSettings", &g_data->mist_start, 1);
76 }
77 
79 {
80  EEVEE_FramebufferList *fbl = vedata->fbl;
81  EEVEE_PassList *psl = vedata->psl;
82  EEVEE_EffectsInfo *effects = vedata->stl->effects;
83 
84  if (fbl->mist_accum_fb != NULL) {
86 
87  /* Clear texture. */
88  if (effects->taa_current_sample == 1) {
89  const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
90  GPU_framebuffer_clear_color(fbl->mist_accum_fb, clear);
91  }
92 
94 
95  /* Restore */
97  }
98 }
#define UNUSED(x)
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
@ DRW_STATE_BLEND_ADD
Definition: DRW_render.h:324
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
#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
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
Scene scene
GPUBatch * DRW_cache_fullscreen_quad_get(void)
Definition: draw_cache.c:356
const DRWContextState * DRW_context_state_get(void)
DefaultTextureList * DRW_viewport_texture_list_get(void)
Definition: draw_manager.c:638
float DRW_view_near_distance_get(const DRWView *view)
void DRW_shgroup_uniform_vec3(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
float DRW_view_far_distance_get(const DRWView *view)
void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
void DRW_draw_pass(DRWPass *pass)
void DRW_texture_ensure_fullscreen_2d(GPUTexture **tex, eGPUTextureFormat format, DRWTextureFlag flags)
static struct @318 g_data
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx GPU_R32F
void EEVEE_mist_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
Definition: eevee_mist.c:78
void EEVEE_mist_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
Definition: eevee_mist.c:20
struct GPUShader * EEVEE_shaders_effect_mist_sh_get(void)
#define fabsf(x)
Definition: metal/compat.h:219
static void clear(Message *msg)
Definition: msgfmt.c:278
struct Scene * scene
Definition: DRW_render.h:979
struct GPUTexture * depth
EEVEE_TextureList * txl
EEVEE_StorageList * stl
EEVEE_PassList * psl
EEVEE_FramebufferList * fbl
struct GPUFrameBuffer * main_fb
struct GPUFrameBuffer * mist_accum_fb
struct DRWPass * mist_accum_ps
struct EEVEE_PrivateData * g_data
struct EEVEE_EffectsInfo * effects
struct GPUTexture * mist_accum
struct GPUUniformBuf * combined
struct EEVEE_ViewLayerData::@210 renderpass_ubo
struct GPUUniformBuf * common_ubo
struct World * world
float miststa
short mistype
float mistdist