Cleanup: Eevee: Use dummy texture for GTAO when not enabled
authorClément Foucault <foucault.clem@gmail.com>
Fri, 17 May 2019 17:12:17 +0000 (19:12 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 17 May 2019 17:25:01 +0000 (19:25 +0200)
source/blender/draw/engines/eevee/eevee_materials.c
source/blender/draw/engines/eevee/eevee_occlusion.c

index 0ed5d4a..44e9b98 100644 (file)
@@ -395,13 +395,7 @@ static void add_standard_uniforms(DRWShadingGroup *shgrp,
     DRW_shgroup_uniform_texture_ref(shgrp, "maxzBuffer", &vedata->txl->maxzbuffer);
   }
   if ((use_diffuse || use_glossy) && !use_ssrefraction) {
-    if ((effects->enabled_effects & EFFECT_GTAO) != 0) {
-      DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &effects->gtao_horizons);
-    }
-    else {
-      /* Use maxzbuffer as fallback to avoid sampling problem on certain platform, see: T52593 */
-      DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &vedata->txl->maxzbuffer);
-    }
+    DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &effects->gtao_horizons);
   }
   if (use_diffuse) {
     DRW_shgroup_uniform_texture_ref(shgrp, "irradianceGrid", &lcache->grid_tx.tex);
index 8c1e412..59def36 100644 (file)
@@ -41,6 +41,8 @@ static struct {
   struct GPUShader *gtao_layer_sh;
   struct GPUShader *gtao_debug_sh;
   struct GPUTexture *src_depth;
+
+  struct GPUTexture *dummy_horizon_tx;
 } e_data = {NULL}; /* Engine data */
 
 extern char datatoc_ambient_occlusion_lib_glsl[];
@@ -74,6 +76,11 @@ int EEVEE_occlusion_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
   const DRWContextState *draw_ctx = DRW_context_state_get();
   const Scene *scene_eval = DEG_get_evaluated_scene(draw_ctx->depsgraph);
 
+  if (!e_data.dummy_horizon_tx) {
+    float pixel[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+    e_data.dummy_horizon_tx = DRW_texture_create_2d(1, 1, GPU_RGBA8, DRW_TEX_WRAP, pixel);
+  }
+
   if (scene_eval->eevee.flag & SCE_EEVEE_GTAO_ENABLED) {
     const float *viewport_size = DRW_viewport_size_get();
     const int fs_size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
@@ -117,7 +124,7 @@ int EEVEE_occlusion_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
   }
 
   /* Cleanup */
-  effects->gtao_horizons = NULL;
+  effects->gtao_horizons = e_data.dummy_horizon_tx;
   GPU_FRAMEBUFFER_FREE_SAFE(fbl->gtao_fb);
   common_data->ao_settings = 0.0f;
 
@@ -303,4 +310,5 @@ void EEVEE_occlusion_free(void)
   DRW_SHADER_FREE_SAFE(e_data.gtao_sh);
   DRW_SHADER_FREE_SAFE(e_data.gtao_layer_sh);
   DRW_SHADER_FREE_SAFE(e_data.gtao_debug_sh);
+  DRW_TEXTURE_FREE_SAFE(e_data.dummy_horizon_tx);
 }