Blender  V2.93
eevee_mist.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2016, Blender Foundation.
17  */
18 
26 #include "DRW_engine.h"
27 #include "DRW_render.h"
28 
29 #include "DNA_world_types.h"
30 
31 #include "BLI_string_utils.h"
32 
33 #include "eevee_private.h"
34 
36 {
37  const DRWContextState *draw_ctx = DRW_context_state_get();
38  EEVEE_FramebufferList *fbl = vedata->fbl;
40  EEVEE_TextureList *txl = vedata->txl;
41  EEVEE_StorageList *stl = vedata->stl;
42  EEVEE_PassList *psl = vedata->psl;
43  EEVEE_PrivateData *g_data = stl->g_data;
44  Scene *scene = draw_ctx->scene;
45 
46  /* Create FrameBuffer. */
47  /* Should be enough precision for many samples. */
49 
50  GPU_framebuffer_ensure_config(&fbl->mist_accum_fb,
51  {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(txl->mist_accum)});
52 
53  /* Mist settings. */
54  if (scene && scene->world) {
55  g_data->mist_start = scene->world->miststa;
56  g_data->mist_inv_dist = (scene->world->mistdist > 0.0f) ? 1.0f / scene->world->mistdist : 0.0f;
57 
58  switch (scene->world->mistype) {
59  case WO_MIST_QUADRATIC:
60  g_data->mist_falloff = 2.0f;
61  break;
62  case WO_MIST_LINEAR:
63  g_data->mist_falloff = 1.0f;
64  break;
66  g_data->mist_falloff = 0.5f;
67  break;
68  }
69  }
70  else {
71  float near = DRW_view_near_distance_get(NULL);
72  float far = DRW_view_far_distance_get(NULL);
73  /* Fallback */
74  g_data->mist_start = near;
75  g_data->mist_inv_dist = 1.0f / fabsf(far - near);
76  g_data->mist_falloff = 1.0f;
77  }
78 
79  /* XXX ??!! WHY? If not it does not match cycles. */
80  g_data->mist_falloff *= 0.5f;
81 
82  /* Create Pass and shgroup. */
85  psl->mist_accum_ps);
86  DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
87  DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
88  DRW_shgroup_uniform_block(grp, "renderpass_block", sldata->renderpass_ubo.combined);
89  DRW_shgroup_uniform_vec3(grp, "mistSettings", &g_data->mist_start, 1);
91 }
92 
94 {
95  EEVEE_FramebufferList *fbl = vedata->fbl;
96  EEVEE_PassList *psl = vedata->psl;
97  EEVEE_EffectsInfo *effects = vedata->stl->effects;
98 
99  if (fbl->mist_accum_fb != NULL) {
101 
102  /* Clear texture. */
103  if (effects->taa_current_sample == 1) {
104  const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
105  GPU_framebuffer_clear_color(fbl->mist_accum_fb, clear);
106  }
107 
109 
110  /* Restore */
112  }
113 }
#define UNUSED(x)
@ WO_MIST_QUADRATIC
@ WO_MIST_INVERSE_QUADRATIC
@ WO_MIST_LINEAR
@ DRW_STATE_BLEND_ADD
Definition: DRW_render.h:336
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:315
#define DRW_PASS_CREATE(pass, state)
Definition: DRW_render.h:593
#define DRW_shgroup_call(shgroup, geom, ob)
Definition: DRW_render.h:420
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
@ GPU_R32F
Definition: GPU_texture.h:111
Scene scene
GPUBatch * DRW_cache_fullscreen_quad_get(void)
Definition: draw_cache.c:358
const DRWContextState * DRW_context_state_get(void)
DefaultTextureList * DRW_viewport_texture_list_get(void)
Definition: draw_manager.c:702
float DRW_view_near_distance_get(const DRWView *view)
void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const GPUUniformBuf *ubo)
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)
void EEVEE_mist_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
Definition: eevee_mist.c:93
void EEVEE_mist_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
Definition: eevee_mist.c:35
struct GPUShader * EEVEE_shaders_effect_mist_sh_get(void)
#define fabsf(x)
static void clear(Message *msg)
Definition: msgfmt.c:294
struct Scene * scene
Definition: DRW_render.h:745
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::@202 renderpass_ubo
struct GPUUniformBuf * common_ubo
struct World * world
float miststa
short mistype
float mistdist