Eevee: Shadow: Add high bitdepth option.
authorClément Foucault <foucault.clem@gmail.com>
Sat, 2 Sep 2017 00:27:28 +0000 (02:27 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Sun, 10 Sep 2017 01:09:45 +0000 (03:09 +0200)
This option is here for reducing the memory usage of shadow maps.

Also lower bitdepth are quicker to process.

release/scripts/startup/bl_ui/properties_render.py
release/scripts/startup/bl_ui/properties_render_layer.py
source/blender/draw/engines/eevee/eevee_engine.c
source/blender/draw/engines/eevee/eevee_lights.c
source/blender/draw/engines/eevee/eevee_private.h
source/blender/makesrna/intern/rna_scene.c

index 49c3c9ad7c9dd3cd724075ddd5c734ef56559787..41e0e925569fd5f21646d6bfafeaad8ebd4f0754 100644 (file)
@@ -763,6 +763,7 @@ class RENDER_PT_eevee_shadows(RenderButtonsPanel, Panel):
         col = layout.column()
         col.prop(props, "shadow_method")
         col.prop(props, "shadow_size")
+        col.prop(props, "shadow_high_bitdepth")
 
 
 classes = (
index 250a4ea61a3b63fbdbed8a8b2862f8bfa534fd52..796580516038fcb1e7f2b2d434f0570607be2068 100644 (file)
@@ -309,6 +309,7 @@ class RENDERLAYER_PT_eevee_shadows(RenderLayerButtonsPanel, Panel):
         col = layout.column()
         col.template_override_property(layer_props, scene_props, "shadow_method")
         col.template_override_property(layer_props, scene_props, "shadow_size")
+        col.template_override_property(layer_props, scene_props, "shadow_high_bitdepth")
 
 
 classes = (
index 735c3a77c5d102a488db0822a80bf013c21dea7f..8d3d749d55a4ce244648955c2d58426bff0b7c62 100644 (file)
@@ -312,6 +312,7 @@ static void EEVEE_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDPr
 
        BKE_collection_engine_property_add_int(props, "shadow_method", SHADOW_ESM);
        BKE_collection_engine_property_add_int(props, "shadow_size", 512);
+       BKE_collection_engine_property_add_bool(props, "shadow_high_bitdepth", false);
 }
 
 static const DrawEngineDataSize EEVEE_data_size = DRW_VIEWPORT_DATA_SIZE(EEVEE_Data);
index b70cfcb01dc955444550c4c50a5d0732d431c3c4..0033670528a4e64a5177c874c62ff2c04b9f1d04 100644 (file)
@@ -97,13 +97,19 @@ void EEVEE_lights_init(EEVEE_SceneLayerData *sldata)
 
        int sh_method = BKE_collection_engine_property_value_get_int(props, "shadow_method");
        int sh_size = BKE_collection_engine_property_value_get_int(props, "shadow_size");
+       int sh_high_bitdepth = BKE_collection_engine_property_value_get_int(props, "shadow_high_bitdepth");
 
        EEVEE_LampsInfo *linfo = sldata->lamps;
-       if ((linfo->shadow_size != sh_size) || (linfo->shadow_method != sh_method)) {
+       if ((linfo->shadow_size != sh_size) ||
+               (linfo->shadow_method != sh_method) ||
+               (linfo->shadow_high_bitdepth != sh_high_bitdepth))
+       {
                BLI_assert((sh_size > 0) && (sh_size <= 8192));
                DRW_TEXTURE_FREE_SAFE(sldata->shadow_pool);
+               DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
                DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_target);
 
+               linfo->shadow_high_bitdepth = sh_high_bitdepth;
                linfo->shadow_method = sh_method;
                linfo->shadow_size = sh_size;
                linfo->shadow_render_data.stored_texel_size = 1.0 / (float)linfo->shadow_size;
@@ -115,11 +121,8 @@ void EEVEE_lights_init(EEVEE_SceneLayerData *sldata)
 
                CLAMP(new_cube_target_size, 1, 4096);
 
-               if (linfo->shadow_cube_target_size != new_cube_target_size) {
-                       linfo->shadow_cube_target_size = new_cube_target_size;
-                       DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
-                       linfo->shadow_render_data.cube_texel_size = 1.0 / (float)linfo->shadow_cube_target_size;
-               }
+               linfo->shadow_cube_target_size = new_cube_target_size;
+               linfo->shadow_render_data.cube_texel_size = 1.0 / (float)linfo->shadow_cube_target_size;
        }
 }
 
@@ -279,8 +282,8 @@ void EEVEE_lights_cache_finish(EEVEE_SceneLayerData *sldata)
        }
 
        switch (linfo->shadow_method) {
-               case SHADOW_ESM: shadow_pool_format = DRW_TEX_R_32; break;
-               case SHADOW_VSM: shadow_pool_format = DRW_TEX_RG_32; break;
+               case SHADOW_ESM: shadow_pool_format = ((linfo->shadow_high_bitdepth) ? DRW_TEX_R_32 : DRW_TEX_R_16); break;
+               case SHADOW_VSM: shadow_pool_format = ((linfo->shadow_high_bitdepth) ? DRW_TEX_RG_32 : DRW_TEX_RG_16); break;
                default:
                        BLI_assert(!"Incorrect Shadow Method");
                        break;
index 724764b5291a9a71333f11efff4b9509c6235cf8..1e994c8d1fa9525ea62fb3737d1477fef56650bf 100644 (file)
@@ -249,6 +249,7 @@ typedef struct EEVEE_LampsInfo {
        int num_shadow, cache_num_shadow;
        int update_flag;
        int shadow_size, shadow_method;
+       bool shadow_high_bitdepth;
        int shadow_cube_target_size;
        /* List of lights in the scene. */
        /* XXX This is fragile, can get out of sync quickly. */
index f763f2bf454320fe8167d5f062245b0d4742541d..119432f7ed3ac9d164e90a501669f6690a241864 100644 (file)
@@ -2660,6 +2660,7 @@ RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_border_fade)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_firefly_fac)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(shadow_method)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(shadow_size)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(shadow_high_bitdepth)
 
 /* object engine */
 RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(show_wire)
@@ -6568,6 +6569,12 @@ static void rna_def_scene_layer_engine_settings_eevee(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
        RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_SceneLayerEngineSettings_update");
 
+       prop = RNA_def_property(srna, "shadow_high_bitdepth", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_shadow_high_bitdepth_get", "rna_LayerEngineSettings_Eevee_shadow_high_bitdepth_set");
+       RNA_def_property_ui_text(prop, "High Bitdepth", "Use 32bit shadows");
+       RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+       RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_SceneLayerEngineSettings_update");
+
        RNA_define_verify_sdna(1); /* not in sdna */
 }