diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
commit | 29f3af95272590d26f610ae828b2eeee89c82a00 (patch) | |
tree | a696a58a2561c48f7ec6166e369e22081e0a64d8 /source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl | |
parent | dcb93126876879d969a30a7865700abd072066f8 (diff) |
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes.
Also, a huge code cleanup has been done at all levels.
Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development.
Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl')
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl new file mode 100644 index 00000000000..cb03ad44615 --- /dev/null +++ b/source/blender/draw/engines/overlay/shaders/edit_gpencil_vert.glsl @@ -0,0 +1,103 @@ + +uniform float normalSize; +uniform bool doMultiframe; +uniform bool doStrokeEndpoints; +uniform bool hideSelect; +uniform bool doWeightColor; +uniform float gpEditOpacity; +uniform vec4 gpEditColor; +uniform sampler1D weightTex; + +in vec3 pos; +in float ma; +in uint vflag; +in float weight; + +out vec4 finalColor; + +void discard_vert() +{ + /* We set the vertex at the camera origin to generate 0 fragments. */ + gl_Position = vec4(0.0, 0.0, -3e36, 0.0); +} + +#define GP_EDIT_POINT_SELECTED (1u << 0u) +#define GP_EDIT_STROKE_SELECTED (1u << 1u) +#define GP_EDIT_MULTIFRAME (1u << 2u) +#define GP_EDIT_STROKE_START (1u << 3u) +#define GP_EDIT_STROKE_END (1u << 4u) + +#ifdef USE_POINTS +# define colorUnselect colorGpencilVertex +# define colorSelect colorGpencilVertexSelect +#else +# define colorUnselect gpEditColor +# define colorSelect (hideSelect ? colorUnselect : colorGpencilVertexSelect) +#endif + +vec3 weight_to_rgb(float t) +{ + if (t < 0.0) { + /* No weight */ + return colorUnselect.rgb; + } + else if (t > 1.0) { + /* Error color */ + return vec3(1.0, 0.0, 1.0); + } + else { + return texture(weightTex, t).rgb; + } +} + +void main() +{ + GPU_INTEL_VERTEX_SHADER_WORKAROUND + + vec3 world_pos = point_object_to_world(pos); + gl_Position = point_world_to_ndc(world_pos); + + bool is_multiframe = (vflag & GP_EDIT_MULTIFRAME) != 0u; + bool is_stroke_sel = (vflag & GP_EDIT_STROKE_SELECTED) != 0u; + bool is_point_sel = (vflag & GP_EDIT_POINT_SELECTED) != 0u; + + if (doWeightColor) { + finalColor.rgb = weight_to_rgb(weight); + finalColor.a = gpEditOpacity; + } + else { + finalColor = (is_point_sel) ? colorSelect : colorUnselect; + finalColor.a *= gpEditOpacity; + } + +#ifdef USE_POINTS + gl_PointSize = sizeVertex * 2.0; + + if (doStrokeEndpoints && !doWeightColor) { + bool is_stroke_start = (vflag & GP_EDIT_STROKE_START) != 0u; + bool is_stroke_end = (vflag & GP_EDIT_STROKE_END) != 0u; + + if (is_stroke_start) { + gl_PointSize *= 2.0; + finalColor.rgb = vec3(0.0, 1.0, 0.0); + } + else if (is_stroke_end) { + gl_PointSize *= 1.5; + finalColor.rgb = vec3(1.0, 0.0, 0.0); + } + } + + if ((!is_stroke_sel && !doWeightColor) || (!doMultiframe && is_multiframe)) { + discard_vert(); + } +#endif + + /* Discard unwanted padding vertices. */ + if (ma == -1.0 || (is_multiframe && !doMultiframe)) { + discard_vert(); + } + +#ifdef USE_WORLD_CLIP_PLANES + world_clip_planes_calc_clip_distance(world_pos); +#endif +} |