2017-05-04 17:36:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file eevee_effects.c
|
|
|
|
* \ingroup draw_engine
|
2017-11-20 14:11:45 +11:00
|
|
|
*
|
|
|
|
* Gather all screen space effects technique such as Bloom, Motion Blur, DoF, SSAO, SSR, ...
|
2017-05-04 17:36:40 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
#include "eevee_private.h"
|
2017-10-10 17:18:29 +02:00
|
|
|
#include "GPU_texture.h"
|
2017-12-08 11:56:48 +01:00
|
|
|
#include "GPU_extensions.h"
|
2017-05-04 17:36:40 +02:00
|
|
|
|
|
|
|
static struct {
|
2017-06-22 02:28:49 +02:00
|
|
|
/* Downsample Depth */
|
2017-07-21 14:27:16 +02:00
|
|
|
struct GPUShader *minz_downlevel_sh;
|
|
|
|
struct GPUShader *maxz_downlevel_sh;
|
|
|
|
struct GPUShader *minz_downdepth_sh;
|
|
|
|
struct GPUShader *maxz_downdepth_sh;
|
2017-07-23 20:33:29 +02:00
|
|
|
struct GPUShader *minz_downdepth_layer_sh;
|
|
|
|
struct GPUShader *maxz_downdepth_layer_sh;
|
2017-07-21 14:27:16 +02:00
|
|
|
struct GPUShader *minz_copydepth_sh;
|
|
|
|
struct GPUShader *maxz_copydepth_sh;
|
2017-06-22 02:28:49 +02:00
|
|
|
|
2017-07-21 14:27:16 +02:00
|
|
|
/* Simple Downsample */
|
2017-07-20 18:40:23 +02:00
|
|
|
struct GPUShader *downsample_sh;
|
2017-08-18 22:31:06 +02:00
|
|
|
struct GPUShader *downsample_cube_sh;
|
2017-07-20 18:40:23 +02:00
|
|
|
|
2017-09-25 20:14:07 +02:00
|
|
|
/* Theses are just references, not actually allocated */
|
2017-07-03 16:38:14 +02:00
|
|
|
struct GPUTexture *depth_src;
|
2017-07-20 18:40:23 +02:00
|
|
|
struct GPUTexture *color_src;
|
2017-09-25 20:14:07 +02:00
|
|
|
|
2017-07-23 20:33:29 +02:00
|
|
|
int depth_src_layer;
|
2017-08-18 22:31:06 +02:00
|
|
|
float cube_texel_size;
|
2017-05-04 17:36:40 +02:00
|
|
|
} e_data = {NULL}; /* Engine data */
|
|
|
|
|
2017-06-22 02:28:49 +02:00
|
|
|
extern char datatoc_effect_minmaxz_frag_glsl[];
|
2017-07-20 18:40:23 +02:00
|
|
|
extern char datatoc_effect_downsample_frag_glsl[];
|
2017-08-18 22:31:06 +02:00
|
|
|
extern char datatoc_effect_downsample_cube_frag_glsl[];
|
|
|
|
extern char datatoc_lightprobe_vert_glsl[];
|
|
|
|
extern char datatoc_lightprobe_geom_glsl[];
|
2017-05-11 14:31:28 +02:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
static void eevee_create_shader_downsample(void)
|
2017-07-23 00:03:45 +02:00
|
|
|
{
|
2017-11-01 01:03:36 +01:00
|
|
|
e_data.downsample_sh = DRW_shader_create_fullscreen(datatoc_effect_downsample_frag_glsl, NULL);
|
2017-11-20 14:28:24 +11:00
|
|
|
e_data.downsample_cube_sh = DRW_shader_create(
|
|
|
|
datatoc_lightprobe_vert_glsl,
|
|
|
|
datatoc_lightprobe_geom_glsl,
|
|
|
|
datatoc_effect_downsample_cube_frag_glsl, NULL);
|
|
|
|
|
|
|
|
e_data.minz_downlevel_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
|
|
|
"#define MIN_PASS\n");
|
|
|
|
e_data.maxz_downlevel_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
|
|
|
"#define MAX_PASS\n");
|
|
|
|
e_data.minz_downdepth_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
2017-12-08 11:54:15 +01:00
|
|
|
"#define MIN_PASS\n");
|
2017-11-20 14:28:24 +11:00
|
|
|
e_data.maxz_downdepth_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
2017-12-08 11:54:15 +01:00
|
|
|
"#define MAX_PASS\n");
|
2017-11-20 14:28:24 +11:00
|
|
|
e_data.minz_downdepth_layer_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
|
|
|
"#define MIN_PASS\n"
|
2017-12-08 11:54:15 +01:00
|
|
|
"#define LAYERED\n");
|
2017-11-20 14:28:24 +11:00
|
|
|
e_data.maxz_downdepth_layer_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
|
|
|
"#define MAX_PASS\n"
|
2017-12-08 11:54:15 +01:00
|
|
|
"#define LAYERED\n");
|
2017-11-20 14:28:24 +11:00
|
|
|
e_data.minz_copydepth_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
|
|
|
"#define MIN_PASS\n"
|
|
|
|
"#define COPY_DEPTH\n");
|
|
|
|
e_data.maxz_copydepth_sh = DRW_shader_create_fullscreen(
|
|
|
|
datatoc_effect_minmaxz_frag_glsl,
|
|
|
|
"#define MAX_PASS\n"
|
|
|
|
"#define COPY_DEPTH\n");
|
2017-07-23 00:03:45 +02:00
|
|
|
}
|
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
void EEVEE_effects_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Object *camera)
|
2017-05-04 17:36:40 +02:00
|
|
|
{
|
2018-01-21 17:25:10 +01:00
|
|
|
EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
EEVEE_FramebufferList *fbl = vedata->fbl;
|
|
|
|
EEVEE_TextureList *txl = vedata->txl;
|
2017-05-09 21:57:13 +02:00
|
|
|
EEVEE_EffectsInfo *effects;
|
2018-02-03 03:00:39 +01:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
ViewLayer *view_layer = draw_ctx->view_layer;
|
2017-05-04 17:36:40 +02:00
|
|
|
|
|
|
|
const float *viewport_size = DRW_viewport_size_get();
|
2017-06-22 02:28:49 +02:00
|
|
|
/* Shaders */
|
2017-11-01 01:03:36 +01:00
|
|
|
if (!e_data.downsample_sh) {
|
|
|
|
eevee_create_shader_downsample();
|
2017-05-07 14:27:43 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 17:36:40 +02:00
|
|
|
if (!stl->effects) {
|
|
|
|
stl->effects = MEM_callocN(sizeof(EEVEE_EffectsInfo), "EEVEE_EffectsInfo");
|
|
|
|
}
|
|
|
|
|
2017-05-09 21:57:13 +02:00
|
|
|
effects = stl->effects;
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
effects->enabled_effects = 0;
|
2018-01-29 18:16:11 +01:00
|
|
|
effects->enabled_effects |= EEVEE_motion_blur_init(sldata, vedata, camera);
|
2017-11-01 01:03:36 +01:00
|
|
|
effects->enabled_effects |= EEVEE_bloom_init(sldata, vedata);
|
2018-01-29 18:16:11 +01:00
|
|
|
effects->enabled_effects |= EEVEE_depth_of_field_init(sldata, vedata, camera);
|
2017-11-01 01:03:36 +01:00
|
|
|
effects->enabled_effects |= EEVEE_temporal_sampling_init(sldata, vedata);
|
|
|
|
effects->enabled_effects |= EEVEE_occlusion_init(sldata, vedata);
|
2017-11-14 00:49:54 +01:00
|
|
|
effects->enabled_effects |= EEVEE_subsurface_init(sldata, vedata);
|
2017-11-01 01:03:36 +01:00
|
|
|
effects->enabled_effects |= EEVEE_screen_raytrace_init(sldata, vedata);
|
|
|
|
effects->enabled_effects |= EEVEE_volumes_init(sldata, vedata);
|
|
|
|
|
2018-02-03 03:00:39 +01:00
|
|
|
/* Force normal buffer creation. */
|
|
|
|
if (DRW_state_is_image_render() &&
|
2018-02-15 18:03:55 +11:00
|
|
|
(view_layer->passflag & SCE_PASS_NORMAL) != 0)
|
2018-02-03 03:00:39 +01:00
|
|
|
{
|
|
|
|
effects->enabled_effects |= EFFECT_NORMAL_BUFFER;
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/**
|
|
|
|
* Ping Pong buffer
|
|
|
|
*/
|
|
|
|
if ((effects->enabled_effects & EFFECT_POST_BUFFER) != 0) {
|
2017-10-10 18:32:05 +02:00
|
|
|
DRWFboTexture tex = {&txl->color_post, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
|
2017-05-16 03:03:58 +02:00
|
|
|
DRW_framebuffer_init(&fbl->effect_fb, &draw_engine_eevee_type,
|
2017-05-09 21:57:13 +02:00
|
|
|
(int)viewport_size[0], (int)viewport_size[1],
|
|
|
|
&tex, 1);
|
|
|
|
}
|
2017-08-18 15:06:51 +02:00
|
|
|
else {
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Cleanup to release memory */
|
|
|
|
DRW_TEXTURE_FREE_SAFE(txl->color_post);
|
|
|
|
DRW_FRAMEBUFFER_FREE_SAFE(fbl->effect_fb);
|
2017-06-22 03:10:39 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/**
|
|
|
|
* MinMax Pyramid
|
|
|
|
*/
|
2017-11-01 16:17:33 +01:00
|
|
|
DRWFboTexture texmax = {&txl->maxzbuffer, DRW_TEX_DEPTH_24, DRW_TEX_MIPMAP};
|
2017-12-08 11:56:48 +01:00
|
|
|
|
|
|
|
if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
/* Intel gpu seems to have problem rendering to only depth format */
|
|
|
|
texmax.format = DRW_TEX_R_32;
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_framebuffer_init(&fbl->downsample_fb, &draw_engine_eevee_type,
|
2018-01-23 22:50:05 -02:00
|
|
|
max_ii((int)viewport_size[0] / 2, 1), max_ii((int)viewport_size[1] / 2, 1),
|
2017-11-01 16:17:33 +01:00
|
|
|
&texmax, 1);
|
2017-08-18 15:06:51 +02:00
|
|
|
|
2017-12-08 11:56:48 +01:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/**
|
|
|
|
* Compute Mipmap texel alignement.
|
|
|
|
*/
|
2017-08-09 15:20:18 +02:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
float mip_size[2] = {viewport_size[0], viewport_size[1]};
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
mip_size[0] = floorf(fmaxf(1.0f, mip_size[0] / 2.0f));
|
|
|
|
mip_size[1] = floorf(fmaxf(1.0f, mip_size[1] / 2.0f));
|
|
|
|
}
|
2018-01-21 17:25:10 +01:00
|
|
|
common_data->mip_ratio[i][0] = viewport_size[0] / (mip_size[0] * powf(2.0f, floorf(log2f(floorf(viewport_size[0] / mip_size[0])))));
|
|
|
|
common_data->mip_ratio[i][1] = viewport_size[1] / (mip_size[1] * powf(2.0f, floorf(log2f(floorf(viewport_size[1] / mip_size[1])))));
|
2017-08-09 15:20:18 +02:00
|
|
|
}
|
|
|
|
|
2017-07-21 15:06:29 +02:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/**
|
|
|
|
* Normal buffer for deferred passes.
|
|
|
|
*/
|
|
|
|
if ((effects->enabled_effects & EFFECT_NORMAL_BUFFER) != 0) {
|
2017-08-18 15:06:51 +02:00
|
|
|
if (txl->ssr_normal_input == NULL) {
|
|
|
|
DRWTextureFormat nor_format = DRW_TEX_RG_16;
|
|
|
|
txl->ssr_normal_input = DRW_texture_create_2D((int)viewport_size[0], (int)viewport_size[1], nor_format, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reattach textures to the right buffer (because we are alternating between buffers) */
|
|
|
|
/* TODO multiple FBO per texture!!!! */
|
|
|
|
DRW_framebuffer_texture_detach(txl->ssr_normal_input);
|
|
|
|
DRW_framebuffer_texture_attach(fbl->main, txl->ssr_normal_input, 1, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Cleanup to release memory */
|
|
|
|
DRW_TEXTURE_FREE_SAFE(txl->ssr_normal_input);
|
|
|
|
}
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/**
|
|
|
|
* Setup double buffer so we can access last frame as it was before post processes.
|
|
|
|
*/
|
2017-07-19 14:22:03 +02:00
|
|
|
if ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0) {
|
2017-10-10 18:32:05 +02:00
|
|
|
DRWFboTexture tex_double_buffer = {&txl->color_double_buffer, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
|
2017-07-19 14:22:03 +02:00
|
|
|
DRW_framebuffer_init(&fbl->double_buffer, &draw_engine_eevee_type,
|
|
|
|
(int)viewport_size[0], (int)viewport_size[1],
|
|
|
|
&tex_double_buffer, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Cleanup to release memory */
|
|
|
|
DRW_TEXTURE_FREE_SAFE(txl->color_double_buffer);
|
|
|
|
DRW_FRAMEBUFFER_FREE_SAFE(fbl->double_buffer);
|
|
|
|
}
|
2017-05-07 14:27:43 +02:00
|
|
|
}
|
|
|
|
|
2018-01-21 17:25:10 +01:00
|
|
|
void EEVEE_effects_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
|
2017-05-04 17:36:40 +02:00
|
|
|
{
|
|
|
|
EEVEE_PassList *psl = vedata->psl;
|
|
|
|
EEVEE_TextureList *txl = vedata->txl;
|
2017-12-08 11:56:48 +01:00
|
|
|
int downsample_write = DRW_STATE_WRITE_DEPTH;
|
|
|
|
|
|
|
|
/* Intel gpu seems to have problem rendering to only depth format.
|
|
|
|
* Use color texture instead. */
|
|
|
|
if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
downsample_write = DRW_STATE_WRITE_COLOR;
|
|
|
|
}
|
2017-05-04 17:36:40 +02:00
|
|
|
|
2017-06-19 20:18:04 +10:00
|
|
|
struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
|
2017-05-04 17:36:40 +02:00
|
|
|
|
2017-07-20 18:40:23 +02:00
|
|
|
{
|
|
|
|
psl->color_downsample_ps = DRW_pass_create("Downsample", DRW_STATE_WRITE_COLOR);
|
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.downsample_sh, psl->color_downsample_ps);
|
|
|
|
DRW_shgroup_uniform_buffer(grp, "source", &e_data.color_src);
|
2018-01-21 17:25:10 +01:00
|
|
|
DRW_shgroup_uniform_float(grp, "fireflyFactor", &sldata->common_data.ssr_firefly_fac, 1);
|
2017-07-20 18:40:23 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
}
|
|
|
|
|
2017-08-18 22:31:06 +02:00
|
|
|
{
|
|
|
|
static int zero = 0;
|
2018-03-01 19:27:38 +01:00
|
|
|
static unsigned int six = 6;
|
2017-08-18 22:31:06 +02:00
|
|
|
psl->color_downsample_cube_ps = DRW_pass_create("Downsample Cube", DRW_STATE_WRITE_COLOR);
|
2018-03-01 19:27:38 +01:00
|
|
|
DRWShadingGroup *grp = DRW_shgroup_create(e_data.downsample_cube_sh, psl->color_downsample_cube_ps);
|
2017-08-18 22:31:06 +02:00
|
|
|
DRW_shgroup_uniform_buffer(grp, "source", &e_data.color_src);
|
|
|
|
DRW_shgroup_uniform_float(grp, "texelSize", &e_data.cube_texel_size, 1);
|
|
|
|
DRW_shgroup_uniform_int(grp, "Layer", &zero, 1);
|
2018-03-01 19:27:38 +01:00
|
|
|
DRW_shgroup_call_instances_add(grp, quad, NULL, &six);
|
2017-08-18 22:31:06 +02:00
|
|
|
}
|
|
|
|
|
2017-06-22 02:28:49 +02:00
|
|
|
{
|
2017-07-21 14:27:16 +02:00
|
|
|
/* Perform min/max downsample */
|
2017-11-01 01:03:36 +01:00
|
|
|
DRWShadingGroup *grp;
|
|
|
|
|
|
|
|
#if 0 /* Not used for now */
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->minz_downlevel_ps = DRW_pass_create("HiZ Min Down Level", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-11-01 01:03:36 +01:00
|
|
|
grp = DRW_shgroup_create(e_data.minz_downlevel_sh, psl->minz_downlevel_ps);
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &stl->g_data->minzbuffer);
|
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
2017-07-21 14:27:16 +02:00
|
|
|
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->maxz_downlevel_ps = DRW_pass_create("HiZ Max Down Level", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-21 14:27:16 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.maxz_downlevel_sh, psl->maxz_downlevel_ps);
|
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &txl->maxzbuffer);
|
2017-06-22 02:28:49 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
|
2017-07-21 14:27:16 +02:00
|
|
|
/* Copy depth buffer to halfres top level of HiZ */
|
2017-11-01 01:03:36 +01:00
|
|
|
#if 0 /* Not used for now */
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->minz_downdepth_ps = DRW_pass_create("HiZ Min Copy Depth Halfres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-21 14:27:16 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.minz_downdepth_sh, psl->minz_downdepth_ps);
|
2017-07-03 16:38:14 +02:00
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
|
2017-06-22 02:28:49 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
2017-06-22 02:28:49 +02:00
|
|
|
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->maxz_downdepth_ps = DRW_pass_create("HiZ Max Copy Depth Halfres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-21 14:27:16 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.maxz_downdepth_sh, psl->maxz_downdepth_ps);
|
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
|
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
#if 0 /* Not used for now */
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->minz_downdepth_layer_ps = DRW_pass_create("HiZ Min Copy DepthLayer Halfres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-23 20:33:29 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.minz_downdepth_layer_sh, psl->minz_downdepth_layer_ps);
|
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
|
|
|
|
DRW_shgroup_uniform_int(grp, "depthLayer", &e_data.depth_src_layer, 1);
|
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
2017-07-23 20:33:29 +02:00
|
|
|
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->maxz_downdepth_layer_ps = DRW_pass_create("HiZ Max Copy DepthLayer Halfres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-23 20:33:29 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.maxz_downdepth_layer_sh, psl->maxz_downdepth_layer_ps);
|
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
|
|
|
|
DRW_shgroup_uniform_int(grp, "depthLayer", &e_data.depth_src_layer, 1);
|
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
|
2017-07-21 14:27:16 +02:00
|
|
|
/* Copy depth buffer to halfres top level of HiZ */
|
2017-11-01 01:03:36 +01:00
|
|
|
#if 0 /* Not used for now */
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->minz_copydepth_ps = DRW_pass_create("HiZ Min Copy Depth Fullres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-21 14:27:16 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.minz_copydepth_sh, psl->minz_copydepth_ps);
|
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
|
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
2017-07-21 14:27:16 +02:00
|
|
|
|
2017-12-08 11:56:48 +01:00
|
|
|
psl->maxz_copydepth_ps = DRW_pass_create("HiZ Max Copy Depth Fullres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
|
2017-07-21 14:27:16 +02:00
|
|
|
grp = DRW_shgroup_create(e_data.maxz_copydepth_sh, psl->maxz_copydepth_ps);
|
2017-07-03 16:38:14 +02:00
|
|
|
DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
|
2017-06-22 02:28:49 +02:00
|
|
|
DRW_shgroup_call_add(grp, quad, NULL);
|
|
|
|
}
|
2017-05-04 17:36:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
#if 0 /* Not required for now */
|
2017-07-21 14:27:16 +02:00
|
|
|
static void min_downsample_cb(void *vedata, int UNUSED(level))
|
2017-06-22 02:28:49 +02:00
|
|
|
{
|
|
|
|
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_draw_pass(psl->minz_downlevel_ps);
|
|
|
|
}
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
2017-07-21 14:27:16 +02:00
|
|
|
|
|
|
|
static void max_downsample_cb(void *vedata, int UNUSED(level))
|
|
|
|
{
|
|
|
|
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
|
|
|
DRW_draw_pass(psl->maxz_downlevel_ps);
|
2017-06-22 02:28:49 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 18:40:23 +02:00
|
|
|
static void simple_downsample_cb(void *vedata, int UNUSED(level))
|
|
|
|
{
|
|
|
|
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
|
|
|
DRW_draw_pass(psl->color_downsample_ps);
|
|
|
|
}
|
|
|
|
|
2017-08-18 22:31:06 +02:00
|
|
|
static void simple_downsample_cube_cb(void *vedata, int level)
|
|
|
|
{
|
|
|
|
EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
|
|
|
|
e_data.cube_texel_size = (float)(1 << level) / (float)GPU_texture_width(e_data.color_src);
|
|
|
|
DRW_draw_pass(psl->color_downsample_cube_ps);
|
|
|
|
}
|
|
|
|
|
2017-07-23 20:33:29 +02:00
|
|
|
void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int layer)
|
2017-06-22 02:28:49 +02:00
|
|
|
{
|
|
|
|
EEVEE_PassList *psl = vedata->psl;
|
|
|
|
EEVEE_FramebufferList *fbl = vedata->fbl;
|
2017-07-21 14:27:16 +02:00
|
|
|
EEVEE_TextureList *txl = vedata->txl;
|
2017-06-22 02:28:49 +02:00
|
|
|
|
2017-07-03 16:38:14 +02:00
|
|
|
e_data.depth_src = depth_src;
|
2017-08-12 16:13:08 +02:00
|
|
|
e_data.depth_src_layer = layer;
|
2017-06-23 21:08:53 +02:00
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
#if 0 /* Not required for now */
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Min buffer");
|
2017-07-21 14:27:16 +02:00
|
|
|
/* Copy depth buffer to min texture top level */
|
|
|
|
DRW_framebuffer_texture_attach(fbl->downsample_fb, stl->g_data->minzbuffer, 0, 0);
|
|
|
|
DRW_framebuffer_bind(fbl->downsample_fb);
|
2017-07-23 20:33:29 +02:00
|
|
|
if (layer >= 0) {
|
|
|
|
DRW_draw_pass(psl->minz_downdepth_layer_ps);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DRW_draw_pass(psl->minz_downdepth_ps);
|
|
|
|
}
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_framebuffer_texture_detach(stl->g_data->minzbuffer);
|
|
|
|
|
|
|
|
/* Create lower levels */
|
|
|
|
DRW_framebuffer_recursive_downsample(fbl->downsample_fb, stl->g_data->minzbuffer, 8, &min_downsample_cb, vedata);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-11-01 01:03:36 +01:00
|
|
|
#endif
|
2017-07-21 14:27:16 +02:00
|
|
|
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Max buffer");
|
2017-07-21 14:27:16 +02:00
|
|
|
/* Copy depth buffer to max texture top level */
|
|
|
|
DRW_framebuffer_texture_attach(fbl->downsample_fb, txl->maxzbuffer, 0, 0);
|
|
|
|
DRW_framebuffer_bind(fbl->downsample_fb);
|
2017-07-23 20:33:29 +02:00
|
|
|
if (layer >= 0) {
|
|
|
|
DRW_draw_pass(psl->maxz_downdepth_layer_ps);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DRW_draw_pass(psl->maxz_downdepth_ps);
|
|
|
|
}
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_framebuffer_texture_detach(txl->maxzbuffer);
|
2017-06-22 02:28:49 +02:00
|
|
|
|
|
|
|
/* Create lower levels */
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_framebuffer_recursive_downsample(fbl->downsample_fb, txl->maxzbuffer, 8, &max_downsample_cb, vedata);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-11-01 01:03:36 +01:00
|
|
|
|
|
|
|
/* Restore */
|
|
|
|
DRW_framebuffer_bind(fbl->main);
|
2017-06-22 02:28:49 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 18:40:23 +02:00
|
|
|
/**
|
|
|
|
* Simple downsampling algorithm. Reconstruct mip chain up to mip level.
|
|
|
|
**/
|
|
|
|
void EEVEE_downsample_buffer(EEVEE_Data *vedata, struct GPUFrameBuffer *fb_src, GPUTexture *texture_src, int level)
|
|
|
|
{
|
|
|
|
e_data.color_src = texture_src;
|
|
|
|
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_start("Downsample buffer");
|
2017-07-20 18:40:23 +02:00
|
|
|
/* Create lower levels */
|
|
|
|
DRW_framebuffer_recursive_downsample(fb_src, texture_src, level, &simple_downsample_cb, vedata);
|
2017-07-26 19:58:15 +02:00
|
|
|
DRW_stats_group_end();
|
2017-07-20 18:40:23 +02:00
|
|
|
}
|
|
|
|
|
2017-08-18 22:31:06 +02:00
|
|
|
/**
|
|
|
|
* Simple downsampling algorithm for cubemap. Reconstruct mip chain up to mip level.
|
|
|
|
**/
|
|
|
|
void EEVEE_downsample_cube_buffer(EEVEE_Data *vedata, struct GPUFrameBuffer *fb_src, GPUTexture *texture_src, int level)
|
|
|
|
{
|
|
|
|
e_data.color_src = texture_src;
|
|
|
|
|
|
|
|
DRW_stats_group_start("Downsample Cube buffer");
|
|
|
|
/* Create lower levels */
|
|
|
|
DRW_framebuffer_recursive_downsample(fb_src, texture_src, level, &simple_downsample_cube_cb, vedata);
|
|
|
|
DRW_stats_group_end();
|
|
|
|
}
|
|
|
|
|
2018-02-26 20:08:48 +01:00
|
|
|
void EEVEE_draw_effects(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
|
2017-05-04 17:36:40 +02:00
|
|
|
{
|
2017-05-07 14:27:43 +02:00
|
|
|
EEVEE_TextureList *txl = vedata->txl;
|
2017-05-04 17:36:40 +02:00
|
|
|
EEVEE_FramebufferList *fbl = vedata->fbl;
|
|
|
|
EEVEE_StorageList *stl = vedata->stl;
|
|
|
|
EEVEE_EffectsInfo *effects = stl->effects;
|
|
|
|
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/* only once per frame after the first post process */
|
|
|
|
effects->swap_double_buffer = ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0);
|
|
|
|
|
2017-05-07 14:27:43 +02:00
|
|
|
/* Init pointers */
|
|
|
|
effects->source_buffer = txl->color; /* latest updated texture */
|
|
|
|
effects->target_buffer = fbl->effect_fb; /* next target to render to */
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Temporal Anti-Aliasing MUST come first */
|
|
|
|
EEVEE_temporal_sampling_draw(vedata);
|
2017-09-25 20:14:07 +02:00
|
|
|
|
2017-05-09 21:57:13 +02:00
|
|
|
/* Detach depth for effects to use it */
|
|
|
|
DRW_framebuffer_texture_detach(dtxl->depth);
|
|
|
|
|
2017-11-01 01:03:36 +01:00
|
|
|
/* Post process stack (order matters) */
|
|
|
|
EEVEE_motion_blur_draw(vedata);
|
|
|
|
EEVEE_depth_of_field_draw(vedata);
|
|
|
|
EEVEE_bloom_draw(vedata);
|
2017-05-07 14:27:43 +02:00
|
|
|
|
2018-01-29 18:16:11 +01:00
|
|
|
/* Save the final texture and framebuffer for final transformation or read. */
|
|
|
|
effects->final_tx = effects->source_buffer;
|
|
|
|
effects->final_fb = (effects->target_buffer != fbl->main) ? fbl->main : fbl->effect_fb;
|
2017-07-22 16:22:01 +02:00
|
|
|
|
|
|
|
/* If no post processes is enabled, buffers are still not swapped, do it now. */
|
|
|
|
SWAP_DOUBLE_BUFFERS();
|
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
if (!stl->g_data->valid_double_buffer &&
|
2017-10-07 15:57:14 +11:00
|
|
|
((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0) &&
|
|
|
|
(DRW_state_is_image_render() == false))
|
2017-07-22 20:36:34 +02:00
|
|
|
{
|
2017-07-22 16:22:01 +02:00
|
|
|
/* If history buffer is not valid request another frame.
|
|
|
|
* This fix black reflections on area resize. */
|
|
|
|
DRW_viewport_request_redraw();
|
|
|
|
}
|
|
|
|
|
2017-07-23 00:03:45 +02:00
|
|
|
/* Record pers matrix for the next frame. */
|
2018-02-26 20:08:48 +01:00
|
|
|
DRW_viewport_matrix_get(stl->effects->prev_persmat, DRW_MAT_PERS);
|
2017-07-23 00:03:45 +02:00
|
|
|
|
2017-07-22 20:36:34 +02:00
|
|
|
/* Update double buffer status if render mode. */
|
|
|
|
if (DRW_state_is_image_render()) {
|
|
|
|
stl->g_data->valid_double_buffer = (txl->color_double_buffer != NULL);
|
|
|
|
}
|
2017-05-04 17:36:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EEVEE_effects_free(void)
|
|
|
|
{
|
2017-07-20 18:40:23 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.downsample_sh);
|
2017-08-18 22:31:06 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.downsample_cube_sh);
|
2017-07-16 23:49:25 +02:00
|
|
|
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.minz_downlevel_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.maxz_downlevel_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.minz_downdepth_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.maxz_downdepth_sh);
|
2017-07-23 20:33:29 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.minz_downdepth_layer_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.maxz_downdepth_layer_sh);
|
2017-07-21 14:27:16 +02:00
|
|
|
DRW_SHADER_FREE_SAFE(e_data.minz_copydepth_sh);
|
|
|
|
DRW_SHADER_FREE_SAFE(e_data.maxz_copydepth_sh);
|
2017-07-21 11:53:13 +02:00
|
|
|
}
|