Sculpt Overlay: Fix mask drawn as flat shaded when smooth shading enabled
authorClément Foucault <foucault.clem@gmail.com>
Fri, 22 Feb 2019 03:03:22 +0000 (04:03 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Fri, 22 Feb 2019 03:03:59 +0000 (04:03 +0100)
Removes the flat shader variant since the attrib is specified for each vert
loop in flat shaded mode. It was something leftover from the previous
implementation.

source/blender/draw/modes/sculpt_mode.c
source/blender/draw/modes/shaders/sculpt_mask_vert.glsl

index 546270f..5d008a3 100644 (file)
@@ -36,7 +36,6 @@
 #include "draw_common.h"
 
 extern char datatoc_sculpt_mask_vert_glsl[];
-extern char datatoc_gpu_shader_flat_color_frag_glsl[];
 extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
 
 /* *********** LISTS *********** */
@@ -93,7 +92,6 @@ static struct {
         * Add sources to source/blender/draw/modes/shaders
         * init in SCULPT_engine_init();
         * free in SCULPT_engine_free(); */
-       struct GPUShader *shader_flat;
        struct GPUShader *shader_smooth;
 } e_data = {NULL}; /* Engine data */
 
@@ -117,11 +115,6 @@ static void SCULPT_engine_init(void *vedata)
 
        UNUSED_VARS(txl, fbl, stl);
 
-       if (!e_data.shader_flat) {
-               e_data.shader_flat = DRW_shader_create(datatoc_sculpt_mask_vert_glsl, NULL,
-                                                      datatoc_gpu_shader_flat_color_frag_glsl,
-                                                      "#define SHADE_FLAT");
-       }
        if (!e_data.shader_smooth) {
                e_data.shader_smooth = DRW_shader_create(datatoc_sculpt_mask_vert_glsl, NULL,
                                                         datatoc_gpu_shader_3D_smooth_color_frag_glsl, NULL);
@@ -136,37 +129,16 @@ static void SCULPT_cache_init(void *vedata)
        SCULPT_StorageList *stl = ((SCULPT_Data *)vedata)->stl;
 
        if (!stl->g_data) {
-               /* Alloc transient pointers */
                stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
        }
 
        {
-               /* Create a pass */
                DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY;
                psl->pass = DRW_pass_create("Sculpt Pass", state);
-
-               /* Create a shadingGroup using a function in draw_common.c or custom one */
-               /*
-                * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
-                * -- or --
-                * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
-                */
-               stl->g_data->group_flat = DRW_shgroup_create(e_data.shader_flat, psl->pass);
                stl->g_data->group_smooth = DRW_shgroup_create(e_data.shader_smooth, psl->pass);
        }
 }
 
-static bool object_is_flat(const Object *ob)
-{
-       Mesh *me = ob->data;
-       if (me->mpoly && me->mpoly[0].flag & ME_SMOOTH) {
-               return false;
-       }
-       else {
-               return true;
-       }
-}
-
 static void sculpt_draw_mask_cb(
         DRWShadingGroup *shgroup,
         void (*draw_fn)(DRWShadingGroup *shgroup, struct GPUBatch *geom),
@@ -206,10 +178,7 @@ static void SCULPT_cache_populate(void *vedata, Object *ob)
 
                        PBVH *pbvh = ob->sculpt->pbvh;
                        if (pbvh && pbvh_has_mask(pbvh)) {
-                               /* Get geometry cache */
-                               DRWShadingGroup *shgroup = object_is_flat(ob) ? stl->g_data->group_flat : stl->g_data->group_smooth;
-
-                               DRW_shgroup_call_generate_add(shgroup, sculpt_draw_mask_cb, ob, ob->obmat);
+                               DRW_shgroup_call_generate_add(stl->g_data->group_smooth, sculpt_draw_mask_cb, ob, ob->obmat);
                        }
                }
        }
@@ -258,7 +227,6 @@ static void SCULPT_draw_scene(void *vedata)
  * Mostly used for freeing shaders */
 static void SCULPT_engine_free(void)
 {
-       DRW_SHADER_FREE_SAFE(e_data.shader_flat);
        DRW_SHADER_FREE_SAFE(e_data.shader_smooth);
 }
 
index e76d21e..553a49f 100644 (file)
@@ -4,11 +4,7 @@ uniform mat4 ModelViewProjectionMatrix;
 in vec3 pos;
 in float msk;
 
-#ifdef SHADE_FLAT
-flat out vec4 finalColor;
-#else
 out vec4 finalColor;
-#endif
 
 void main()
 {