Eevee: Transparency: Add transparent Shadow method UI.
authorClément Foucault <foucault.clem@gmail.com>
Tue, 11 Jul 2017 10:39:20 +0000 (12:39 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Tue, 11 Jul 2017 10:39:35 +0000 (12:39 +0200)
release/scripts/startup/bl_ui/properties_material.py
source/blender/draw/engines/eevee/eevee_materials.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesrna/intern/rna_material.c

index 88fc2a427344bfd49593e7376584f701e4e423d5..e7e920007235b89659d5bfe82fd0b60580206f7a 100644 (file)
@@ -1172,12 +1172,18 @@ class EEVEE_MATERIAL_PT_options(MaterialButtonsPanel, Panel):
 
         layout.prop(mat, "blend_method")
 
-        if mat.blend_method not in {"CLIP", "HASHED"}:
-            layout.prop(mat, "blend_hide_backside")
+        if mat.blend_method != "OPAQUE":
+            layout.prop(mat, "transparent_shadow_method")
 
-        if mat.blend_method == "CLIP":
+            row = layout.row()
+            row.active = ((mat.blend_method == "CLIP") or (mat.transparent_shadow_method == "CLIP"))
             layout.prop(mat, "alpha_threshold")
 
+        if mat.blend_method not in {"OPAQUE", "CLIP", "HASHED"}:
+            layout.prop(mat, "transparent_hide_backside")
+
+
+
 classes = (
     MATERIAL_MT_sss_presets,
     MATERIAL_MT_specials,
index ab56b90841689a7a237517cb9e95f83cd97cde83..b635b128520c6bd27a6ff1f7e70b8a012fbffc77 100644 (file)
@@ -997,15 +997,27 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sl
                                ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, mat_geom[i]);
 
                                /* Shadow Pass */
-                               if (ma->blend_method == MA_BM_SOLID)
-                                       EEVEE_lights_cache_shcaster_add(sldata, psl, mat_geom[i], ob->obmat);
-                               else if (ma->blend_method == MA_BM_HASHED) {
-                                       struct GPUMaterial *gpumat = EEVEE_material_mesh_depth_get(scene, ma, true, true);
-                                       EEVEE_lights_cache_shcaster_material_add(sldata, psl, gpumat, mat_geom[i], ob->obmat, NULL);
+                               if (ma->blend_method != MA_BM_SOLID) {
+                                       struct GPUMaterial *gpumat;
+                                       switch (ma->blend_shadow) {
+                                               case MA_BS_SOLID:
+                                                       EEVEE_lights_cache_shcaster_add(sldata, psl, mat_geom[i], ob->obmat);
+                                                       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->obmat, &ma->alpha_threshold);
+                                                       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->obmat, NULL);
+                                                       break;
+                                               case MA_BS_NONE:
+                                               default:
+                                                       break;
+                                       }
                                }
-                               else if (ma->blend_method == MA_BM_CLIP) {
-                                       struct GPUMaterial *gpumat = EEVEE_material_mesh_depth_get(scene, ma, false, true);
-                                       EEVEE_lights_cache_shcaster_material_add(sldata, psl, gpumat, mat_geom[i], ob->obmat, &ma->alpha_threshold);
+                               else {
+                                       EEVEE_lights_cache_shcaster_add(sldata, psl, mat_geom[i], ob->obmat);
                                }
                        }
                }
index 4af8ec70b8d605e23ea501959e23c477b703e483..41ad12e63f2a7d59ed4c697c14816a9d79563eaf 100644 (file)
@@ -214,8 +214,9 @@ typedef struct Material {
        /* Transparency */
        float alpha_threshold;
        char blend_method;
+       char blend_shadow;
        char blend_flag;
-       char pad6[2];
+       char pad6;
 
        /* image to use for image/uv space, also bake target
         * (not to be used shading/rendering pipeline, this is editor featyure only!). */
@@ -512,5 +513,13 @@ enum {
        MA_BL_HIDE_BACKSIDE =       (1 << 0),
 };
 
+/* blend_shadow */
+enum {
+       MA_BS_NONE = 0,
+       MA_BS_SOLID,
+       MA_BS_CLIP,
+       MA_BS_HASHED,
+};
+
 #endif
 
index 1d9302f5d37040dd3cc13ba0440cab3abaca950b..d01ce407815406cda248e1cb11805824fe06e8cc 100644 (file)
@@ -1815,6 +1815,14 @@ void RNA_def_material(BlenderRNA *brna)
                {0, NULL, 0, NULL, NULL}
        };
 
+       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"},
+               {0, NULL, 0, NULL, NULL}
+       };
+
        srna = RNA_def_struct(brna, "Material", "ID");
        RNA_def_struct_ui_text(srna, "Material",
                               "Material data-block to define the appearance of geometric objects for rendering");
@@ -1844,16 +1852,22 @@ 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);
+       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 method for transparent material");
+       RNA_def_property_update(prop, 0, "rna_Material_draw_update");
+
        prop = RNA_def_property(srna, "alpha_threshold", PROP_FLOAT, PROP_FACTOR);
        RNA_def_property_range(prop, 0, 1);
        RNA_def_property_ui_text(prop, "Clip Threshold", "A pixel is rendered only if its alpha value is above this threshold");
-       RNA_def_property_update(prop, 0, "rna_Material_update");
+       RNA_def_property_update(prop, 0, "rna_Material_draw_update");
 
-       prop = RNA_def_property(srna, "blend_hide_backside", PROP_BOOLEAN, PROP_NONE);
+       prop = RNA_def_property(srna, "transparent_hide_backside", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "blend_flag", MA_BL_HIDE_BACKSIDE);
        RNA_def_property_ui_text(prop, "Hide Backside" , "Limit transparency to a single layer "
                                                         "(avoids transparency sorting problems)");
-       RNA_def_property_update(prop, 0, "rna_Material_update");
+       RNA_def_property_update(prop, 0, "rna_Material_draw_update");
 
        /* For Preview Render */
        prop = RNA_def_property(srna, "preview_render_type", PROP_ENUM, PROP_NONE);