diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_bloom.c | 64 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_engine.c | 1 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_private.h | 5 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_shaders.c | 69 | ||||
-rw-r--r-- | source/blender/draw/tests/shaders_test.cc | 8 |
5 files changed, 87 insertions, 60 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_bloom.c b/source/blender/draw/engines/eevee/eevee_bloom.c index 8fd953478d5..9b8f7ddab0c 100644 --- a/source/blender/draw/engines/eevee/eevee_bloom.c +++ b/source/blender/draw/engines/eevee/eevee_bloom.c @@ -30,45 +30,8 @@ #include "eevee_private.h" -static struct { - /* Bloom */ - struct GPUShader *bloom_blit_sh[2]; - struct GPUShader *bloom_downsample_sh[2]; - struct GPUShader *bloom_upsample_sh[2]; - struct GPUShader *bloom_resolve_sh[2]; -} e_data = {{NULL}}; /* Engine data */ - -extern char datatoc_effect_bloom_frag_glsl[]; - static const bool use_highres = true; -static void eevee_create_shader_bloom(void) -{ - e_data.bloom_blit_sh[0] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_BLIT\n"); - e_data.bloom_blit_sh[1] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_BLIT\n" - "#define HIGH_QUALITY\n"); - - e_data.bloom_downsample_sh[0] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_DOWNSAMPLE\n"); - e_data.bloom_downsample_sh[1] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_DOWNSAMPLE\n" - "#define HIGH_QUALITY\n"); - - e_data.bloom_upsample_sh[0] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_UPSAMPLE\n"); - e_data.bloom_upsample_sh[1] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_UPSAMPLE\n" - "#define HIGH_QUALITY\n"); - - e_data.bloom_resolve_sh[0] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_RESOLVE\n"); - e_data.bloom_resolve_sh[1] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, - "#define STEP_RESOLVE\n" - "#define HIGH_QUALITY\n"); -} - int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata) { EEVEE_StorageList *stl = vedata->stl; @@ -81,11 +44,6 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata) if (scene_eval->eevee.flag & SCE_EEVEE_BLOOM_ENABLED) { const float *viewport_size = DRW_viewport_size_get(); - /* Shaders */ - if (!e_data.bloom_blit_sh[0]) { - eevee_create_shader_bloom(); - } - /* Bloom */ int blitsize[2], texsize[2]; @@ -246,26 +204,26 @@ void EEVEE_bloom_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *ved const bool use_antiflicker = true; eevee_create_bloom_pass("Bloom Downsample First", effects, - e_data.bloom_downsample_sh[use_antiflicker], + EEVEE_shaders_bloom_downsample_get(use_antiflicker), &psl->bloom_downsample_first, false, false); eevee_create_bloom_pass("Bloom Downsample", effects, - e_data.bloom_downsample_sh[0], + EEVEE_shaders_bloom_downsample_get(false), &psl->bloom_downsample, false, false); eevee_create_bloom_pass("Bloom Upsample", effects, - e_data.bloom_upsample_sh[use_highres], + EEVEE_shaders_bloom_upsample_get(use_highres), &psl->bloom_upsample, true, false); grp = eevee_create_bloom_pass("Bloom Blit", effects, - e_data.bloom_blit_sh[use_antiflicker], + EEVEE_shaders_bloom_blit_get(use_antiflicker), &psl->bloom_blit, false, false); @@ -274,7 +232,7 @@ void EEVEE_bloom_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *ved grp = eevee_create_bloom_pass("Bloom Resolve", effects, - e_data.bloom_resolve_sh[use_highres], + EEVEE_shaders_bloom_resolve_get(use_highres), &psl->bloom_resolve, true, true); @@ -362,7 +320,7 @@ void EEVEE_bloom_output_init(EEVEE_ViewLayerData *UNUSED(sldata), /* Create Pass and shgroup. */ DRWShadingGroup *grp = eevee_create_bloom_pass("Bloom Accumulate", effects, - e_data.bloom_resolve_sh[use_highres], + EEVEE_shaders_bloom_resolve_get(use_highres), &psl->bloom_accum_ps, true, true); @@ -383,13 +341,3 @@ void EEVEE_bloom_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Da GPU_framebuffer_bind(fbl->main_fb); } } - -void EEVEE_bloom_free(void) -{ - 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]); - } -} diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index 6ab267ceb03..d5fd11040e3 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_bloom_free(); EEVEE_depth_of_field_free(); EEVEE_effects_free(); EEVEE_lightprobes_free(); diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index b25f21ce929..7fba0e1b8ed 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -1072,6 +1072,10 @@ void EEVEE_random_rotation_m4(int sample_ofs, float scale, float r_mat[4][4]); void EEVEE_shaders_lightprobe_shaders_init(void); void EEVEE_shaders_material_shaders_init(void); struct DRWShaderLibrary *EEVEE_shader_lib_get(void); +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_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); @@ -1163,7 +1167,6 @@ void EEVEE_bloom_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata); void EEVEE_bloom_draw(EEVEE_Data *vedata); void EEVEE_bloom_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples); void EEVEE_bloom_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata); -void EEVEE_bloom_free(void); /* eevee_occlusion.c */ int EEVEE_occlusion_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 5f125d395d3..6c90d6325a0 100644 --- a/source/blender/draw/engines/eevee/eevee_shaders.c +++ b/source/blender/draw/engines/eevee/eevee_shaders.c @@ -69,6 +69,12 @@ static struct { struct GPUShader *taa_resolve_sh; struct GPUShader *taa_resolve_reproject_sh; + /* Bloom */ + struct GPUShader *bloom_blit_sh[2]; + struct GPUShader *bloom_downsample_sh[2]; + struct GPUShader *bloom_upsample_sh[2]; + struct GPUShader *bloom_resolve_sh[2]; + /* General purpose Shaders. */ struct GPUShader *lookdev_background; struct GPUShader *update_noise_sh; @@ -405,6 +411,62 @@ GPUShader *EEVEE_shaders_taa_resolve_sh_get(EEVEE_EffectsFlag enabled_effects) return *sh; } +GPUShader *EEVEE_shaders_bloom_blit_get(bool high_quality) +{ + int index = high_quality ? 1 : 0; + + if (e_data.bloom_blit_sh[index] == NULL) { + const char *define = high_quality ? "#define STEP_BLIT\n" + "#define HIGH_QUALITY\n" : + "#define STEP_BLIT\n"; + e_data.bloom_blit_sh[index] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, + define); + } + return e_data.bloom_blit_sh[index]; +} + +GPUShader *EEVEE_shaders_bloom_downsample_get(bool high_quality) +{ + int index = high_quality ? 1 : 0; + + if (e_data.bloom_downsample_sh[index] == NULL) { + const char *define = high_quality ? "#define STEP_DOWNSAMPLE\n" + "#define HIGH_QUALITY\n" : + "#define STEP_DOWNSAMPLE\n"; + e_data.bloom_downsample_sh[index] = DRW_shader_create_fullscreen( + datatoc_effect_bloom_frag_glsl, define); + } + return e_data.bloom_downsample_sh[index]; +} + +GPUShader *EEVEE_shaders_bloom_upsample_get(bool high_quality) +{ + int index = high_quality ? 1 : 0; + + if (e_data.bloom_upsample_sh[index] == NULL) { + const char *define = high_quality ? "#define STEP_UPSAMPLE\n" + "#define HIGH_QUALITY\n" : + "#define STEP_UPSAMPLE\n"; + e_data.bloom_upsample_sh[index] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, + define); + } + return e_data.bloom_upsample_sh[index]; +} + +GPUShader *EEVEE_shaders_bloom_resolve_get(bool high_quality) +{ + int index = high_quality ? 1 : 0; + + if (e_data.bloom_resolve_sh[index] == NULL) { + const char *define = high_quality ? "#define STEP_RESOLVE\n" + "#define HIGH_QUALITY\n" : + "#define STEP_RESOLVE\n"; + e_data.bloom_resolve_sh[index] = DRW_shader_create_fullscreen(datatoc_effect_bloom_frag_glsl, + define); + } + return e_data.bloom_resolve_sh[index]; +} + Material *EEVEE_material_default_diffuse_get(void) { if (!e_data.diffuse_mat) { @@ -771,6 +833,13 @@ 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_LIB_FREE_SAFE(e_data.lib); if (e_data.default_world) { diff --git a/source/blender/draw/tests/shaders_test.cc b/source/blender/draw/tests/shaders_test.cc index c991b791686..124049a13e2 100644 --- a/source/blender/draw/tests/shaders_test.cc +++ b/source/blender/draw/tests/shaders_test.cc @@ -252,6 +252,14 @@ TEST_F(DrawTest, eevee_glsl_shaders_static) EEVEE_shaders_lightprobe_shaders_init(); EEVEE_shaders_material_shaders_init(); + EXPECT_NE(EEVEE_shaders_bloom_blit_get(false), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_blit_get(true), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_downsample_get(false), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_downsample_get(true), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_upsample_get(false), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_upsample_get(true), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_resolve_get(false), nullptr); + EXPECT_NE(EEVEE_shaders_bloom_resolve_get(true), nullptr); EXPECT_NE(EEVEE_shaders_probe_filter_glossy_sh_get(), nullptr); EXPECT_NE(EEVEE_shaders_probe_filter_diffuse_sh_get(), nullptr); EXPECT_NE(EEVEE_shaders_probe_filter_visibility_sh_get(), nullptr); |