Eevee: SSR: Add Weight Normalization option.
authorClément Foucault <foucault.clem@gmail.com>
Sat, 22 Jul 2017 12:41:34 +0000 (14:41 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Mon, 24 Jul 2017 13:28:27 +0000 (15:28 +0200)
release/scripts/startup/bl_ui/properties_render.py
release/scripts/startup/bl_ui/properties_render_layer.py
source/blender/draw/engines/eevee/eevee_effects.c
source/blender/draw/engines/eevee/eevee_engine.c
source/blender/draw/engines/eevee/eevee_private.h
source/blender/makesrna/intern/rna_scene.c

index d93d76160f2ad85b1f7ae0970d1630a62018a73f..2ab67e5651d91341501a54c567ec9defc119bd00 100644 (file)
@@ -727,6 +727,7 @@ class RENDER_PT_eevee_shading(RenderButtonsPanel, Panel):
         col = layout.column()
         col.prop(props, "ssr_enable")
         col.prop(props, "ssr_halfres")
+        col.prop(props, "ssr_normalize_weight")
         col.prop(props, "ssr_stride")
         col.prop(props, "ssr_thickness")
         col.prop(props, "ssr_border_fade")
index fefeba9b87023939ff177382d1363c8fa076e307..e8bbf69f94715ca7509a6e362545da16fcec9eaf 100644 (file)
@@ -269,8 +269,10 @@ class RENDERLAYER_PT_eevee_shading(RenderLayerButtonsPanel, Panel):
         col = layout.column()
         col.template_override_property(layer_props, scene_props, "ssr_enable")
         col.template_override_property(layer_props, scene_props, "ssr_halfres")
+        col.template_override_property(layer_props, scene_props, "ssr_normalize_weight")
         col.template_override_property(layer_props, scene_props, "ssr_stride")
         col.template_override_property(layer_props, scene_props, "ssr_thickness")
+        col.template_override_property(layer_props, scene_props, "ssr_border_fade")
 
 
 classes = (
index 65e02350c22cf5d83f4dd0316ff7a5f8943e3623..a48332f0ad46d1f2afaf386d2cf5e223342db10f 100644 (file)
@@ -89,6 +89,8 @@ static struct {
        struct GPUShader *ssr_raytrace_full_sh;
        struct GPUShader *ssr_resolve_sh;
        struct GPUShader *ssr_resolve_full_sh;
+       struct GPUShader *ssr_resolve_norm_sh;
+       struct GPUShader *ssr_resolve_full_norm_sh;
 
        /* Simple Downsample */
        struct GPUShader *downsample_sh;
@@ -202,8 +204,13 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
                e_data.ssr_raytrace_full_sh = DRW_shader_create_fullscreen(ssr_shader_str, SHADER_DEFINES "#define STEP_RAYTRACE\n"
                                                                                                          "#define FULLRES\n");
                e_data.ssr_resolve_sh = DRW_shader_create_fullscreen(ssr_shader_str, SHADER_DEFINES "#define STEP_RESOLVE\n");
+               e_data.ssr_resolve_norm_sh = DRW_shader_create_fullscreen(ssr_shader_str, SHADER_DEFINES "#define STEP_RESOLVE\n"
+                                                                                                            "#define USE_NORMALIZATION\n");
                e_data.ssr_resolve_full_sh = DRW_shader_create_fullscreen(ssr_shader_str, SHADER_DEFINES "#define STEP_RESOLVE\n"
                                                                                                         "#define FULLRES\n");
+               e_data.ssr_resolve_full_norm_sh = DRW_shader_create_fullscreen(ssr_shader_str, SHADER_DEFINES "#define STEP_RESOLVE\n"
+                                                                                                             "#define USE_NORMALIZATION\n"
+                                                                                                             "#define FULLRES\n");
 
                MEM_freeN(ssr_shader_str);
 
@@ -549,6 +556,7 @@ void EEVEE_effects_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
                effects->enabled_effects |= EFFECT_DOUBLE_BUFFER;
 
                effects->reflection_trace_full = !BKE_collection_engine_property_value_get_bool(props, "ssr_halfres");
+               effects->ssr_use_normalization = BKE_collection_engine_property_value_get_bool(props, "ssr_normalize_weight");
                effects->ssr_stride = (float)BKE_collection_engine_property_value_get_int(props, "ssr_stride");
                effects->ssr_thickness = BKE_collection_engine_property_value_get_float(props, "ssr_thickness");
                effects->ssr_border_fac = BKE_collection_engine_property_value_get_float(props, "ssr_border_fade");
@@ -715,7 +723,13 @@ void EEVEE_effects_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata)
 
        if ((effects->enabled_effects & EFFECT_SSR) != 0) {
                struct GPUShader *trace_shader = (effects->reflection_trace_full) ? e_data.ssr_raytrace_full_sh : e_data.ssr_raytrace_sh;
-               struct GPUShader *resolve_shader = (effects->reflection_trace_full) ? e_data.ssr_resolve_full_sh : e_data.ssr_resolve_sh;
+               struct GPUShader *resolve_shader = NULL;
+               if (effects->ssr_use_normalization) {
+                       resolve_shader = (effects->reflection_trace_full) ? e_data.ssr_resolve_full_norm_sh : e_data.ssr_resolve_norm_sh;
+               }
+               else {
+                       resolve_shader = (effects->reflection_trace_full) ? e_data.ssr_resolve_full_sh : e_data.ssr_resolve_sh;
+               }
 
                psl->ssr_raytrace = DRW_pass_create("SSR Raytrace", DRW_STATE_WRITE_COLOR);
                DRWShadingGroup *grp = DRW_shgroup_create(trace_shader, psl->ssr_raytrace);
@@ -1215,6 +1229,8 @@ void EEVEE_effects_free(void)
        DRW_SHADER_FREE_SAFE(e_data.ssr_raytrace_full_sh);
        DRW_SHADER_FREE_SAFE(e_data.ssr_resolve_sh);
        DRW_SHADER_FREE_SAFE(e_data.ssr_resolve_full_sh);
+       DRW_SHADER_FREE_SAFE(e_data.ssr_resolve_norm_sh);
+       DRW_SHADER_FREE_SAFE(e_data.ssr_resolve_full_norm_sh);
 
        DRW_SHADER_FREE_SAFE(e_data.volumetric_upsample_sh);
 
index 29f5380de8560908c21bb6e60f970962102939f8..0f6548d877de6f41ce5140e66f057d764cc90b59 100644 (file)
@@ -212,9 +212,10 @@ static void EEVEE_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDPr
                   props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
 
        BKE_collection_engine_property_add_bool(props, "ssr_enable", false);
+       BKE_collection_engine_property_add_bool(props, "ssr_normalize_weight", false);
        BKE_collection_engine_property_add_bool(props, "ssr_halfres", true);
        BKE_collection_engine_property_add_int(props, "ssr_stride", 16);
-       BKE_collection_engine_property_add_float(props, "ssr_thickness", 0.5f);
+       BKE_collection_engine_property_add_float(props, "ssr_thickness", 0.2f);
        BKE_collection_engine_property_add_float(props, "ssr_border_fade", 0.075f);
 
        BKE_collection_engine_property_add_bool(props, "volumetric_enable", false);
index 4c27f940d92d422c69f9b38e8a84a8f9fdf4243f..824c338b9273783f4eff447ad092a543a1809440 100644 (file)
@@ -319,6 +319,7 @@ typedef struct EEVEE_EffectsInfo {
        /* SSR */
        bool use_ssr;
        bool reflection_trace_full;
+       bool ssr_use_normalization;
        float ssr_border_fac;
        float ssr_stride;
        float ssr_thickness;
index 24358d862eb045bd80a6e8d1145aed9358c010e0..90dab17069e64836c1ce877415aec8f440dad526 100644 (file)
@@ -2624,6 +2624,7 @@ RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_shadow_samples)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_colored_transmittance)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_enable)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_halfres)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_normalize_weight)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(ssr_stride)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_thickness)
 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_border_fade)
@@ -6196,6 +6197,13 @@ 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, "ssr_normalize_weight", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_normalize_weight_get",
+                                      "rna_LayerEngineSettings_Eevee_ssr_normalize_weight_set");
+       RNA_def_property_ui_text(prop, "Weight Normalize", "Fills low resolution in reflection but exhibit harsh transition");
+       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, "ssr_stride", PROP_INT, PROP_PIXEL);
        RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_stride_get",
                                       "rna_LayerEngineSettings_Eevee_ssr_stride_set", NULL);