[Bf-blender-cvs] [e13f5cc5aea] tmp-eevee-shadowmap-refactor: Eevee: Shadow: Speedup: Only render shadow cube face needed

Clément Foucault noreply at git.blender.org
Mon Sep 2 16:53:33 CEST 2019


Commit: e13f5cc5aea6ec851ea4ea41a1057853505a6801
Author: Clément Foucault
Date:   Fri Aug 30 03:12:45 2019 +0200
Branches: tmp-eevee-shadowmap-refactor
https://developer.blender.org/rBe13f5cc5aea6ec851ea4ea41a1057853505a6801

Eevee: Shadow: Speedup: Only render shadow cube face needed

This reduce the number of face to render to 5 in the case of area lights
and 5 or 1 for spotlights.

Spotlights that have a spot size less than 90 degrees only need 1 face and
are the fastest.

===================================================================

M	source/blender/draw/engines/eevee/eevee_lights.c

===================================================================

diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
index 6a7376db557..76e7340a20f 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -688,12 +688,13 @@ static void eevee_shadow_cube_setup(Object *ob,
   Light *la = (Light *)ob->data;
 
   normalize_m4_m4(cube_data->shadowmat, ob->obmat);
-  copy_v3_v3(cube_data->position, ob->obmat[3]);
 
   if (linfo->soft_shadows) {
     shadow_cube_random_position_set(evli, la, sample_ofs, cube_data->shadowmat[3]);
   }
 
+  copy_v3_v3(cube_data->position, cube_data->shadowmat[3]);
+
   invert_m4(cube_data->shadowmat);
 
   ubo_data->bias = 0.05f * la->bias;
@@ -1212,6 +1213,7 @@ void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, DRWView
   /* Render each shadow to one layer of the array */
   for (i = 0; (ob = linfo->shadow_cube_ref[i]) && (i < MAX_SHADOW_CUBE); i++) {
     EEVEE_LightEngineData *led = EEVEE_light_data_ensure(ob);
+    Light *la = (Light *)ob->data;
 
     if (!led->need_update || !cube_visible[i]) {
       continue;
@@ -1233,6 +1235,17 @@ void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, DRWView
      * The only time it's more beneficial is when the CPU culling overhead
      * outweigh the instancing overhead. which is rarely the case. */
     for (int j = 0; j < 6; j++) {
+      /* Optimization: Only render the needed faces. */
+      /* Skip all but -Z face. */
+      if (la->type == LA_SPOT && la->spotsize < DEG2RADF(90.0f) && j != 5)
+        continue;
+      /* Skip +Z face. */
+      if (la->type != LA_LOCAL && j == 4)
+        continue;
+      /* TODO(fclem) some cube sides can be invisible in the main views. Cull them. */
+      // if (frustum_intersect(g_data->cube_views[j], main_view))
+      //   continue;
+
       DRW_view_set_active(g_data->cube_views[j]);
       int layer = i * 6 + j;
       GPU_framebuffer_texture_layer_attach(



More information about the Bf-blender-cvs mailing list