Eevee: Material: Decouple transparent shadows from blend mode

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.
This commit is contained in:
Clément Foucault 2019-03-29 19:18:08 +01:00
parent f0a20ae1c9
commit d6747f310f
Notes: blender-bot 2024-01-31 11:35:08 +01:00
Referenced by commit 13eb2e9640, Quick Explode: update for recent eevee shadow refactor
6 changed files with 41 additions and 39 deletions

View 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")

View 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

View 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)

View 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. */
}

View 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;
}
}
}

View 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);