diff options
author | Jeroen Bakker <jeroen@blender.org> | 2020-09-01 12:48:37 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-09-02 14:03:06 +0300 |
commit | feb4b645d70ec8ad5c3f91a957738a9fba4054f0 (patch) | |
tree | 4868e334b328f4dbfd81ff1dff531fe2d3834efb /source/blender/draw/engines | |
parent | d851b38185c1777287a19618c7fd103ad18e15f3 (diff) |
EEVEE: Shader tests for Depth of Field
This patch moves the EEVEE depth of field shaders to eevee_shaders.c and
adds them to the eevee shaders test suite.
Reviewed By: Clément Foucault
Differential Revision: https://developer.blender.org/D8771
Diffstat (limited to 'source/blender/draw/engines')
4 files changed, 73 insertions, 61 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.c b/source/blender/draw/engines/eevee/eevee_depth_of_field.c index 1d8082538a8..92ba526c67c 100644 --- a/source/blender/draw/engines/eevee/eevee_depth_of_field.c +++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.c @@ -40,46 +40,6 @@ #include "GPU_texture.h" #include "eevee_private.h" -static struct { - /* Depth Of Field */ - struct GPUShader *dof_downsample_sh[2]; - struct GPUShader *dof_scatter_sh[2]; - struct GPUShader *dof_resolve_sh[2]; -} e_data = {{NULL}}; /* Engine data */ - -extern char datatoc_effect_dof_vert_glsl[]; -extern char datatoc_effect_dof_frag_glsl[]; - -extern char datatoc_common_view_lib_glsl[]; - -static void eevee_create_shader_depth_of_field(const bool use_alpha) -{ - DRWShaderLibrary *lib = EEVEE_shader_lib_get(); - - e_data.dof_downsample_sh[use_alpha] = DRW_shader_create_fullscreen_with_shaderlib( - datatoc_effect_dof_frag_glsl, - lib, - use_alpha ? "#define USE_ALPHA_DOF\n" - "#define STEP_DOWNSAMPLE\n" : - "#define STEP_DOWNSAMPLE\n"); - - e_data.dof_scatter_sh[use_alpha] = DRW_shader_create_with_shaderlib( - datatoc_effect_dof_vert_glsl, - NULL, - datatoc_effect_dof_frag_glsl, - lib, - use_alpha ? "#define USE_ALPHA_DOF\n" - "#define STEP_SCATTER\n" : - "#define STEP_SCATTER\n"); - - e_data.dof_resolve_sh[use_alpha] = DRW_shader_create_fullscreen_with_shaderlib( - datatoc_effect_dof_frag_glsl, - lib, - use_alpha ? "#define USE_ALPHA_DOF\n" - "#define STEP_RESOLVE\n" : - "#define STEP_RESOLVE\n"); -} - int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera) @@ -95,12 +55,6 @@ int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), if (cam && (cam->dof.flag & CAM_DOF_ENABLED)) { RegionView3D *rv3d = draw_ctx->rv3d; - const bool use_alpha = !DRW_state_draw_background(); - - if (!e_data.dof_downsample_sh[use_alpha]) { - eevee_create_shader_depth_of_field(use_alpha); - } - const float *viewport_size = DRW_viewport_size_get(); /* Retrieve Near and Far distance */ @@ -212,7 +166,8 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ DRW_PASS_CREATE(psl->dof_down, DRW_STATE_WRITE_COLOR); - grp = DRW_shgroup_create(e_data.dof_downsample_sh[use_alpha], psl->dof_down); + grp = DRW_shgroup_create(EEVEE_shaders_depth_of_field_downsample_get(use_alpha), + psl->dof_down); DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer); DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1); @@ -226,7 +181,8 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ const float *viewport_size = DRW_viewport_size_get(); const int sprite_len = ((int)viewport_size[0] / 2) * ((int)viewport_size[1] / 2); /* brackets matters */ - grp = DRW_shgroup_create(e_data.dof_scatter_sh[use_alpha], psl->dof_scatter); + grp = DRW_shgroup_create(EEVEE_shaders_depth_of_field_scatter_get(use_alpha), + psl->dof_scatter); DRW_shgroup_uniform_texture_ref(grp, "nearBuffer", &effects->dof_down_near); DRW_shgroup_uniform_texture_ref(grp, "farBuffer", &effects->dof_down_far); DRW_shgroup_uniform_texture_ref(grp, "cocBuffer", &effects->dof_coc); @@ -236,7 +192,8 @@ void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_ DRW_PASS_CREATE(psl->dof_resolve, DRW_STATE_WRITE_COLOR); - grp = DRW_shgroup_create(e_data.dof_resolve_sh[use_alpha], psl->dof_resolve); + grp = DRW_shgroup_create(EEVEE_shaders_depth_of_field_resolve_get(use_alpha), + psl->dof_resolve); DRW_shgroup_uniform_texture_ref(grp, "scatterBuffer", &effects->dof_blur); DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer); DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); @@ -278,12 +235,3 @@ void EEVEE_depth_of_field_draw(EEVEE_Data *vedata) SWAP_BUFFERS(); } } - -void EEVEE_depth_of_field_free(void) -{ - for (int i = 0; i < 2; i++) { - DRW_SHADER_FREE_SAFE(e_data.dof_downsample_sh[i]); - DRW_SHADER_FREE_SAFE(e_data.dof_scatter_sh[i]); - DRW_SHADER_FREE_SAFE(e_data.dof_resolve_sh[i]); - } -} diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index d5fd11040e3..0f9f2c184bb 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -571,7 +571,6 @@ static void eevee_render_to_image(void *vedata, static void eevee_engine_free(void) { EEVEE_shaders_free(); - EEVEE_depth_of_field_free(); EEVEE_effects_free(); EEVEE_lightprobes_free(); EEVEE_shadows_free(); diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 7fba0e1b8ed..bf346708b34 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -1076,6 +1076,9 @@ struct GPUShader *EEVEE_shaders_bloom_blit_get(bool high_quality); struct GPUShader *EEVEE_shaders_bloom_downsample_get(bool high_quality); struct GPUShader *EEVEE_shaders_bloom_upsample_get(bool high_quality); struct GPUShader *EEVEE_shaders_bloom_resolve_get(bool high_quality); +struct GPUShader *EEVEE_shaders_depth_of_field_downsample_get(bool use_alpha); +struct GPUShader *EEVEE_shaders_depth_of_field_scatter_get(bool use_alpha); +struct GPUShader *EEVEE_shaders_depth_of_field_resolve_get(bool use_alpha); struct GPUShader *EEVEE_shaders_probe_filter_glossy_sh_get(void); struct GPUShader *EEVEE_shaders_probe_filter_diffuse_sh_get(void); struct GPUShader *EEVEE_shaders_probe_filter_visibility_sh_get(void); @@ -1159,7 +1162,6 @@ void EEVEE_lightprobes_planar_data_from_object(Object *ob, int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Object *camera); void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata); void EEVEE_depth_of_field_draw(EEVEE_Data *vedata); -void EEVEE_depth_of_field_free(void); /* eevee_bloom.c */ int EEVEE_bloom_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata); diff --git a/source/blender/draw/engines/eevee/eevee_shaders.c b/source/blender/draw/engines/eevee/eevee_shaders.c index 6c90d6325a0..37c43f9f6ef 100644 --- a/source/blender/draw/engines/eevee/eevee_shaders.c +++ b/source/blender/draw/engines/eevee/eevee_shaders.c @@ -75,6 +75,11 @@ static struct { struct GPUShader *bloom_upsample_sh[2]; struct GPUShader *bloom_resolve_sh[2]; + /* Depth Of Field */ + struct GPUShader *dof_downsample_sh[2]; + struct GPUShader *dof_scatter_sh[2]; + struct GPUShader *dof_resolve_sh[2]; + /* General purpose Shaders. */ struct GPUShader *lookdev_background; struct GPUShader *update_noise_sh; @@ -411,6 +416,10 @@ GPUShader *EEVEE_shaders_taa_resolve_sh_get(EEVEE_EffectsFlag enabled_effects) return *sh; } +/* -------------------------------------------------------------------- */ +/** \name Bloom + * \{ */ + GPUShader *EEVEE_shaders_bloom_blit_get(bool high_quality) { int index = high_quality ? 1 : 0; @@ -467,6 +476,58 @@ GPUShader *EEVEE_shaders_bloom_resolve_get(bool high_quality) return e_data.bloom_resolve_sh[index]; } +/* \} */ + +/* -------------------------------------------------------------------- */ +/** \name Depth of field + * \{ */ + +GPUShader *EEVEE_shaders_depth_of_field_downsample_get(bool use_alpha) +{ + int index = use_alpha ? 1 : 0; + if (e_data.dof_downsample_sh[index] == NULL) { + e_data.dof_downsample_sh[index] = DRW_shader_create_fullscreen_with_shaderlib( + datatoc_effect_dof_frag_glsl, + e_data.lib, + use_alpha ? "#define USE_ALPHA_DOF\n" + "#define STEP_DOWNSAMPLE\n" : + "#define STEP_DOWNSAMPLE\n"); + } + return e_data.dof_downsample_sh[index]; +} + +GPUShader *EEVEE_shaders_depth_of_field_scatter_get(bool use_alpha) +{ + int index = use_alpha ? 1 : 0; + if (e_data.dof_scatter_sh[index] == NULL) { + e_data.dof_scatter_sh[index] = DRW_shader_create_with_shaderlib(datatoc_effect_dof_vert_glsl, + NULL, + datatoc_effect_dof_frag_glsl, + e_data.lib, + use_alpha ? + "#define USE_ALPHA_DOF\n" + "#define STEP_SCATTER\n" : + "#define STEP_SCATTER\n"); + } + return e_data.dof_scatter_sh[index]; +} + +GPUShader *EEVEE_shaders_depth_of_field_resolve_get(bool use_alpha) +{ + int index = use_alpha ? 1 : 0; + if (e_data.dof_resolve_sh[index] == NULL) { + e_data.dof_resolve_sh[index] = DRW_shader_create_fullscreen_with_shaderlib( + datatoc_effect_dof_frag_glsl, + e_data.lib, + use_alpha ? "#define USE_ALPHA_DOF\n" + "#define STEP_RESOLVE\n" : + "#define STEP_RESOLVE\n"); + } + return e_data.dof_resolve_sh[index]; +} + +/* \} */ + Material *EEVEE_material_default_diffuse_get(void) { if (!e_data.diffuse_mat) { @@ -833,12 +894,14 @@ void EEVEE_shaders_free(void) DRW_SHADER_FREE_SAFE(e_data.velocity_resolve_sh); DRW_SHADER_FREE_SAFE(e_data.taa_resolve_sh); DRW_SHADER_FREE_SAFE(e_data.taa_resolve_reproject_sh); - for (int i = 0; i < 2; i++) { DRW_SHADER_FREE_SAFE(e_data.bloom_blit_sh[i]); DRW_SHADER_FREE_SAFE(e_data.bloom_downsample_sh[i]); DRW_SHADER_FREE_SAFE(e_data.bloom_upsample_sh[i]); DRW_SHADER_FREE_SAFE(e_data.bloom_resolve_sh[i]); + DRW_SHADER_FREE_SAFE(e_data.dof_downsample_sh[i]); + DRW_SHADER_FREE_SAFE(e_data.dof_scatter_sh[i]); + DRW_SHADER_FREE_SAFE(e_data.dof_resolve_sh[i]); } DRW_SHADER_LIB_FREE_SAFE(e_data.lib); |