Eevee: Transparency: Add hide backside option.
This commit is contained in:
parent
a098d02718
commit
a57bc75576
|
@ -1172,6 +1172,9 @@ 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 == "CLIP":
|
||||
layout.prop(mat, "alpha_threshold")
|
||||
|
||||
|
|
|
@ -823,7 +823,7 @@ static void material_opaque(
|
|||
|
||||
static void material_transparent(
|
||||
Material *ma, EEVEE_SceneLayerData *sldata, EEVEE_Data *vedata,
|
||||
bool do_cull, bool use_flat_nor, struct GPUMaterial **gpumat, struct DRWShadingGroup **shgrp)
|
||||
bool do_cull, bool use_flat_nor, struct GPUMaterial **gpumat, struct DRWShadingGroup **shgrp, struct DRWShadingGroup **shgrp_depth)
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
|
@ -866,8 +866,14 @@ static void material_transparent(
|
|||
DRW_shgroup_uniform_float(*shgrp, "roughness", rough_p, 1);
|
||||
}
|
||||
|
||||
DRWState cur_state = (do_cull) ? DRW_STATE_CULL_BACK : 0;
|
||||
DRWState all_state = DRW_STATE_CULL_BACK | DRW_STATE_BLEND | DRW_STATE_ADDITIVE | DRW_STATE_MULTIPLY;
|
||||
const bool use_prepass = ((ma->blend_flag & MA_BL_HIDE_BACKSIDE) != 0);
|
||||
|
||||
DRWState all_state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_CULL_BACK | DRW_STATE_DEPTH_LESS | DRW_STATE_DEPTH_EQUAL |
|
||||
DRW_STATE_BLEND | DRW_STATE_ADDITIVE | DRW_STATE_MULTIPLY;
|
||||
|
||||
DRWState cur_state = DRW_STATE_WRITE_COLOR;
|
||||
cur_state |= (use_prepass) ? DRW_STATE_DEPTH_EQUAL : DRW_STATE_DEPTH_LESS;
|
||||
cur_state |= (do_cull) ? DRW_STATE_CULL_BACK : 0;
|
||||
|
||||
switch (ma->blend_method) {
|
||||
case MA_BM_ADD:
|
||||
|
@ -887,6 +893,17 @@ static void material_transparent(
|
|||
/* Disable other blend modes and use the one we want. */
|
||||
DRW_shgroup_state_disable(*shgrp, all_state);
|
||||
DRW_shgroup_state_enable(*shgrp, cur_state);
|
||||
|
||||
/* Depth prepass */
|
||||
if (use_prepass) {
|
||||
*shgrp_depth = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->transparent_pass);
|
||||
|
||||
cur_state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
cur_state |= (do_cull) ? DRW_STATE_CULL_BACK : 0;
|
||||
|
||||
DRW_shgroup_state_disable(*shgrp_depth, all_state);
|
||||
DRW_shgroup_state_enable(*shgrp_depth, cur_state);
|
||||
}
|
||||
}
|
||||
|
||||
void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sldata, Object *ob)
|
||||
|
@ -945,7 +962,7 @@ void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_SceneLayerData *sl
|
|||
case MA_BM_MULTIPLY:
|
||||
case MA_BM_BLEND:
|
||||
material_transparent(ma, sldata, vedata, do_cull, use_flat_nor,
|
||||
&gpumat_array[i], &shgrp_array[i]);
|
||||
&gpumat_array[i], &shgrp_array[i], &shgrp_depth_array[i]);
|
||||
break;
|
||||
default:
|
||||
BLI_assert(0);
|
||||
|
|
|
@ -1270,8 +1270,10 @@ typedef struct ZSortData {
|
|||
|
||||
static int pass_shgroup_dist_sort(void *thunk, const void *a, const void *b)
|
||||
{
|
||||
const DRWCall *call_a = (DRWCall *)((const DRWShadingGroup *)a)->calls.first;
|
||||
const DRWCall *call_b = (DRWCall *)((const DRWShadingGroup *)b)->calls.first;
|
||||
const DRWShadingGroup *shgrp_a = (const DRWShadingGroup *)a;
|
||||
const DRWShadingGroup *shgrp_b = (const DRWShadingGroup *)b;
|
||||
const DRWCall *call_a = (DRWCall *)(shgrp_a)->calls.first;
|
||||
const DRWCall *call_b = (DRWCall *)(shgrp_b)->calls.first;
|
||||
const ZSortData *zsortdata = (ZSortData *)thunk;
|
||||
|
||||
float tmp[3];
|
||||
|
@ -1282,12 +1284,21 @@ static int pass_shgroup_dist_sort(void *thunk, const void *a, const void *b)
|
|||
|
||||
if (a_sq < b_sq) return 1;
|
||||
else if (a_sq > b_sq) return -1;
|
||||
else return 0;
|
||||
else {
|
||||
/* If there is a depth prepass put it before */
|
||||
if ((shgrp_a->state_extra & DRW_STATE_WRITE_DEPTH) != 0) {
|
||||
return -1;
|
||||
}
|
||||
else if ((shgrp_b->state_extra & DRW_STATE_WRITE_DEPTH) != 0) {
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort Shading groups by decreasing Z between
|
||||
* the first call object center and a given world space point.
|
||||
* Sort Shading groups by decreasing Z of their first draw call.
|
||||
* This is usefull for order dependant effect such as transparency.
|
||||
**/
|
||||
void DRW_pass_sort_shgroup_z(DRWPass *pass)
|
||||
{
|
||||
|
|
|
@ -213,7 +213,9 @@ typedef struct Material {
|
|||
|
||||
/* Transparency */
|
||||
float alpha_threshold;
|
||||
char blend_method, pad6[3];
|
||||
char blend_method;
|
||||
char blend_flag;
|
||||
char pad6[2];
|
||||
|
||||
/* image to use for image/uv space, also bake target
|
||||
* (not to be used shading/rendering pipeline, this is editor featyure only!). */
|
||||
|
@ -505,5 +507,10 @@ enum {
|
|||
MA_BM_BLEND,
|
||||
};
|
||||
|
||||
/* blend_flag */
|
||||
enum {
|
||||
MA_BL_HIDE_BACKSIDE = (1 << 0),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1849,6 +1849,12 @@ void RNA_def_material(BlenderRNA *brna)
|
|||
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");
|
||||
|
||||
prop = RNA_def_property(srna, "blend_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");
|
||||
|
||||
/* For Preview Render */
|
||||
prop = RNA_def_property(srna, "preview_render_type", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "pr_type");
|
||||
|
|
Loading…
Reference in New Issue