[Bf-blender-cvs] [6adaa4202a4] tmp-eevee-shadowmap-refactor: EEVEE: Fix spotlight shadow optimization

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


Commit: 6adaa4202a4510d9c9b5985201f1d0ece2b7de25
Author: Clément Foucault
Date:   Mon Sep 2 01:03:36 2019 +0200
Branches: tmp-eevee-shadowmap-refactor
https://developer.blender.org/rB6adaa4202a4510d9c9b5985201f1d0ece2b7de25

EEVEE: Fix spotlight shadow optimization

Spot light can be non-uniform and scale in one direction. This fix makes
sure both directions are taken into account before skipping cubemap faces.

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

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

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

diff --git a/source/blender/draw/engines/eevee/eevee_shadows_cube.c b/source/blender/draw/engines/eevee/eevee_shadows_cube.c
index 423a7cee52d..95fd91329af 100644
--- a/source/blender/draw/engines/eevee/eevee_shadows_cube.c
+++ b/source/blender/draw/engines/eevee/eevee_shadows_cube.c
@@ -164,6 +164,19 @@ static void eevee_ensure_cube_views(
   }
 }
 
+/* Does a spot angle fits a single cubeface. */
+static bool spot_angle_fit_single_face(const EEVEE_Light *evli)
+{
+  /* alpha = spot/cone half angle. */
+  /* beta = scaled spot/cone half angle. */
+  float cos_alpha = evli->spotsize;
+  float sin_alpha = sqrtf(max_ff(0.0f, 1.0f - cos_alpha * cos_alpha));
+  float cos_beta = min_ff(cos_alpha / hypotf(cos_alpha, sin_alpha * evli->sizex),
+                          cos_alpha / hypotf(cos_alpha, sin_alpha * evli->sizey));
+  /* Don't use 45 degrees because AA jitter can offset the face. */
+  return cos_beta > cosf(DEG2RADF(42.0f));
+}
+
 void EEVEE_shadows_draw_cubemap(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, int cube_index)
 {
   EEVEE_PassList *psl = vedata->psl;
@@ -188,7 +201,7 @@ void EEVEE_shadows_draw_cubemap(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
   for (int j = 0; j < 6; j++) {
     /* Optimization: Only render the needed faces. */
     /* Skip all but -Z face. */
-    if (evli->light_type == LA_SPOT && j != 5 && evli->spotsize > cosf(DEG2RADF(90.0f) * 0.5f))
+    if (evli->light_type == LA_SPOT && j != 5 && spot_angle_fit_single_face(evli))
       continue;
     /* Skip +Z face. */
     if (evli->light_type != LA_LOCAL && j == 4)



More information about the Bf-blender-cvs mailing list