Eevee: Material: Decouple transparent shadows from blend mode
authorClément Foucault <foucault.clem@gmail.com>
Fri, 29 Mar 2019 18:18:08 +0000 (19:18 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 29 Mar 2019 18:18:19 +0000 (19:18 +0100)
This makes it easier to exclude a surface from casting shadows and can be
used to manipulate the shadows even for opaque surfaces.

Versionning ensure that old behavior is transfered to new rendering logic.

release/scripts/startup/bl_ui/properties_material.py
source/blender/blenkernel/BKE_blender_version.h
source/blender/blenkernel/intern/material.c
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/eevee/eevee_materials.c
source/blender/makesrna/intern/rna_material.c

index 260e57c..145e9cf 100644 (file)
@@ -213,13 +213,11 @@ class EEVEE_MATERIAL_PT_settings(MaterialButtonsPanel, Panel):
         mat = context.material
 
         layout.prop(mat, "blend_method")
+        layout.prop(mat, "shadow_method")
 
-        if mat.blend_method != 'OPAQUE':
-            layout.prop(mat, "transparent_shadow_method")
-
-            row = layout.row()
-            row.active = ((mat.blend_method == 'CLIP') or (mat.transparent_shadow_method == 'CLIP'))
-            row.prop(mat, "alpha_threshold")
+        row = layout.row()
+        row.active = ((mat.blend_method == 'CLIP') or (mat.shadow_method == 'CLIP'))
+        row.prop(mat, "alpha_threshold")
 
         if mat.blend_method not in {'OPAQUE', 'CLIP', 'HASHED'}:
             layout.prop(mat, "show_transparent_back")
index 66d0c3c..9ae8572 100644 (file)
@@ -24,7 +24,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         280
-#define BLENDER_SUBVERSION      52
+#define BLENDER_SUBVERSION      53
 /* Several breakages with 280, e.g. collections vs layers */
 #define BLENDER_MINVERSION      280
 #define BLENDER_MINSUBVERSION   0
index f708984..52e7c68 100644 (file)
@@ -142,6 +142,7 @@ void BKE_material_init(Material *ma)
 
        ma->alpha_threshold = 0.5f;
 
+       ma->blend_shadow = MA_BS_SOLID;
 }
 
 Material *BKE_material_add(Main *bmain, const char *name)
index 522d036..960fb3b 100644 (file)
@@ -2945,6 +2945,15 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                } FOREACH_NODETREE_END;
        }
 
+       if (!MAIN_VERSION_ATLEAST(bmain, 280, 53)) {
+               for (Material *mat = bmain->materials.first; mat; mat = mat->id.next) {
+                       /* Eevee: Keep material appearance consistent with previous behavior. */
+                       if (!mat->use_nodes || !mat->nodetree || mat->blend_method == MA_BM_SOLID) {
+                               mat->blend_shadow = MA_BS_SOLID;
+                       }
+               }
+       }
+
        {
                /* Versioning code until next subversion bump goes here. */
        }
index ad49d3f..99a3c0c 100644 (file)
@@ -1624,34 +1624,28 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sld
                                        }
 
                                        /* Shadow Pass */
-                                       if (ma->use_nodes && ma->nodetree && (ma->blend_method != MA_BM_SOLID)) {
-                                               struct GPUMaterial *gpumat;
-                                               switch (ma->blend_shadow) {
-                                                       case MA_BS_SOLID:
-                                                               EEVEE_lights_cache_shcaster_add(
-                                                                       sldata, stl, mat_geom[i], ob);
-                                                               *cast_shadow = true;
-                                                               break;
-                                                       case MA_BS_CLIP:
-                                                               gpumat = EEVEE_material_mesh_depth_get(scene, ma, false, true);
-                                                               EEVEE_lights_cache_shcaster_material_add(
-                                                                       sldata, psl, gpumat, mat_geom[i], ob, &ma->alpha_threshold);
-                                                               *cast_shadow = true;
-                                                               break;
-                                                       case MA_BS_HASHED:
-                                                               gpumat = EEVEE_material_mesh_depth_get(scene, ma, true, true);
-                                                               EEVEE_lights_cache_shcaster_material_add(
-                                                                       sldata, psl, gpumat, mat_geom[i], ob, NULL);
-                                                               *cast_shadow = true;
-                                                               break;
-                                                       case MA_BS_NONE:
-                                                       default:
-                                                               break;
-                                               }
-                                       }
-                                       else {
-                                               EEVEE_lights_cache_shcaster_add(sldata, stl, mat_geom[i], ob);
-                                               *cast_shadow = true;
+                                       struct GPUMaterial *gpumat;
+                                       switch (ma->blend_shadow) {
+                                               case MA_BS_SOLID:
+                                                       EEVEE_lights_cache_shcaster_add(
+                                                               sldata, stl, mat_geom[i], ob);
+                                                       *cast_shadow = true;
+                                                       break;
+                                               case MA_BS_CLIP:
+                                                       gpumat = EEVEE_material_mesh_depth_get(scene, ma, false, true);
+                                                       EEVEE_lights_cache_shcaster_material_add(
+                                                               sldata, psl, gpumat, mat_geom[i], ob, &ma->alpha_threshold);
+                                                       *cast_shadow = true;
+                                                       break;
+                                               case MA_BS_HASHED:
+                                                       gpumat = EEVEE_material_mesh_depth_get(scene, ma, true, true);
+                                                       EEVEE_lights_cache_shcaster_material_add(
+                                                               sldata, psl, gpumat, mat_geom[i], ob, NULL);
+                                                       *cast_shadow = true;
+                                                       break;
+                                               case MA_BS_NONE:
+                                               default:
+                                                       break;
                                        }
                                }
                        }
index 9e8604f..5445db7 100644 (file)
@@ -677,8 +677,8 @@ void RNA_def_material(BlenderRNA *brna)
        static EnumPropertyItem prop_eevee_blend_shadow_items[] = {
                {MA_BS_NONE, "NONE", 0, "None", "Material will cast no shadow"},
                {MA_BS_SOLID, "OPAQUE", 0, "Opaque", "Material will cast shadows without transparency"},
-               {MA_BS_CLIP, "CLIP", 0, "Clip", "Use the alpha threshold to clip the visibility (binary visibility)"},
-               {MA_BS_HASHED, "HASHED", 0, "Hashed", "Use noise to dither the binary visibility and use filtering to reduce the noise"},
+               {MA_BS_CLIP, "CLIP", 0, "Alpha Clip", "Use the alpha threshold to clip the visibility (binary visibility)"},
+               {MA_BS_HASHED, "HASHED", 0, "Alpha Hashed", "Use noise to dither the binary visibility and use filtering to reduce the noise"},
                {0, NULL, 0, NULL, NULL},
        };
 
@@ -693,10 +693,10 @@ void RNA_def_material(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Blend Mode", "Blend Mode for Transparent Faces");
        RNA_def_property_update(prop, 0, "rna_Material_draw_update");
 
-       prop = RNA_def_property(srna, "transparent_shadow_method", PROP_ENUM, PROP_NONE);
+       prop = RNA_def_property(srna, "shadow_method", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "blend_shadow");
        RNA_def_property_enum_items(prop, prop_eevee_blend_shadow_items);
-       RNA_def_property_ui_text(prop, "Transparent Shadow", "Shadow mapping method for transparent material");
+       RNA_def_property_ui_text(prop, "Shadow Mode", "Shadow mapping method");
        RNA_def_property_update(prop, 0, "rna_Material_draw_update");
 
        prop = RNA_def_property(srna, "alpha_threshold", PROP_FLOAT, PROP_FACTOR);