Fix T56692: The edges are not highlighted in Mark Freestyle Edge
authorClément Foucault <foucault.clem@gmail.com>
Wed, 5 Sep 2018 13:42:32 +0000 (15:42 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 5 Sep 2018 17:00:12 +0000 (19:00 +0200)
This was not ported yet.

source/blender/draw/CMakeLists.txt
source/blender/draw/intern/draw_cache_impl_mesh.c
source/blender/draw/intern/draw_common.c
source/blender/draw/intern/draw_common.h
source/blender/draw/modes/shaders/common_globals_lib.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_common_lib.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl
source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl

index bac3a2f02fbdc618e8e08d85fc5afc989de98534..bfa796da122c3e3158949f3dfd071483b58e739b 100644 (file)
@@ -344,4 +344,8 @@ data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl SRC)
 list(APPEND INC
 )
 
+if(WITH_FREESTYLE)
+       add_definitions(-DWITH_FREESTYLE)
+endif()
+
 blender_add_lib(bf_draw "${SRC}" "${INC}" "${INC_SYS}")
index 8c3ecfadad962b87ad4b80574192b79fad2542c8..1c70d40d6f1dc945f656f69174acdd5d66470a8d 100644 (file)
@@ -1340,6 +1340,7 @@ enum {
        VFLAG_VERTEX_SELECTED = 1 << 1,
        VFLAG_FACE_ACTIVE     = 1 << 2,
        VFLAG_FACE_SELECTED   = 1 << 3,
+       VFLAG_FACE_FREESTYLE  = 1 << 4,
 };
 
 enum {
@@ -1348,6 +1349,7 @@ enum {
        VFLAG_EDGE_SELECTED = 1 << 2,
        VFLAG_EDGE_SEAM     = 1 << 3,
        VFLAG_EDGE_SHARP    = 1 << 4,
+       VFLAG_EDGE_FREESTYLE = 1 << 5,
        /* Beware to not go over 1 << 7
         * (see gpu_shader_edit_mesh_overlay_geom.glsl) */
 };
@@ -1362,6 +1364,16 @@ static uchar mesh_render_data_looptri_flag(MeshRenderData *rdata, const BMFace *
        if (BM_elem_flag_test(efa, BM_ELEM_SELECT))
                fflag |= VFLAG_FACE_SELECTED;
 
+#ifdef WITH_FREESTYLE
+       BMesh *bm = rdata->edit_bmesh->bm;
+       if (CustomData_has_layer(&bm->edata, CD_FREESTYLE_EDGE)) {
+               FreestyleFace *ffa = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
+
+               if (ffa->flag & FREESTYLE_FACE_MARK)
+                       fflag |= VFLAG_FACE_FREESTYLE;
+       }
+#endif
+
        return fflag;
 }
 
@@ -1383,11 +1395,21 @@ static void mesh_render_data_edge_flag(
        if (!BM_elem_flag_test(eed, BM_ELEM_SMOOTH))
                eattr->e_flag |= VFLAG_EDGE_SHARP;
 
+#ifdef WITH_FREESTYLE
+       BMesh *bm = rdata->edit_bmesh->bm;
+       if (CustomData_has_layer(&bm->edata, CD_FREESTYLE_EDGE)) {
+               FreestyleEdge *fed = CustomData_bmesh_get(&bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
+
+               if (fed->flag & FREESTYLE_EDGE_MARK)
+                       eattr->e_flag |= VFLAG_EDGE_FREESTYLE;
+       }
+#endif
+
        /* Use a byte for value range */
        if (rdata->cd.offset.crease != -1) {
                float crease = BM_ELEM_CD_GET_FLOAT(eed, rdata->cd.offset.crease);
                if (crease > 0) {
-                       eattr->crease = (char)(crease * 255.0f);
+                       eattr->crease = (uchar)(crease * 255.0f);
                }
        }
 
@@ -1395,14 +1417,13 @@ static void mesh_render_data_edge_flag(
        if (rdata->cd.offset.bweight != -1) {
                float bweight = BM_ELEM_CD_GET_FLOAT(eed, rdata->cd.offset.bweight);
                if (bweight > 0) {
-                       eattr->bweight = (char)(bweight * 255.0f);
+                       eattr->bweight = (uchar)(bweight * 255.0f);
                }
        }
 }
 
 static uchar mesh_render_data_vertex_flag(MeshRenderData *rdata, const BMVert *eve)
 {
-
        uchar vflag = 0;
 
        /* Current vertex */
index f675740b41485203d70966aa4605bd48304b1277..4e903b264c67eb7abb285e29014fd628303fcd6b 100644 (file)
@@ -78,6 +78,14 @@ void DRW_globals_update(void)
        UI_GetThemeColor4fv(TH_FACE_DOT, ts.colorFaceDot);
        UI_GetThemeColor4fv(TH_BACK, ts.colorBackground);
 
+#ifdef WITH_FREESTYLE
+       UI_GetThemeColor4fv(TH_FREESTYLE_EDGE_MARK, ts.colorEdgeFreestyle);
+       UI_GetThemeColor4fv(TH_FREESTYLE_FACE_MARK, ts.colorFaceFreestyle);
+#else
+       zero_v4(ts.colorEdgeFreestyle);
+       zero_v4(ts.colorFaceFreestyle);
+#endif
+
        /* Curve */
        UI_GetThemeColor4fv(TH_HANDLE_FREE, ts.colorHandleFree);
        UI_GetThemeColor4fv(TH_HANDLE_AUTO, ts.colorHandleAuto);
index bab6c67a081d40ced942605e68bb2868b4aec805..c402f63f6a22988a1e02f770c2244d1d595a95f2 100644 (file)
@@ -60,8 +60,10 @@ typedef struct GlobalsUboStorage {
        float colorEdgeCrease[4];
        float colorEdgeBWeight[4];
        float colorEdgeFaceSelect[4];
+       float colorEdgeFreestyle[4];
        float colorFace[4];
        float colorFaceSelect[4];
+       float colorFaceFreestyle[4];
        float colorNormal[4];
        float colorVNormal[4];
        float colorLNormal[4];
index c55457bb6d2a08c78974764ca3b26e09ad09951e..c0243838c65ffafca02eba519384898104d74eaa 100644 (file)
@@ -21,13 +21,14 @@ layout(std140) uniform globalsBlock {
        vec4 colorEdgeCrease;
        vec4 colorEdgeBWeight;
        vec4 colorEdgeFaceSelect;
+       vec4 colorEdgeFreestyle;
        vec4 colorFace;
        vec4 colorFaceSelect;
+       vec4 colorFaceFreestyle;
        vec4 colorNormal;
        vec4 colorVNormal;
        vec4 colorLNormal;
        vec4 colorFaceDot;
-
        vec4 colorDeselect;
        vec4 colorOutline;
        vec4 colorLampNoAlpha;
index dabbb4a321a514cc04f339ae7f15fa00bfb46070..f0981cca9e724e7c0cd2713af09add2a657e011f 100644 (file)
@@ -3,6 +3,7 @@
 #define EDGE_SELECTED   (1 << 2)
 #define EDGE_SEAM       (1 << 3)
 #define EDGE_SHARP      (1 << 4)
+#define EDGE_FREESTYLE  (1 << 5)
 #define EDGE_VERTEX_ACTIVE   (1 << (0 + 8))
 #define EDGE_VERTEX_SELECTED (1 << (1 + 8))
 
 vec4 EDIT_MESH_edge_color_outer(int edge_flag, bool face_active, float crease, float bweight)
 {
        vec4 color = vec4(0.0);
+       color = ((edge_flag & EDGE_FREESTYLE) != 0) ? colorEdgeFreestyle : color;
        color = ((edge_flag & EDGE_SHARP) != 0) ? colorEdgeSharp : color;
        color = (crease > 0.0) ? vec4(colorEdgeCrease.rgb, crease) : color;
        color = (bweight > 0.0) ? vec4(colorEdgeBWeight.rgb, bweight) : color;
        color = ((edge_flag & EDGE_SEAM) != 0) ? colorEdgeSeam : color;
 
-       if (face_active)
-       {
+       if (face_active) {
                color = colorEditMeshActive;
        }
        return color;
@@ -41,8 +42,7 @@ vec4 EDIT_MESH_edge_color_inner(int edge_flag, bool face_active)
 
 vec4 EDIT_MESH_vertex_color(int vertex_flag)
 {
-       if ((vertex_flag & (VERTEX_ACTIVE | VERTEX_SELECTED)) != 0)
-       {
+       if ((vertex_flag & (VERTEX_ACTIVE | VERTEX_SELECTED)) != 0) {
                return colorEdgeSelect;
        }
        else {
index c9de6d29524335f270b2b63134621e8f3e83cb41..40ea6b301b40a78fbc72305240046b174d7faa97 100644 (file)
@@ -6,10 +6,20 @@ in ivec4 data;
 
 flat out vec4 faceColor;
 
-#define FACE_SELECTED (1 << 3)
+#define FACE_ACTIVE     (1 << 2)
+#define FACE_SELECTED   (1 << 3)
+#define FACE_FREESTYLE  (1 << 4)
 
 void main()
 {
        gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
-       faceColor = ((data.x & FACE_SELECTED) != 0)? colorFaceSelect: colorFace;
+
+       if ((data.x & FACE_ACTIVE) != 0)
+               faceColor = colorFaceSelect;
+       else if ((data.x & FACE_SELECTED) != 0)
+               faceColor = colorFaceSelect;
+       else if ((data.x & FACE_FREESTYLE) != 0)
+               faceColor = colorFaceFreestyle;
+       else
+               faceColor = colorFace;
 }
index f19c203a70d21431ab56f8c5a264e78c43209670..7d6c64afabc8285c8db6d8417ec037f8f4859044 100644 (file)
@@ -56,6 +56,7 @@ flat out vec2 ssPos[3];
 
 #define FACE_ACTIVE     (1 << 2)
 #define FACE_SELECTED   (1 << 3)
+#define FACE_FREESTYLE  (1 << 4)
 
 /* project to screen space */
 vec2 proj(vec4 pos)
@@ -108,6 +109,8 @@ void main()
                faceColor = colorFaceSelect;
        else if ((vData[0].x & FACE_SELECTED) != 0)
                faceColor = colorFaceSelect;
+       else if ((vData[0].x & FACE_FREESTYLE) != 0)
+               faceColor = colorFaceFreestyle;
        else
                faceColor = colorFace;