Edit Mesh: Make "fresnel effect" not transparent but mix between 2 colors
authorClément Foucault <foucault.clem@gmail.com>
Mon, 10 Dec 2018 17:30:37 +0000 (18:30 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Mon, 10 Dec 2018 18:02:17 +0000 (19:02 +0100)
Alpha blending is causing too many issues.
Revert back to something simpler.

source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_common.h
source/blender/draw/modes/edit_mesh_mode.c
source/blender/draw/modes/shaders/common_globals_lib.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_points_vert.glsl

index 4d33e6ed80242c295934fcc3e69d9ea48e12e088..09134f139a7dd12b15353e97a1260d5ae6049431 100644 (file)
@@ -87,6 +87,10 @@ void DRW_globals_update(void)
        UI_GetThemeColor4fv(TH_FACE_DOT, ts.colorFaceDot);
        UI_GetThemeColor4fv(TH_BACK, ts.colorBackground);
 
+       /* Custom median color to slightly affect the edit mesh colors. */
+       interp_v4_v4v4(ts.colorEditMeshMiddle, ts.colorVertexSelect, ts.colorWireEdit, 0.35f);
+       copy_v3_fl(ts.colorEditMeshMiddle, dot_v3v3(ts.colorEditMeshMiddle, (float[3]){0.3333f, 0.3333f, 0.3333f})); /* Desaturate */
+
 #ifdef WITH_FREESTYLE
        UI_GetThemeColor4fv(TH_FREESTYLE_EDGE_MARK, ts.colorEdgeFreestyle);
        UI_GetThemeColor4fv(TH_FREESTYLE_FACE_MARK, ts.colorFaceFreestyle);
index f9e9d2adba3b974a7227a9aad8acbe9a1c51fd60..fc9641b06ee38e7a72f5bfd29a281256aa2364e5 100644 (file)
@@ -80,6 +80,7 @@ typedef struct GlobalsUboStorage {
        float colorLampNoAlpha[4];
 
        float colorBackground[4];
+       float colorEditMeshMiddle[4];
 
        float colorHandleFree[4];
        float colorHandleAuto[4];
index a7ae8ebde12494757e913d714a1fd394b59def71..7dc3f3af3e61b596c8009473c24bc79bcb75a7d5 100644 (file)
@@ -360,12 +360,14 @@ static DRWPass *edit_mesh_create_overlay_pass(
                DRW_shgroup_uniform_vec2(*r_lverts_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
                DRW_shgroup_uniform_float(*r_lverts_shgrp, "edgeScale", edge_width_scale, 1);
                DRW_shgroup_state_enable(*r_lverts_shgrp, DRW_STATE_WRITE_DEPTH);
+               DRW_shgroup_state_disable(*r_lverts_shgrp, DRW_STATE_BLEND);
 
                *r_verts_shgrp = DRW_shgroup_create(e_data.overlay_vert_sh, pass);
                DRW_shgroup_uniform_block(*r_verts_shgrp, "globalsBlock", globals_ubo);
                DRW_shgroup_uniform_vec2(*r_verts_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
                DRW_shgroup_uniform_float(*r_verts_shgrp, "edgeScale", edge_width_scale, 1);
                DRW_shgroup_state_enable(*r_verts_shgrp, DRW_STATE_WRITE_DEPTH);
+               DRW_shgroup_state_disable(*r_verts_shgrp, DRW_STATE_BLEND);
        }
 
        if ((tsettings->selectmode & SCE_SELECT_FACE) != 0) {
index 69ba304ca2480ffe3ff240787b7f32dbd4327d7a..520b368bbc2d96fa373284142dad036af2a5f49d 100644 (file)
@@ -36,6 +36,7 @@ layout(std140) uniform globalsBlock {
        vec4 colorLampNoAlpha;
 
        vec4 colorBackground;
+       vec4 colorEditMeshMiddle;
 
        vec4 colorHandleFree;
        vec4 colorHandleAuto;
index 8d7a653c2fed1b6bb8419c259077b31aab9a1fd0..0d5c76ad790d0af2e7d025e50232aee898c4b54e 100644 (file)
@@ -144,7 +144,7 @@ void main()
 #endif
 
 #ifdef VERTEX_FACING
-       FragColor.a *= 1.0 - abs(facing) * 0.4;
+       FragColor.rgb = mix(colorEditMeshMiddle.rgb, FragColor.rgb, 1.0 - abs(facing) * 0.4);
 #endif
 
        /* don't write depth if not opaque */
index 3886213ce4926686835f36f905dbd93bf732bb83..245cbab92d5f45d125abd49052d119087036e50a 100644 (file)
@@ -38,8 +38,10 @@ void main()
                ? normalize(vPos.xyz)
                : vec3(0.0, 0.0, 1.0);
        float facing = dot(view_vec, view_normal);
+       facing = 1.0 - abs(facing) * 0.4;
 
-       finalColor.a *= 1.0 - abs(facing) * 0.4;
+       finalColor = mix(colorEditMeshMiddle, finalColor, facing);
+       finalColor.a = 1.0;
 #endif
 
        if ((data.x & VERTEX_EXISTS) == 0) {