diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-07-01 23:29:16 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-07-01 23:29:16 +0300 |
commit | 2002b29ecd2b8fff6f1320fa194f8d7525bf9b2e (patch) | |
tree | ee226fbed4cafce9e9d97aa1c7db9b47f4a29bda /source/blender | |
parent | c2a762c8e6e529a36b0e8cff5ac9339e084829b4 (diff) |
Workbench: Combine Xray Alpha with object/material alpha ...
... instead of overiding it (previous behavior).
In practice it's not really noticeable.
This means an object with alpha will never be more opaque when enabling
xray.
Diffstat (limited to 'source/blender')
5 files changed, 10 insertions, 9 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c index 04e1255521f..4b4bd74ae76 100644 --- a/source/blender/draw/engines/workbench/workbench_data.c +++ b/source/blender/draw/engines/workbench/workbench_data.c @@ -24,6 +24,8 @@ #include "DNA_userdef_types.h" +#include "ED_view3d.h" + #include "UI_resources.h" #include "GPU_batch.h" @@ -55,6 +57,7 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd) wpd->shading = v3d->shading; wpd->use_color_render_settings = false; } + wpd->shading.xray_alpha = XRAY_ALPHA(v3d); wpd->use_color_management = BKE_scene_check_color_management_enabled(scene); diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 49b84b41744..31549c6f752 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -451,6 +451,8 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) WORKBENCH_PrivateData *wpd = stl->g_data; workbench_private_data_init(wpd); + wpd->shading.xray_alpha = 1.0f; + workbench_dof_engine_init(vedata, camera); if (OIT_ENABLED(wpd)) { @@ -987,8 +989,6 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) int color_type = workbench_material_determine_color_type( wpd, image, ob, use_sculpt_pbvh); if (color_type == V3D_SHADING_MATERIAL_COLOR && mat && mat->a < 1.0) { - /* Hack */ - wpd->shading.xray_alpha = mat->a; material = workbench_forward_get_or_create_material_data( vedata, ob, mat, image, iuser, color_type, 0, use_sculpt_pbvh); has_transp_mat = true; @@ -1009,8 +1009,6 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) int color_type = workbench_material_determine_color_type(wpd, NULL, ob, use_sculpt_pbvh); if ((ob->color[3] < 1.0f) && (color_type == V3D_SHADING_OBJECT_COLOR)) { - /* Hack */ - wpd->shading.xray_alpha = ob->color[3]; material = workbench_forward_get_or_create_material_data( vedata, ob, NULL, NULL, NULL, color_type, 0, use_sculpt_pbvh); has_transp_mat = true; @@ -1046,8 +1044,6 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) for (int i = 0; i < materials_len; ++i) { struct Material *mat = give_current_material(ob, i + 1); if (mat != NULL && mat->a < 1.0f) { - /* Hack */ - wpd->shading.xray_alpha = mat->a; material = workbench_forward_get_or_create_material_data( vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh); has_transp_mat = true; @@ -1071,8 +1067,6 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob) if (geoms != NULL && geoms[i] != NULL) { Material *mat = give_current_material(ob, i + 1); if (mat != NULL && mat->a < 1.0f) { - /* Hack */ - wpd->shading.xray_alpha = mat->a; material = workbench_forward_get_or_create_material_data( vedata, ob, mat, NULL, NULL, V3D_SHADING_MATERIAL_COLOR, 0, use_sculpt_pbvh); has_transp_mat = true; diff --git a/source/blender/draw/engines/workbench/workbench_forward.c b/source/blender/draw/engines/workbench/workbench_forward.c index 612a3901ca0..9245d13eab0 100644 --- a/source/blender/draw/engines/workbench/workbench_forward.c +++ b/source/blender/draw/engines/workbench/workbench_forward.c @@ -178,7 +178,7 @@ WORKBENCH_MaterialData *workbench_forward_get_or_create_material_data(WORKBENCH_ wpd->transparent_accum_uniform_sh, psl->transparent_accum_pass); DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo); - DRW_shgroup_uniform_float_copy(grp, "alpha", wpd->shading.xray_alpha); + DRW_shgroup_uniform_float_copy(grp, "alpha", material_template.alpha); DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)wpd->viewvecs, 3); workbench_material_copy(material, &material_template); if (STUDIOLIGHT_TYPE_MATCAP_ENABLED(wpd)) { diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c index d570fda9dac..0bbe7c978be 100644 --- a/source/blender/draw/engines/workbench/workbench_materials.c +++ b/source/blender/draw/engines/workbench/workbench_materials.c @@ -53,6 +53,7 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd, copy_v3_fl3(data->specular_color, 0.05f, 0.05f, 0.05f); /* Dielectric: 5% reflective. */ data->metallic = 0.0f; data->roughness = 0.632455532f; /* sqrtf(0.4f); */ + data->alpha = wpd->shading.xray_alpha; if (color_type == V3D_SHADING_SINGLE_COLOR) { copy_v3_v3(data->diffuse_color, wpd->shading.single_color); @@ -72,10 +73,12 @@ void workbench_material_update_data(WORKBENCH_PrivateData *wpd, else if (ELEM(color_type, V3D_SHADING_OBJECT_COLOR, V3D_SHADING_VERTEX_COLOR)) { copy_v3_v3(data->diffuse_color, ob->color); copy_v3_v3(data->base_color, data->diffuse_color); + data->alpha *= ob->color[3]; } else { /* V3D_SHADING_MATERIAL_COLOR */ if (mat) { + data->alpha *= mat->a; if (SPECULAR_HIGHLIGHT_ENABLED(wpd)) { copy_v3_v3(data->base_color, &mat->r); mul_v3_v3fl(data->diffuse_color, &mat->r, 1.0f - mat->metallic); diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h index 34196c6aa04..3b62ed33e96 100644 --- a/source/blender/draw/engines/workbench/workbench_private.h +++ b/source/blender/draw/engines/workbench/workbench_private.h @@ -286,6 +286,7 @@ typedef struct WORKBENCH_MaterialData { float base_color[3]; float diffuse_color[3]; float specular_color[3]; + float alpha; float metallic; float roughness; int object_id; |