Commit: 7641f92710a09ea089748896bbad0bf5383ba349 Author: Clément Foucault Date: Wed Aug 9 23:48:42 2017 +0200 Branches: blender2.8 https://developer.blender.org/rB7641f92710a09ea089748896bbad0bf5383ba349
Eevee: Refraction: Make it available for opaque materials. Theses Materials are rendered after the SSR pass. The only difference with previous method is that they have a depth prepass (less overdraw) and are not sorted. =================================================================== M release/scripts/startup/bl_ui/properties_material.py M source/blender/draw/engines/eevee/eevee_engine.c M source/blender/draw/engines/eevee/eevee_materials.c M source/blender/draw/engines/eevee/eevee_private.h M source/blender/makesdna/DNA_material_types.h M source/blender/makesrna/intern/rna_material.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py index 1ad4a5160ce..02025f458e4 100644 --- a/release/scripts/startup/bl_ui/properties_material.py +++ b/release/scripts/startup/bl_ui/properties_material.py @@ -1182,7 +1182,8 @@ class EEVEE_MATERIAL_PT_options(MaterialButtonsPanel, Panel): if mat.blend_method not in {"OPAQUE", "CLIP", "HASHED"}: layout.prop(mat, "transparent_hide_backside") - layout.prop(mat, "transparent_refraction") + + layout.prop(mat, "transparent_screen_refraction") diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index fd8c9c5ea4a..66fe3a7556c 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -194,23 +194,30 @@ static void EEVEE_draw_scene(void *vedata) DRW_draw_pass(psl->probe_display); - /* Volumetrics */ - DRW_stats_group_start("Volumetrics"); - EEVEE_effects_do_volumetrics(sldata, vedata); - DRW_stats_group_end(); - /* Prepare Refraction */ EEVEE_effects_do_refraction(sldata, vedata); /* Restore main FB */ DRW_framebuffer_bind(fbl->main); + /* Opaque refraction */ + DRW_stats_group_start("Opaque Refraction"); + DRW_draw_pass(psl->refract_depth_pass); + DRW_draw_pass(psl->refract_depth_pass_cull); + DRW_draw_pass(psl->refract_pass); + DRW_stats_group_end(); + /* Transparent */ DRW_pass_sort_shgroup_z(psl->transparent_pass); DRW_stats_group_start("Transparent"); DRW_draw_pass(psl->transparent_pass); DRW_stats_group_end(); + /* Volumetrics */ + DRW_stats_group_start("Volumetrics"); + EEVEE_effects_do_volumetrics(sldata, vedata); + DRW_stats_group_end(); + /* Post Process */ DRW_stats_group_start("Post FX"); EEVEE_draw_effects(vedata); diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index b961591178a..cf27cba0b1a 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -855,6 +855,29 @@ void EEVEE_materials_cache_init(EEVEE_Data *vedata) } { + DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE; + psl->refract_depth_pass = DRW_pass_create("Refract Depth Pass", state); + stl->g_data->refract_depth_shgrp = DRW_shgroup_create(e_data.default_prepass_sh, psl->refract_depth_pass); + + state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK; + psl->refract_depth_pass_cull = DRW_pass_create("Refract Depth Pass Cull", state); + stl->g_data->refract_depth_shgrp_cull = DRW_shgroup_create(e_data.default_prepass_sh, psl->refract_depth_pass_cull); + + state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE; + psl->refract_depth_pass_clip = DRW_pass_create("Refract Depth Pass Clip", state); + stl->g_data->refract_depth_shgrp_clip = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->refract_depth_pass_clip); + + state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_CULL_BACK; + psl->refract_depth_pass_clip_cull = DRW_pass_create("Refract Depth Pass Cull Clip", state); + stl->g_data->refract_depth_shgrp_clip_cull = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->refract_depth_pass_clip_cull); + } + + { + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE; + psl->refract_pass = DRW_pass_create("Opaque Refraction Pass", state); + } + + { DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE; psl->transparent_pass = DRW_pass_create("Material Transparent Pass", state); } @@ -897,6 +920,7 @@ static void material_opaque( float *rough_p = &ma->gloss_mir; const bool use_gpumat = (ma->use_nodes && ma->nodetree); + const bool use_refract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) && ((stl->effects->enabled_effects & EFFECT_REFRACT) != 0); EeveeMaterialShadingGroups *emsg = BLI_ghash_lookup(material_hash, (const void *)ma); @@ -907,7 +931,7 @@ static void material_opaque( /* This will have been created already, just perform a lookup. */ *gpumat = (use_gpumat) ? EEVEE_material_mesh_get( - scene, ma, stl->effects->use_ao, stl->effects->use_bent_normals, false, false, false) : NULL; + scene, ma, stl->effects->use_ao, stl->effects->use_bent_normals, false, false, use_refract) : NULL; *gpumat_depth = (use_gpumat) ? EEVEE_material_mesh_depth_get( scene, ma, (ma->blend_method == MA_BM_HASHED), false) : NULL; return; @@ -916,13 +940,14 @@ static void material_opaque( if (use_gpumat) { /* Shading */ *gpumat = EEVEE_material_mesh_get(scene, ma, - stl->effects->use_ao, stl->effects->use_bent_normals, false, false, false); + stl->effects->use_ao, stl->effects->use_bent_normals, false, false, use_refract); - *shgrp = DRW_shgroup_material_create(*gpumat, psl->material_pass); + *shgrp = DRW_shgroup_material_create(*gpumat, use_refract ? psl->refract_pass : psl->material_pass); if (*shgrp) { static int ssr_id; + static float refract_thickness = 0.0f; /* TODO Param */ ssr_id = (stl->effects->use_ssr) ? 0 : -1; - add_standard_uniforms(*shgrp, sldata, vedata, &ssr_id, NULL); + add_standard_uniforms(*shgrp, sldata, vedata, &ssr_id, (use_refract) ? &refract_thickness : NULL); } else { /* Shader failed : pink color */ @@ -939,8 +964,14 @@ static void material_opaque( *gpumat_depth = EEVEE_material_mesh_depth_get(scene, ma, (ma->blend_method == MA_BM_HASHED), false); - *shgrp_depth = DRW_shgroup_material_create(*gpumat_depth, do_cull ? psl->depth_pass_cull : psl->depth_pass); - *shgrp_depth_clip = DRW_shgroup_material_create(*gpumat_depth, do_cull ? psl->depth_pass_clip_cull : psl->depth_pass_clip); + if (use_refract) { + *shgrp_depth = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->refract_depth_pass_cull : psl->refract_depth_pass); + *shgrp_depth_clip = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->refract_depth_pass_clip_cull : psl->refract_depth_pass_clip); + } + else { + *shgrp_depth = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->depth_pass_cull : psl->depth_pass); + *shgrp_depth_clip = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->depth_pass_clip_cull : psl->depth_pass_clip); + } if (*shgrp != NULL) { if (ma->blend_method == MA_BM_CLIP) { @@ -963,8 +994,14 @@ static void material_opaque( /* Fallback default depth prepass */ if (*shgrp_depth == NULL) { - *shgrp_depth = do_cull ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp; - *shgrp_depth_clip = do_cull ? stl->g_data->depth_shgrp_clip_cull : stl->g_data->depth_shgrp_clip; + if (use_refract) { + *shgrp_depth = (do_cull) ? stl->g_data->refract_depth_shgrp_cull : stl->g_data->refract_depth_shgrp; + *shgrp_depth_clip = (do_cull) ? stl->g_data->refract_depth_shgrp_clip_cull : stl->g_data->refract_depth_shgrp_clip; + } + else { + *shgrp_depth = (do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp; + *shgrp_depth_clip = (do_cull) ? stl->g_data->depth_shgrp_clip_cull : stl->g_data->depth_shgrp_clip; + } } emsg = MEM_mallocN(sizeof("EeveeMaterialShadingGroups"), "EeveeMaterialShadingGroups"); @@ -983,7 +1020,7 @@ static void material_transparent( EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl; EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl; - const bool use_refract = ((ma->blend_flag & MA_BL_REFRACTION) != 0) && ((stl->effects->enabled_effects & EFFECT_REFRACT) != 0); + const bool use_refract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) && ((stl->effects->enabled_effects & EFFECT_REFRACT) != 0); float *color_p = &ma->r; float *metal_p = &ma->ray_mirror; diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 04bcd02cb9c..8afa31a03e0 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -125,8 +125,13 @@ typedef struct EEVEE_PassList { struct DRWPass *depth_pass_cull; struct DRWPass *depth_pass_clip; struct DRWPass *depth_pass_clip_cull; + struct DRWPass *refract_depth_pass; + struct DRWPass *refract_depth_pass_cull; + struct DRWPass *refract_depth_pass_clip; + struct DRWPass *refract_depth_pass_clip_cull; struct DRWPass *default_pass[VAR_MAT_MAX]; struct DRWPass *material_pass; + struct DRWPass *refract_pass; struct DRWPass *transparent_pass; struct DRWPass *background_pass; } EEVEE_PassList; @@ -462,6 +467,10 @@ typedef struct EEVEE_PrivateData { struct DRWShadingGroup *depth_shgrp_cull; struct DRWShadingGroup *depth_shgrp_clip; struct DRWShadingGroup *depth_shgrp_clip_cull; + struct DRWShadingGroup *refract_depth_shgrp; + struct DRWShadingGroup *refract_depth_shgrp_cull; + struct DRWShadingGroup *refract_depth_shgrp_clip; + struct DRWShadingGroup *refract_depth_shgrp_clip_cull; struct DRWShadingGroup *cube_display_shgrp; struct DRWShadingGroup *planar_downsample; struct GHash *material_hash; diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h index 71d1cfc8e70..f4f68e112e2 100644 --- a/source/blender/makesdna/DNA_material_types.h +++ b/source/blender/makesdna/DNA_material_types.h @@ -511,7 +511,7 @@ enum { /* blend_flag */ enum { MA_BL_HIDE_BACKSIDE = (1 << 0), - MA_BL_REFRACTION = (1 << 1), + MA_BL_SS_REFRACTION = (1 << 1), }; /* blend_shadow */ diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 40c4345659c..a6427fda464 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -1869,9 +1869,10 @@ void RNA_def_material(BlenderRNA *brna) "(avoids transparency sorting problems)"); RNA_def_property_update(prop, 0, "rn @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs