[Bf-blender-cvs] [94efac42975] greasepencil-object: Add edit point custom shader
Antonio Vazquez
noreply at git.blender.org
Tue Nov 28 13:45:20 CET 2017
Commit: 94efac429753cec91ffb7c576f9ba7218641f8fb
Author: Antonio Vazquez
Date: Tue Nov 28 13:45:05 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB94efac429753cec91ffb7c576f9ba7218641f8fb
Add edit point custom shader
The previous shader was not working in some Intel cards, and these commit is to replace with a new shader that works in all card types.
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
A source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_frag.glsl
A source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_geom.glsl
A source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_vert.glsl
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 6b442b6b306..776cd6823f9 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -245,6 +245,9 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_pixel_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_swirl_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_painting_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/gpencil_paper_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_vert.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_geom.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_frag.glsl SRC)
list(APPEND INC
)
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index cdb30dd21ec..540292cc6c8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -609,7 +609,7 @@ static void gpencil_add_editpoints_shgroup(
if (cache->batch_edit[cache->cache_idx]) {
if ((obact) && (obact == ob)) {
/* edit pass */
- DRW_shgroup_call_add(stl->g_data->shgrps_edit_volumetric, cache->batch_edit[cache->cache_idx], gpf->viewmatrix);
+ DRW_shgroup_call_add(stl->g_data->shgrps_edit_point, cache->batch_edit[cache->cache_idx], gpf->viewmatrix);
}
}
}
@@ -796,8 +796,10 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
stl->g_data->shgrps_edit_line = DRW_shgroup_create(e_data->gpencil_line_sh, psl->edit_pass);
stl->g_data->tot_sh++;
}
- if (!stl->g_data->shgrps_edit_volumetric) {
- stl->g_data->shgrps_edit_volumetric = DRW_shgroup_create(e_data->gpencil_volumetric_sh, psl->edit_pass);
+ if (!stl->g_data->shgrps_edit_point) {
+ stl->g_data->shgrps_edit_point = DRW_shgroup_create(e_data->gpencil_edit_point_sh, psl->edit_pass);
+ const float *viewport_size = DRW_viewport_size_get();
+ DRW_shgroup_uniform_vec2(stl->g_data->shgrps_edit_point, "Viewport", viewport_size, 1);
stl->g_data->tot_sh++;
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index e662765a8ac..784196d87f3 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -58,6 +58,9 @@ extern char datatoc_gpencil_pixel_frag_glsl[];
extern char datatoc_gpencil_swirl_frag_glsl[];
extern char datatoc_gpencil_painting_frag_glsl[];
extern char datatoc_gpencil_paper_frag_glsl[];
+extern char datatoc_gpencil_edit_point_vert_glsl[];
+extern char datatoc_gpencil_edit_point_geom_glsl[];
+extern char datatoc_gpencil_edit_point_frag_glsl[];
/* *********** STATIC *********** */
static GPENCIL_e_data e_data = {NULL}; /* Engine data */
@@ -133,10 +136,12 @@ static void GPENCIL_engine_init(void *vedata)
datatoc_gpencil_point_frag_glsl,
NULL);
}
-
/* used for edit points or strokes with one point only */
- if (!e_data.gpencil_volumetric_sh) {
- e_data.gpencil_volumetric_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ if (!e_data.gpencil_edit_point_sh) {
+ e_data.gpencil_edit_point_sh = DRW_shader_create(
+ datatoc_gpencil_edit_point_vert_glsl,
+ datatoc_gpencil_edit_point_geom_glsl,
+ datatoc_gpencil_edit_point_frag_glsl, NULL);
}
/* used for edit lines for edit modes */
@@ -167,6 +172,7 @@ static void GPENCIL_engine_free(void)
DRW_SHADER_FREE_SAFE(e_data.gpencil_fill_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_stroke_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_point_sh);
+ DRW_SHADER_FREE_SAFE(e_data.gpencil_edit_point_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_fullscreen_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_blur_sh);
DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_wave_sh);
@@ -207,7 +213,7 @@ static void GPENCIL_cache_init(void *vedata)
stl->g_data->tot_sh_point = 0;
stl->g_data->shgrps_edit_line = NULL;
- stl->g_data->shgrps_edit_volumetric = NULL;
+ stl->g_data->shgrps_edit_point = NULL;
if (!stl->shgroups) {
/* Alloc maximum size because count strokes is very slow and can be very complex due onion skinning.
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 4598a0c0572..395ef274d64 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -208,7 +208,7 @@ typedef struct GPENCIL_Data {
/* *********** STATIC *********** */
typedef struct g_data {
- struct DRWShadingGroup *shgrps_edit_volumetric;
+ struct DRWShadingGroup *shgrps_edit_point;
struct DRWShadingGroup *shgrps_edit_line;
struct DRWShadingGroup *shgrps_drawing_stroke;
struct DRWShadingGroup *shgrps_drawing_fill;
@@ -242,7 +242,7 @@ typedef struct GPENCIL_e_data {
struct GPUShader *gpencil_fill_sh;
struct GPUShader *gpencil_stroke_sh;
struct GPUShader *gpencil_point_sh;
- struct GPUShader *gpencil_volumetric_sh;
+ struct GPUShader *gpencil_edit_point_sh;
struct GPUShader *gpencil_line_sh;
struct GPUShader *gpencil_drawing_fill_sh;
struct GPUShader *gpencil_fullscreen_sh;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_frag.glsl
new file mode 100644
index 00000000000..b3bd8e488f2
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_frag.glsl
@@ -0,0 +1,17 @@
+in vec4 mColor;
+in vec2 mTexCoord;
+out vec4 fragColor;
+
+void main()
+{
+ vec2 centered = mTexCoord - vec2(0.5);
+ float dist_squared = dot(centered, centered);
+ const float rad_squared = 0.25;
+
+ // round point with jaggy edges
+ if (dist_squared > rad_squared) {
+ discard;
+ }
+
+ fragColor = mColor;
+}
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_geom.glsl
new file mode 100644
index 00000000000..68c6e73aa34
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_geom.glsl
@@ -0,0 +1,48 @@
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 Viewport;
+
+layout(points) in;
+layout(triangle_strip, max_vertices = 4) out;
+
+in vec4 finalColor[1];
+in float finalThickness[1];
+
+out vec4 mColor;
+out vec2 mTexCoord;
+
+/* project 3d point to 2d on screen space */
+vec2 toScreenSpace(vec4 vertex)
+{
+ return vec2(vertex.xy / vertex.w) * Viewport;
+}
+
+void main(void)
+{
+ vec4 P0 = gl_in[0].gl_Position;
+ vec2 sp0 = toScreenSpace(P0);
+
+ float size = finalThickness[0];
+
+ /* generate the triangle strip */
+ mTexCoord = vec2(0, 1);
+ mColor = finalColor[0];
+ gl_Position = vec4(vec2(sp0.x - size, sp0.y + size) / Viewport, 0, 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(0, 0);
+ mColor = finalColor[0];
+ gl_Position = vec4(vec2(sp0.x - size, sp0.y - size) / Viewport, 0, 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(1, 1);
+ mColor = finalColor[0];
+ gl_Position = vec4(vec2(sp0.x + size, sp0.y + size) / Viewport, 0, 1.0);
+ EmitVertex();
+
+ mTexCoord = vec2(1, 0);
+ mColor = finalColor[0];
+ gl_Position = vec4(vec2(sp0.x + size, sp0.y - size) / Viewport, 0, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_vert.glsl
new file mode 100644
index 00000000000..77fdf58bea0
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_vert.glsl
@@ -0,0 +1,15 @@
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in vec4 color;
+in float size;
+
+out vec4 finalColor;
+out float finalThickness;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 );
+ finalColor = color;
+ finalThickness = size;
+}
More information about the Bf-blender-cvs
mailing list