diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-07-10 19:34:33 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-07-11 13:39:35 +0300 |
commit | a57bc75576e780797a60e2240a12f49247ca9505 (patch) | |
tree | 1382ae0ecbeac165407d2b4c14b0e0fa40c02782 /source/blender/draw | |
parent | a098d02718c64ed34838914bac19aebba76c5e4e (diff) |
Eevee: Transparency: Add hide backside option.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_materials.c | 25 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 21 |
2 files changed, 37 insertions, 9 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 0681780484d..bd6c4b9ccc0 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -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); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index ef000a4f791..812280319e9 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -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) { |