diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/draw/engines/gpencil/shaders | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/draw/engines/gpencil/shaders')
29 files changed, 1330 insertions, 1287 deletions
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl index cd348a477a1..0f64f54c67b 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl @@ -8,7 +8,7 @@ uniform vec2 Viewport; uniform int blur[2]; uniform vec3 loc; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform float pixfactor; float defaultpixsize = pixsize * (1000.0 / pixfactor); @@ -18,66 +18,68 @@ out vec4 FragColor; float get_zdepth(ivec2 poxy) { - /* if outside viewport set as infinite depth */ - if ((poxy.x < 0) || (poxy.x > Viewport.x)) { - return 1.0f; - } - if ((poxy.y < 0) || (poxy.y > Viewport.y)) { - return 1.0f; - } - - float zdepth = texelFetch(strokeDepth, poxy, 0).r; - return zdepth; + /* if outside viewport set as infinite depth */ + if ((poxy.x < 0) || (poxy.x > Viewport.x)) { + return 1.0f; + } + if ((poxy.y < 0) || (poxy.y > Viewport.y)) { + return 1.0f; + } + + float zdepth = texelFetch(strokeDepth, poxy, 0).r; + return zdepth; } void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); - - vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); - - float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : (noffset[0] / defaultpixsize); - float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : (noffset[1] / defaultpixsize); - - /* round to avoid shift when add more samples */ - dx = floor(dx) + 1.0; - dy = floor(dy) + 1.0; - - /* apply blurring, using a 9-tap filter with predefined gaussian weights */ - /* depth (get the value of the surrounding pixels) */ - float outdepth = get_zdepth(ivec2(uv.x, uv.y)); - for (int x = -1; x < 2; x++) { - for (int y = -1; y < 2; y++) { - float depth = get_zdepth(ivec2(uv.x + x * dx, uv.y + y * dy)); - if (depth < outdepth) { - outdepth = depth; - break; - } - } - } - gl_FragDepth = outdepth; - - /* color */ - vec4 outcolor = vec4(0.0); - outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y + 1.0 * dy), 0) * 0.0947416; - outcolor += texelFetch(strokeColor, ivec2(uv.x - 0.0 * dx, uv.y + 1.0 * dy), 0) * 0.118318; - outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y + 1.0 * dy), 0) * 0.0947416; - outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y + 0.0 * dy), 0) * 0.118318; - - outcolor += texelFetch(strokeColor, ivec2(uv.x, uv.y), 0) * 0.147761; - - outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y + 0.0 * dy), 0) * 0.118318; - outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y - 1.0 * dy), 0) * 0.0947416; - outcolor += texelFetch(strokeColor, ivec2(uv.x + 0.0 * dx, uv.y - 1.0 * dy), 0) * 0.118318; - outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y - 1.0 * dy), 0) * 0.0947416; - - FragColor = clamp(outcolor, 0, 1.0); - - /* discar extreme values */ - if (outcolor.a < 0.02f) { - discard; - } - if ((outdepth <= 0.000001) || (outdepth >= 0.999999)){ - discard; - } + ivec2 uv = ivec2(gl_FragCoord.xy); + + vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + + float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : + (noffset[0] / defaultpixsize); + float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : + (noffset[1] / defaultpixsize); + + /* round to avoid shift when add more samples */ + dx = floor(dx) + 1.0; + dy = floor(dy) + 1.0; + + /* apply blurring, using a 9-tap filter with predefined gaussian weights */ + /* depth (get the value of the surrounding pixels) */ + float outdepth = get_zdepth(ivec2(uv.x, uv.y)); + for (int x = -1; x < 2; x++) { + for (int y = -1; y < 2; y++) { + float depth = get_zdepth(ivec2(uv.x + x * dx, uv.y + y * dy)); + if (depth < outdepth) { + outdepth = depth; + break; + } + } + } + gl_FragDepth = outdepth; + + /* color */ + vec4 outcolor = vec4(0.0); + outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y + 1.0 * dy), 0) * 0.0947416; + outcolor += texelFetch(strokeColor, ivec2(uv.x - 0.0 * dx, uv.y + 1.0 * dy), 0) * 0.118318; + outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y + 1.0 * dy), 0) * 0.0947416; + outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y + 0.0 * dy), 0) * 0.118318; + + outcolor += texelFetch(strokeColor, ivec2(uv.x, uv.y), 0) * 0.147761; + + outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y + 0.0 * dy), 0) * 0.118318; + outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * dx, uv.y - 1.0 * dy), 0) * 0.0947416; + outcolor += texelFetch(strokeColor, ivec2(uv.x + 0.0 * dx, uv.y - 1.0 * dy), 0) * 0.118318; + outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * dx, uv.y - 1.0 * dy), 0) * 0.0947416; + + FragColor = clamp(outcolor, 0, 1.0); + + /* discar extreme values */ + if (outcolor.a < 0.02f) { + discard; + } + if ((outdepth <= 0.000001) || (outdepth >= 0.999999)) { + discard; + } } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl index fb44b18cc86..52f42d30d06 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl @@ -8,79 +8,75 @@ uniform float factor; out vec4 FragColor; -#define MODE_GRAYSCALE 0 -#define MODE_SEPIA 1 -#define MODE_DUOTONE 2 -#define MODE_CUSTOM 3 +#define MODE_GRAYSCALE 0 +#define MODE_SEPIA 1 +#define MODE_DUOTONE 2 +#define MODE_CUSTOM 3 #define MODE_TRANSPARENT 4 float get_luminance(vec4 color) { - float lum = (color.r * 0.2126) + (color.g * 0.7152) + (color.b * 0.723); - return lum; + float lum = (color.r * 0.2126) + (color.g * 0.7152) + (color.b * 0.723); + return lum; } void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); + ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; - vec4 src_pixel= texelFetch(strokeColor, uv.xy, 0); - float luminance = get_luminance(src_pixel); - vec4 outcolor; + float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; + vec4 src_pixel = texelFetch(strokeColor, uv.xy, 0); + float luminance = get_luminance(src_pixel); + vec4 outcolor; - /* is transparent */ - if (src_pixel.a == 0.0f) { - discard; - } + /* is transparent */ + if (src_pixel.a == 0.0f) { + discard; + } - switch(mode) { - case MODE_GRAYSCALE: - { - outcolor = vec4(luminance, luminance, luminance, src_pixel.a); - break; - } - case MODE_SEPIA: - { - float Red = (src_pixel.r * 0.393) + (src_pixel.g * 0.769) + (src_pixel.b * 0.189); - float Green = (src_pixel.r * 0.349) + (src_pixel.g * 0.686) + (src_pixel.b * 0.168); - float Blue = (src_pixel.r * 0.272) + (src_pixel.g * 0.534) + (src_pixel.b * 0.131); - outcolor = vec4(Red, Green, Blue, src_pixel.a); - break; - } - case MODE_DUOTONE: - { - if (luminance <= factor) { - outcolor = low_color; - } - else { - outcolor = high_color; - } - break; - } - case MODE_CUSTOM: - { - /* if below umbral, force custom color */ - if (luminance <= factor) { - outcolor = low_color; - } - else { - outcolor = vec4(luminance * low_color.r, luminance * low_color.b, luminance * low_color.b, src_pixel.a); - } - break; - } - case MODE_TRANSPARENT: - { - outcolor = vec4(src_pixel.rgb, src_pixel.a * factor); - break; - } - default: - { - outcolor = src_pixel; - } + switch (mode) { + case MODE_GRAYSCALE: { + outcolor = vec4(luminance, luminance, luminance, src_pixel.a); + break; + } + case MODE_SEPIA: { + float Red = (src_pixel.r * 0.393) + (src_pixel.g * 0.769) + (src_pixel.b * 0.189); + float Green = (src_pixel.r * 0.349) + (src_pixel.g * 0.686) + (src_pixel.b * 0.168); + float Blue = (src_pixel.r * 0.272) + (src_pixel.g * 0.534) + (src_pixel.b * 0.131); + outcolor = vec4(Red, Green, Blue, src_pixel.a); + break; + } + case MODE_DUOTONE: { + if (luminance <= factor) { + outcolor = low_color; + } + else { + outcolor = high_color; + } + break; + } + case MODE_CUSTOM: { + /* if below umbral, force custom color */ + if (luminance <= factor) { + outcolor = low_color; + } + else { + outcolor = vec4(luminance * low_color.r, + luminance * low_color.b, + luminance * low_color.b, + src_pixel.a); + } + break; + } + case MODE_TRANSPARENT: { + outcolor = vec4(src_pixel.rgb, src_pixel.a * factor); + break; + } + default: { + outcolor = src_pixel; + } + } - } - - gl_FragDepth = stroke_depth; - FragColor = outcolor; + gl_FragDepth = stroke_depth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl index 43589461cd1..2cd77007b36 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl @@ -7,31 +7,31 @@ uniform int flipmode; void main() { - vec2 mode = vec2(0,0); - /* horz. */ - if (flipmode >= 110) { - mode[0] = 1; - } - /* vert. */ - if ((flipmode == 101) || (flipmode == 111)) { - mode[1] = 1; - } + vec2 mode = vec2(0, 0); + /* horz. */ + if (flipmode >= 110) { + mode[0] = 1; + } + /* vert. */ + if ((flipmode == 101) || (flipmode == 111)) { + mode[1] = 1; + } - vec2 uv = vec2(gl_FragCoord.xy); - float stroke_depth; - vec4 outcolor; + vec2 uv = vec2(gl_FragCoord.xy); + float stroke_depth; + vec4 outcolor; - if (mode[0] > 0) { - uv.x = wsize.x - uv.x; - } - if (mode[1] > 0) { - uv.y = wsize.y - uv.y; - } + if (mode[0] > 0) { + uv.x = wsize.x - uv.x; + } + if (mode[1] > 0) { + uv.y = wsize.y - uv.y; + } - ivec2 iuv = ivec2(uv.x, uv.y); - stroke_depth = texelFetch(strokeDepth, iuv, 0).r; - outcolor = texelFetch(strokeColor, iuv, 0); + ivec2 iuv = ivec2(uv.x, uv.y); + stroke_depth = texelFetch(strokeDepth, iuv, 0).r; + outcolor = texelFetch(strokeColor, iuv, 0); - gl_FragDepth = stroke_depth; - FragColor = outcolor; + gl_FragDepth = stroke_depth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_prepare_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_prepare_frag.glsl index 9cdcad3e486..676b9b05db9 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_prepare_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_prepare_frag.glsl @@ -14,55 +14,55 @@ uniform int mode; out vec4 FragColor; -#define MODE_LUMINANCE 0 -#define MODE_COLOR 1 +#define MODE_LUMINANCE 0 +#define MODE_COLOR 1 /* calc luminance */ -float luma( vec3 color ) { - /* the color is linear, so do not apply tonemapping */ - return (color.r + color.g + color.b) / 3.0; +float luma(vec3 color) +{ + /* the color is linear, so do not apply tonemapping */ + return (color.r + color.g + color.b) / 3.0; } bool check_color(vec3 color_a, vec3 color_b) { - /* need round the number to avoid precision errors */ - if ((floor(color_a.r * 100) == floor(color_b.r * 100)) && - (floor(color_a.g * 100) == floor(color_b.g * 100)) && - (floor(color_a.b * 100) == floor(color_b.b * 100))) - { - return true; - } + /* need round the number to avoid precision errors */ + if ((floor(color_a.r * 100) == floor(color_b.r * 100)) && + (floor(color_a.g * 100) == floor(color_b.g * 100)) && + (floor(color_a.b * 100) == floor(color_b.b * 100))) { + return true; + } - return false; + return false; } void main() { - vec2 uv = vec2(gl_FragCoord.xy); + vec2 uv = vec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, ivec2(uv.xy), 0).r; - vec4 src_pixel= texelFetch(strokeColor, ivec2(uv.xy), 0); - vec4 outcolor; + float stroke_depth = texelFetch(strokeDepth, ivec2(uv.xy), 0).r; + vec4 src_pixel = texelFetch(strokeColor, ivec2(uv.xy), 0); + vec4 outcolor; - /* is transparent */ - if (src_pixel.a == 0.0f) { - discard; - } + /* is transparent */ + if (src_pixel.a == 0.0f) { + discard; + } - if (mode == MODE_LUMINANCE) { - if (luma(src_pixel.rgb) < threshold) { - discard; - } - } - else if (mode == MODE_COLOR) { - if (!check_color(src_pixel.rgb, select_color.rgb)) { - discard; - } - } - else { - discard; - } + if (mode == MODE_LUMINANCE) { + if (luma(src_pixel.rgb) < threshold) { + discard; + } + } + else if (mode == MODE_COLOR) { + if (!check_color(src_pixel.rgb, select_color.rgb)) { + discard; + } + } + else { + discard; + } - gl_FragDepth = stroke_depth; - FragColor = vec4(glow_color.rgb, 1.0); + gl_FragDepth = stroke_depth; + FragColor = vec4(glow_color.rgb, 1.0); } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_resolve_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_resolve_frag.glsl index 5bff7a20523..e2aceb9eefe 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_resolve_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_resolve_frag.glsl @@ -11,36 +11,36 @@ out vec4 FragColor; void main() { - vec4 outcolor; - ivec2 uv = ivec2(gl_FragCoord.xy); + vec4 outcolor; + ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; - vec4 src_pixel= texelFetch(strokeColor, uv.xy, 0); - vec4 glow_pixel= texelFetch(glowColor, uv.xy, 0); - float glow_depth = texelFetch(glowDepth, uv.xy, 0).r; + float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; + vec4 src_pixel = texelFetch(strokeColor, uv.xy, 0); + vec4 glow_pixel = texelFetch(glowColor, uv.xy, 0); + float glow_depth = texelFetch(glowDepth, uv.xy, 0).r; - if (alpha_mode == 0) { - outcolor = src_pixel + glow_pixel; - } - else { - if ((src_pixel.a < 0.1) || (glow_pixel.a < 0.1)) { - outcolor = src_pixel + glow_pixel; - } - else { - outcolor = src_pixel; - } - } + if (alpha_mode == 0) { + outcolor = src_pixel + glow_pixel; + } + else { + if ((src_pixel.a < 0.1) || (glow_pixel.a < 0.1)) { + outcolor = src_pixel + glow_pixel; + } + else { + outcolor = src_pixel; + } + } - if (src_pixel.a < glow_pixel.a) { - gl_FragDepth = glow_depth; - } - else { - gl_FragDepth = stroke_depth; - } + if (src_pixel.a < glow_pixel.a) { + gl_FragDepth = glow_depth; + } + else { + gl_FragDepth = stroke_depth; + } - if (outcolor.a < 0.001) { - discard; - } + if (outcolor.a < 0.001) { + discard; + } - FragColor = outcolor; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl index c12dd223ebe..a5c321c20c1 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl @@ -8,62 +8,63 @@ uniform vec4 loc; uniform float energy; uniform float ambient; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform float pixfactor; out vec4 FragColor; float defaultpixsize = pixsize * (1000.0 / pixfactor); -#define height loc.w +#define height loc.w /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - /* need to calculate ndc because this is not done by vertex shader */ - vec3 ndc = vec3(vertex).xyz / vertex.w; + /* need to calculate ndc because this is not done by vertex shader */ + vec3 ndc = vec3(vertex).xyz / vertex.w; - vec2 sc; - sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x; - sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y; + vec2 sc; + sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x; + sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y; - return sc; + return sc; } void main() { - float stroke_depth; - vec4 objcolor; + float stroke_depth; + vec4 objcolor; - vec4 light_loc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); - vec2 light2d = toScreenSpace(light_loc); + vec4 light_loc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + vec2 light2d = toScreenSpace(light_loc); - /* calc pixel scale */ - float pxscale = (ProjectionMatrix[3][3] == 0.0) ? (10.0 / (light_loc.z * defaultpixsize)) : (10.0 / defaultpixsize); - pxscale = max(pxscale, 0.000001); + /* calc pixel scale */ + float pxscale = (ProjectionMatrix[3][3] == 0.0) ? (10.0 / (light_loc.z * defaultpixsize)) : + (10.0 / defaultpixsize); + pxscale = max(pxscale, 0.000001); - /* the height over plane is received in the w component of the loc - * and needs a factor to adapt to pixels - */ - float peak = height * 10.0 * pxscale; - vec3 light3d = vec3(light2d.x, light2d.y, peak); + /* the height over plane is received in the w component of the loc + * and needs a factor to adapt to pixels + */ + float peak = height * 10.0 * pxscale; + vec3 light3d = vec3(light2d.x, light2d.y, peak); - vec2 uv = vec2(gl_FragCoord.xy); - vec3 frag_loc = vec3(uv.x, uv.y, 0); - vec3 norm = vec3(0, 0, 1.0); /* always z-up */ + vec2 uv = vec2(gl_FragCoord.xy); + vec3 frag_loc = vec3(uv.x, uv.y, 0); + vec3 norm = vec3(0, 0, 1.0); /* always z-up */ - ivec2 iuv = ivec2(uv.x, uv.y); - stroke_depth = texelFetch(strokeDepth, iuv, 0).r; - objcolor = texelFetch(strokeColor, iuv, 0); + ivec2 iuv = ivec2(uv.x, uv.y); + stroke_depth = texelFetch(strokeDepth, iuv, 0).r; + objcolor = texelFetch(strokeColor, iuv, 0); - /* diffuse light */ - vec3 lightdir = normalize(light3d - frag_loc); - float diff = max(dot(norm, lightdir), 0.0); - float dist = length(light3d - frag_loc) / pxscale; - float factor = diff * ((energy * 100.0) / (dist * dist)); + /* diffuse light */ + vec3 lightdir = normalize(light3d - frag_loc); + float diff = max(dot(norm, lightdir), 0.0); + float dist = length(light3d - frag_loc) / pxscale; + float factor = diff * ((energy * 100.0) / (dist * dist)); - vec3 result = factor * max(ambient, 0.1) * vec3(objcolor); + vec3 result = factor * max(ambient, 0.1) * vec3(objcolor); - gl_FragDepth = stroke_depth; - FragColor = vec4(result.r, result.g, result.b, objcolor.a); + gl_FragDepth = stroke_depth; + FragColor = vec4(result.r, result.g, result.b, objcolor.a); } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl index eb5596c639a..46b3c4286b4 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl @@ -8,7 +8,7 @@ uniform int size[3]; uniform vec4 color; uniform vec3 loc; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform float pixfactor; out vec4 FragColor; @@ -20,30 +20,32 @@ vec2 nsize = max(vec2(size[0], size[1]), 3.0); /* This pixelation shader is a modified version of original Geeks3d.com code */ void main() { - vec2 uv = vec2(gl_FragCoord.xy); - vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); - - float dx = (ProjectionMatrix[3][3] == 0.0) ? (nsize[0] / (nloc.z * defaultpixsize)) : (nsize[0] / defaultpixsize); - float dy = (ProjectionMatrix[3][3] == 0.0) ? (nsize[1] / (nloc.z * defaultpixsize)) : (nsize[1] / defaultpixsize); - - dx = max(abs(dx), 3.0); - dy = max(abs(dy), 3.0); - - vec2 coord = vec2(dx * floor(uv.x / dx), dy * floor(uv.y / dy)); - - float stroke_depth = texelFetch(strokeDepth, ivec2(coord), 0).r; - vec4 outcolor = texelFetch(strokeColor, ivec2(coord), 0); - - if (uselines == 1) { - float difx = uv.x - (floor(uv.x / nsize[0]) * nsize[0]); - if ((difx == 0.5) && (outcolor.a > 0)) { - outcolor = color; - } - float dify = uv.y - (floor(uv.y / nsize[1]) * nsize[1]); - if ((dify == 0.5) && (outcolor.a > 0)) { - outcolor = color; - } - } - gl_FragDepth = stroke_depth; - FragColor = outcolor; + vec2 uv = vec2(gl_FragCoord.xy); + vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + + float dx = (ProjectionMatrix[3][3] == 0.0) ? (nsize[0] / (nloc.z * defaultpixsize)) : + (nsize[0] / defaultpixsize); + float dy = (ProjectionMatrix[3][3] == 0.0) ? (nsize[1] / (nloc.z * defaultpixsize)) : + (nsize[1] / defaultpixsize); + + dx = max(abs(dx), 3.0); + dy = max(abs(dy), 3.0); + + vec2 coord = vec2(dx * floor(uv.x / dx), dy * floor(uv.y / dy)); + + float stroke_depth = texelFetch(strokeDepth, ivec2(coord), 0).r; + vec4 outcolor = texelFetch(strokeColor, ivec2(coord), 0); + + if (uselines == 1) { + float difx = uv.x - (floor(uv.x / nsize[0]) * nsize[0]); + if ((difx == 0.5) && (outcolor.a > 0)) { + outcolor = color; + } + float dify = uv.y - (floor(uv.y / nsize[1]) * nsize[1]); + if ((dify == 0.5) && (outcolor.a > 0)) { + outcolor = color; + } + } + gl_FragDepth = stroke_depth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl index 2321429fbf1..2a17e573978 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl @@ -13,7 +13,7 @@ uniform vec3 rim_color; uniform vec3 mask_color; uniform vec3 loc; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform float pixfactor; float defaultpixsize = pixsize * (1000.0 / pixfactor); @@ -23,41 +23,43 @@ out vec4 FragColor; void main() { - vec2 uv = vec2(gl_FragCoord.xy); - vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); - - float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : (noffset[0] / defaultpixsize); - float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : (noffset[1] / defaultpixsize); - - float stroke_depth = texelFetch(strokeDepth, ivec2(uv.xy), 0).r; - vec4 src_pixel= texelFetch(strokeColor, ivec2(uv.xy), 0); - vec4 offset_pixel= texelFetch(strokeColor, ivec2(uv.x - dx, uv.y - dy), 0); - vec4 outcolor; - - /* is transparent */ - if (src_pixel.a == 0.0f) { - discard; - } - /* check inside viewport */ - else if ((uv.x - dx < 0) || (uv.x - dx > Viewport[0])) { - discard; - } - else if ((uv.y - dy < 0) || (uv.y - dy > Viewport[1])) { - discard; - } - /* pixel is equal to mask color, keep */ - else if (src_pixel.rgb == mask_color.rgb) { - discard; - } - else { - if ((src_pixel.a > 0) && (offset_pixel.a > 0)) { - discard; - } - else { - outcolor = vec4(rim_color, 1.0); - } - } - - gl_FragDepth = stroke_depth; - FragColor = outcolor; + vec2 uv = vec2(gl_FragCoord.xy); + vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + + float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : + (noffset[0] / defaultpixsize); + float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : + (noffset[1] / defaultpixsize); + + float stroke_depth = texelFetch(strokeDepth, ivec2(uv.xy), 0).r; + vec4 src_pixel = texelFetch(strokeColor, ivec2(uv.xy), 0); + vec4 offset_pixel = texelFetch(strokeColor, ivec2(uv.x - dx, uv.y - dy), 0); + vec4 outcolor; + + /* is transparent */ + if (src_pixel.a == 0.0f) { + discard; + } + /* check inside viewport */ + else if ((uv.x - dx < 0) || (uv.x - dx > Viewport[0])) { + discard; + } + else if ((uv.y - dy < 0) || (uv.y - dy > Viewport[1])) { + discard; + } + /* pixel is equal to mask color, keep */ + else if (src_pixel.rgb == mask_color.rgb) { + discard; + } + else { + if ((src_pixel.a > 0) && (offset_pixel.a > 0)) { + discard; + } + else { + outcolor = vec4(rim_color, 1.0); + } + } + + gl_FragDepth = stroke_depth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_resolve_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_resolve_frag.glsl index 0a7eb65d564..fa010baa32f 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_resolve_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_resolve_frag.glsl @@ -10,89 +10,89 @@ uniform int mode; out vec4 FragColor; -#define MODE_NORMAL 0 -#define MODE_OVERLAY 1 -#define MODE_ADD 2 -#define MODE_SUB 3 +#define MODE_NORMAL 0 +#define MODE_OVERLAY 1 +#define MODE_ADD 2 +#define MODE_SUB 3 #define MODE_MULTIPLY 4 -#define MODE_DIVIDE 5 +#define MODE_DIVIDE 5 float overlay_color(float a, float b) { - float rtn; - if (a < 0.5) { - rtn = 2.0 * a * b; - } - else { - rtn = 1.0 - 2.0 * (1.0 - a) * (1.0 - b); - } + float rtn; + if (a < 0.5) { + rtn = 2.0 * a * b; + } + else { + rtn = 1.0 - 2.0 * (1.0 - a) * (1.0 - b); + } - return rtn; + return rtn; } vec4 get_blend_color(int mode, vec4 src_color, vec4 mix_color) { - vec4 outcolor; - if (mode == MODE_NORMAL) { - outcolor = mix_color; - } - else if (mode == MODE_OVERLAY) { - outcolor.r = overlay_color(src_color.r, mix_color.r); - outcolor.g = overlay_color(src_color.g, mix_color.g); - outcolor.b = overlay_color(src_color.b, mix_color.b); - } - else if (mode == MODE_ADD){ - outcolor = src_color + mix_color; - } - else if (mode == MODE_SUB){ - outcolor = src_color - mix_color; - } - else if (mode == MODE_MULTIPLY) { - outcolor = src_color * mix_color; - } - else if (mode == MODE_DIVIDE) { - outcolor = src_color / mix_color; - } - else { - outcolor = mix_color; - } + vec4 outcolor; + if (mode == MODE_NORMAL) { + outcolor = mix_color; + } + else if (mode == MODE_OVERLAY) { + outcolor.r = overlay_color(src_color.r, mix_color.r); + outcolor.g = overlay_color(src_color.g, mix_color.g); + outcolor.b = overlay_color(src_color.b, mix_color.b); + } + else if (mode == MODE_ADD) { + outcolor = src_color + mix_color; + } + else if (mode == MODE_SUB) { + outcolor = src_color - mix_color; + } + else if (mode == MODE_MULTIPLY) { + outcolor = src_color * mix_color; + } + else if (mode == MODE_DIVIDE) { + outcolor = src_color / mix_color; + } + else { + outcolor = mix_color; + } - /* use always the alpha of source color */ + /* use always the alpha of source color */ - outcolor.a = src_color.a; - /* use alpha to calculate the weight of the mixed color */ - outcolor = mix(src_color, outcolor, mix_color.a); + outcolor.a = src_color.a; + /* use alpha to calculate the weight of the mixed color */ + outcolor = mix(src_color, outcolor, mix_color.a); - return outcolor; + return outcolor; } void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); + ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; - vec4 src_pixel= texelFetch(strokeColor, uv.xy, 0); - vec4 rim_pixel= texelFetch(strokeRim, uv.xy, 0); + float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; + vec4 src_pixel = texelFetch(strokeColor, uv.xy, 0); + vec4 rim_pixel = texelFetch(strokeRim, uv.xy, 0); - vec4 outcolor = src_pixel; + vec4 outcolor = src_pixel; - /* is transparent */ - if (src_pixel.a == 0.0f) { - discard; - } - /* pixel is equal to mask color, keep */ - else if (src_pixel.rgb == mask_color.rgb) { - outcolor = src_pixel; - } - else { - if (rim_pixel.a == 0.0f) { - outcolor = src_pixel; - } - else { - outcolor = get_blend_color(mode, src_pixel, rim_pixel); - } - } + /* is transparent */ + if (src_pixel.a == 0.0f) { + discard; + } + /* pixel is equal to mask color, keep */ + else if (src_pixel.rgb == mask_color.rgb) { + outcolor = src_pixel; + } + else { + if (rim_pixel.a == 0.0f) { + outcolor = src_pixel; + } + else { + outcolor = get_blend_color(mode, src_pixel, rim_pixel); + } + } - gl_FragDepth = stroke_depth; - FragColor = outcolor; + gl_FragDepth = stroke_depth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl index 8bb92f69723..d2e20feae18 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl @@ -19,7 +19,7 @@ uniform float phase; uniform int orientation; uniform vec3 loc; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform float pixfactor; #define M_PI 3.1415926535897932384626433832795 @@ -37,61 +37,62 @@ out vec4 FragColor; /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - /* need to calculate ndc because this is not done by vertex shader */ - vec3 ndc = vec3(vertex).xyz / vertex.w; + /* need to calculate ndc because this is not done by vertex shader */ + vec3 ndc = vec3(vertex).xyz / vertex.w; - vec2 sc; - sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x; - sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y; + vec2 sc; + sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x; + sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y; - return sc; + return sc; } void main() { - vec2 uv = vec2(gl_FragCoord.xy); - vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); - vec2 loc2d = toScreenSpace(nloc); - - float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : (noffset[0] / defaultpixsize); - float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : (noffset[1] / defaultpixsize); - - - /* move point to new coords system */ - vec2 tpos = vec2(uv.x, uv.y) - loc2d; - - /* rotation */ - if (rotation != 0) { - vec2 rotpoint = vec2((tpos.x * cosv) - (tpos.y * sinv), (tpos.x * sinv) + (tpos.y * cosv)); - tpos = rotpoint; - } - - /* apply offset */ - tpos = vec2(tpos.x - dx, tpos.y - dy); - - /* apply scale */ - tpos.x *= 1.0 / scale[0]; - tpos.y *= 1.0 / scale[1]; - - /* back to original coords system */ - vec2 texpos = tpos + loc2d; - - /* wave */ - if (orientation == HORIZONTAL) { - float pval = (uv.x * M_PI) / Viewport[0]; - texpos.y += amplitude * sin((period * pval) + phase); - } - else if (orientation == VERTICAL){ - float pval = (uv.y * M_PI) / Viewport[1]; - texpos.x += amplitude * sin((period * pval) + phase); - } - - vec4 src_pixel = texelFetch(strokeColor, ivec2(texpos.x, texpos.y), 0); - /* is transparent */ - if (src_pixel.a == 0.0f) { - discard; - } - - gl_FragDepth = texelFetch(strokeDepth, ivec2(texpos.x, texpos.y), 0).r; - FragColor = shadow_color; + vec2 uv = vec2(gl_FragCoord.xy); + vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + vec2 loc2d = toScreenSpace(nloc); + + float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z * defaultpixsize)) : + (noffset[0] / defaultpixsize); + float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z * defaultpixsize)) : + (noffset[1] / defaultpixsize); + + /* move point to new coords system */ + vec2 tpos = vec2(uv.x, uv.y) - loc2d; + + /* rotation */ + if (rotation != 0) { + vec2 rotpoint = vec2((tpos.x * cosv) - (tpos.y * sinv), (tpos.x * sinv) + (tpos.y * cosv)); + tpos = rotpoint; + } + + /* apply offset */ + tpos = vec2(tpos.x - dx, tpos.y - dy); + + /* apply scale */ + tpos.x *= 1.0 / scale[0]; + tpos.y *= 1.0 / scale[1]; + + /* back to original coords system */ + vec2 texpos = tpos + loc2d; + + /* wave */ + if (orientation == HORIZONTAL) { + float pval = (uv.x * M_PI) / Viewport[0]; + texpos.y += amplitude * sin((period * pval) + phase); + } + else if (orientation == VERTICAL) { + float pval = (uv.y * M_PI) / Viewport[1]; + texpos.x += amplitude * sin((period * pval) + phase); + } + + vec4 src_pixel = texelFetch(strokeColor, ivec2(texpos.x, texpos.y), 0); + /* is transparent */ + if (src_pixel.a == 0.0f) { + discard; + } + + gl_FragDepth = texelFetch(strokeDepth, ivec2(texpos.x, texpos.y), 0).r; + FragColor = shadow_color; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl index 0343d0d42fc..3ef11008adf 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl @@ -10,23 +10,23 @@ out vec4 FragColor; void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); + ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; - float shadow_depth = texelFetch(shadowDepth, uv.xy, 0).r; - vec4 stroke_pixel= texelFetch(strokeColor, uv.xy, 0); - vec4 shadow_pixel= texelFetch(shadowColor, uv.xy, 0); + float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r; + float shadow_depth = texelFetch(shadowDepth, uv.xy, 0).r; + vec4 stroke_pixel = texelFetch(strokeColor, uv.xy, 0); + vec4 shadow_pixel = texelFetch(shadowColor, uv.xy, 0); - /* copy original pixel */ - vec4 outcolor = stroke_pixel; - float outdepth = stroke_depth; + /* copy original pixel */ + vec4 outcolor = stroke_pixel; + float outdepth = stroke_depth; - /* if stroke is not on top, copy shadow */ - if ((stroke_pixel.a <= 0.2) && (shadow_pixel.a > 0.0)) { - outcolor = shadow_pixel; - outdepth = shadow_depth; - } + /* if stroke is not on top, copy shadow */ + if ((stroke_pixel.a <= 0.2) && (shadow_pixel.a > 0.0)) { + outcolor = shadow_pixel; + outdepth = shadow_depth; + } - gl_FragDepth = outdepth; - FragColor = outcolor; + gl_FragDepth = outdepth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl index 92485987c93..b226d4f93bc 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl @@ -10,7 +10,7 @@ uniform int radius; uniform float angle; uniform int transparent; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform float pixfactor; out vec4 FragColor; @@ -20,50 +20,51 @@ float defaultpixsize = pixsize * (1000.0 / pixfactor); /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - /* need to calculate ndc because this is not done by vertex shader */ - vec3 ndc = vec3(vertex).xyz / vertex.w; + /* need to calculate ndc because this is not done by vertex shader */ + vec3 ndc = vec3(vertex).xyz / vertex.w; - vec2 sc; - sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x; - sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y; + vec2 sc; + sc.x = ((ndc.x + 1.0) / 2.0) * Viewport.x; + sc.y = ((ndc.y + 1.0) / 2.0) * Viewport.y; - return sc; + return sc; } /* This swirl shader is a modified version of original Geeks3d.com code */ void main() { - vec2 uv = vec2(gl_FragCoord.xy); - float stroke_depth; - vec4 outcolor; + vec2 uv = vec2(gl_FragCoord.xy); + float stroke_depth; + vec4 outcolor; - vec4 center3d = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); - vec2 center = toScreenSpace(center3d); - vec2 tc = uv - center; + vec4 center3d = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0); + vec2 center = toScreenSpace(center3d); + vec2 tc = uv - center; - float dist = length(tc); - float pxradius = (ProjectionMatrix[3][3] == 0.0) ? (radius / (loc.z * defaultpixsize)) : (radius / defaultpixsize); - pxradius = max(pxradius, 1); + float dist = length(tc); + float pxradius = (ProjectionMatrix[3][3] == 0.0) ? (radius / (loc.z * defaultpixsize)) : + (radius / defaultpixsize); + pxradius = max(pxradius, 1); - if (dist <= pxradius) { - float percent = (pxradius - dist) / pxradius; - float theta = percent * percent * angle * 8.0; - float s = sin(theta); - float c = cos(theta); - tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); - tc += center; + if (dist <= pxradius) { + float percent = (pxradius - dist) / pxradius; + float theta = percent * percent * angle * 8.0; + float s = sin(theta); + float c = cos(theta); + tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c))); + tc += center; - stroke_depth = texelFetch(strokeDepth, ivec2(tc), 0).r; - outcolor = texelFetch(strokeColor, ivec2(tc), 0); - } - else { - if (transparent == 1) { - discard; - } - stroke_depth = texelFetch(strokeDepth, ivec2(uv), 0).r; - outcolor = texelFetch(strokeColor, ivec2(uv), 0); - } + stroke_depth = texelFetch(strokeDepth, ivec2(tc), 0).r; + outcolor = texelFetch(strokeColor, ivec2(tc), 0); + } + else { + if (transparent == 1) { + discard; + } + stroke_depth = texelFetch(strokeDepth, ivec2(uv), 0).r; + outcolor = texelFetch(strokeColor, ivec2(uv), 0); + } - gl_FragDepth = stroke_depth; - FragColor = outcolor; + gl_FragDepth = stroke_depth; + FragColor = outcolor; } diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl index 04ab1557d07..0a5df9f6d77 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl @@ -17,28 +17,28 @@ uniform vec2 wsize; void main() { - vec4 outcolor; - ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth; - - float value; - if (orientation == HORIZONTAL) { - float pval = (uv.x * M_PI) / wsize[0]; - value = amplitude * sin((period * pval) + phase); - outcolor = texelFetch(strokeColor, ivec2(uv.x, uv.y + value), 0); - stroke_depth = texelFetch(strokeDepth, ivec2(uv.x, uv.y + value), 0).r; - } - else { - float pval = (uv.y * M_PI) / wsize[1]; - value = amplitude * sin((period * pval) + phase); - outcolor = texelFetch(strokeColor, ivec2(uv.x + value, uv.y), 0); - stroke_depth = texelFetch(strokeDepth, ivec2(uv.x + value, uv.y), 0).r; - } - - FragColor = outcolor; - gl_FragDepth = stroke_depth; - - if (outcolor.a < 0.02f) { - discard; - } + vec4 outcolor; + ivec2 uv = ivec2(gl_FragCoord.xy); + float stroke_depth; + + float value; + if (orientation == HORIZONTAL) { + float pval = (uv.x * M_PI) / wsize[0]; + value = amplitude * sin((period * pval) + phase); + outcolor = texelFetch(strokeColor, ivec2(uv.x, uv.y + value), 0); + stroke_depth = texelFetch(strokeDepth, ivec2(uv.x, uv.y + value), 0).r; + } + else { + float pval = (uv.y * M_PI) / wsize[1]; + value = amplitude * sin((period * pval) + phase); + outcolor = texelFetch(strokeColor, ivec2(uv.x + value, uv.y), 0); + stroke_depth = texelFetch(strokeDepth, ivec2(uv.x + value, uv.y), 0).r; + } + + FragColor = outcolor; + gl_FragDepth = stroke_depth; + + if (outcolor.a < 0.02f) { + discard; + } } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_background_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_background_frag.glsl index cbd7a461dd3..18803bfa3fa 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_background_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_background_frag.glsl @@ -5,8 +5,8 @@ uniform sampler2D strokeDepth; void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); + ivec2 uv = ivec2(gl_FragCoord.xy); - gl_FragDepth = texelFetch(strokeDepth, uv, 0).r; - FragColor = texelFetch(strokeColor, uv, 0); + gl_FragDepth = texelFetch(strokeDepth, uv, 0).r; + FragColor = texelFetch(strokeColor, uv, 0); } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl index fdaad9890a0..0482ea50916 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl @@ -14,144 +14,145 @@ uniform int tonemapping; #define ON 1 #define OFF 0 -#define MODE_NORMAL 0 -#define MODE_OVERLAY 1 -#define MODE_ADD 2 -#define MODE_SUB 3 +#define MODE_NORMAL 0 +#define MODE_OVERLAY 1 +#define MODE_ADD 2 +#define MODE_SUB 3 #define MODE_MULTIPLY 4 -#define MODE_DIVIDE 5 +#define MODE_DIVIDE 5 float overlay_color(float a, float b) { - float rtn; - if (a < 0.5) { - rtn = 2.0 * a * b; - } - else { - rtn = 1.0 - 2.0 * (1.0 - a) * (1.0 - b); - } - - return rtn; + float rtn; + if (a < 0.5) { + rtn = 2.0 * a * b; + } + else { + rtn = 1.0 - 2.0 * (1.0 - a) * (1.0 - b); + } + + return rtn; } vec4 get_blend_color(int mode, vec4 src_color, vec4 blend_color) { - vec4 mix_color = blend_color; - vec4 outcolor; - - if (mix_color.a == 0) { - outcolor = src_color; - } - else if (mode == MODE_OVERLAY) { - mix_color.rgb = mix_color.rgb * mix_color.a * blend_opacity; - outcolor.r = overlay_color(src_color.r, mix_color.r); - outcolor.g = overlay_color(src_color.g, mix_color.g); - outcolor.b = overlay_color(src_color.b, mix_color.b); - outcolor.a = src_color.a; - } - else if (mode == MODE_ADD){ - mix_color.rgb = mix_color.rgb * mix_color.a * blend_opacity; - outcolor = src_color + mix_color; - outcolor.a = src_color.a; - } - else if (mode == MODE_SUB){ - outcolor = src_color - mix_color; - outcolor.a = clamp(src_color.a - (mix_color.a * blend_opacity), 0.0, 1.0); - } - else if (mode == MODE_MULTIPLY) { - /* interpolate between 1 and color using opacity */ - mix_color.rgb = mix(vec3(1,1,1), mix_color.rgb * mix_color.a, blend_opacity); - outcolor = src_color * mix_color; - outcolor.a = src_color.a; - } - else if (mode == MODE_DIVIDE) { - mix_color.rgb = mix_color.rgb * mix_color.a * blend_opacity; - outcolor = src_color / mix_color; - outcolor.a = src_color.a; - } - else { - outcolor = mix_color * blend_opacity;; - outcolor.a = src_color.a; - } - - return outcolor; + vec4 mix_color = blend_color; + vec4 outcolor; + + if (mix_color.a == 0) { + outcolor = src_color; + } + else if (mode == MODE_OVERLAY) { + mix_color.rgb = mix_color.rgb * mix_color.a * blend_opacity; + outcolor.r = overlay_color(src_color.r, mix_color.r); + outcolor.g = overlay_color(src_color.g, mix_color.g); + outcolor.b = overlay_color(src_color.b, mix_color.b); + outcolor.a = src_color.a; + } + else if (mode == MODE_ADD) { + mix_color.rgb = mix_color.rgb * mix_color.a * blend_opacity; + outcolor = src_color + mix_color; + outcolor.a = src_color.a; + } + else if (mode == MODE_SUB) { + outcolor = src_color - mix_color; + outcolor.a = clamp(src_color.a - (mix_color.a * blend_opacity), 0.0, 1.0); + } + else if (mode == MODE_MULTIPLY) { + /* interpolate between 1 and color using opacity */ + mix_color.rgb = mix(vec3(1, 1, 1), mix_color.rgb * mix_color.a, blend_opacity); + outcolor = src_color * mix_color; + outcolor.a = src_color.a; + } + else if (mode == MODE_DIVIDE) { + mix_color.rgb = mix_color.rgb * mix_color.a * blend_opacity; + outcolor = src_color / mix_color; + outcolor.a = src_color.a; + } + else { + outcolor = mix_color * blend_opacity; + ; + outcolor.a = src_color.a; + } + + return outcolor; } float linearrgb_to_srgb(float c) { - if (c < 0.0031308) { - return (c < 0.0) ? 0.0 : c * 12.92; - } - else { - return 1.055 * pow(c, 1.0 / 2.4) - 0.055; - } + if (c < 0.0031308) { + return (c < 0.0) ? 0.0 : c * 12.92; + } + else { + return 1.055 * pow(c, 1.0 / 2.4) - 0.055; + } } vec4 tone(vec4 stroke_color) { - if (tonemapping == 1) { - vec4 color = vec4(0, 0, 0, stroke_color.a); - color.r = linearrgb_to_srgb(stroke_color.r); - color.g = linearrgb_to_srgb(stroke_color.g); - color.b = linearrgb_to_srgb(stroke_color.b); - return color; - } - else { - return stroke_color; - } + if (tonemapping == 1) { + vec4 color = vec4(0, 0, 0, stroke_color.a); + color.r = linearrgb_to_srgb(stroke_color.r); + color.g = linearrgb_to_srgb(stroke_color.g); + color.b = linearrgb_to_srgb(stroke_color.b); + return color; + } + else { + return stroke_color; + } } void main() { - vec4 outcolor; - ivec2 uv = ivec2(gl_FragCoord.xy); - vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba; - float stroke_depth = texelFetch(strokeDepth, uv, 0).r; - - vec4 mix_color = texelFetch(blendColor, uv, 0).rgba; - float mix_depth = texelFetch(blendDepth, uv, 0).r; - - /* premult alpha factor to remove double blend effects */ - if (stroke_color.a > 0) { - stroke_color = vec4(vec3(stroke_color.rgb / stroke_color.a), stroke_color.a); - } - if (mix_color.a > 0) { - mix_color = vec4(vec3(mix_color.rgb / mix_color.a), mix_color.a); - } - - /* Normal mode */ - if (mode == MODE_NORMAL) { - if (stroke_color.a > 0) { - if (mix_color.a > 0) { - FragColor = vec4(mix(stroke_color.rgb, mix_color.rgb, mix_color.a), stroke_color.a); - gl_FragDepth = mix_depth; - } - else { - FragColor = stroke_color; - gl_FragDepth = stroke_depth; - } - } - else { - if (clamp_layer == ON) { - discard; - } - else { - FragColor = mix_color; - gl_FragDepth = mix_depth; - } - } - FragColor = tone(FragColor); - return; - } - - /* if not using mask, return mix color */ - if ((stroke_color.a == 0) && (clamp_layer == OFF)) { - FragColor = tone(mix_color); - gl_FragDepth = mix_depth; - return; - } - - /* apply blend mode */ - FragColor = tone(get_blend_color(mode, stroke_color, mix_color)); - gl_FragDepth = stroke_depth; + vec4 outcolor; + ivec2 uv = ivec2(gl_FragCoord.xy); + vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba; + float stroke_depth = texelFetch(strokeDepth, uv, 0).r; + + vec4 mix_color = texelFetch(blendColor, uv, 0).rgba; + float mix_depth = texelFetch(blendDepth, uv, 0).r; + + /* premult alpha factor to remove double blend effects */ + if (stroke_color.a > 0) { + stroke_color = vec4(vec3(stroke_color.rgb / stroke_color.a), stroke_color.a); + } + if (mix_color.a > 0) { + mix_color = vec4(vec3(mix_color.rgb / mix_color.a), mix_color.a); + } + + /* Normal mode */ + if (mode == MODE_NORMAL) { + if (stroke_color.a > 0) { + if (mix_color.a > 0) { + FragColor = vec4(mix(stroke_color.rgb, mix_color.rgb, mix_color.a), stroke_color.a); + gl_FragDepth = mix_depth; + } + else { + FragColor = stroke_color; + gl_FragDepth = stroke_depth; + } + } + else { + if (clamp_layer == ON) { + discard; + } + else { + FragColor = mix_color; + gl_FragDepth = mix_depth; + } + } + FragColor = tone(FragColor); + return; + } + + /* if not using mask, return mix color */ + if ((stroke_color.a == 0) && (clamp_layer == OFF)) { + FragColor = tone(mix_color); + gl_FragDepth = mix_depth; + return; + } + + /* apply blend mode */ + FragColor = tone(get_blend_color(mode, stroke_color, mix_color)); + gl_FragDepth = stroke_depth; } 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 index b3bd8e488f2..6a2a4f68dc9 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_frag.glsl @@ -4,14 +4,14 @@ out vec4 fragColor; void main() { - vec2 centered = mTexCoord - vec2(0.5); - float dist_squared = dot(centered, centered); - const float rad_squared = 0.25; + 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; - } + // round point with jaggy edges + if (dist_squared > rad_squared) { + discard; + } - fragColor = mColor; + 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 index 0d2da00db66..b5d0a5bce71 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_geom.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_geom.glsl @@ -13,36 +13,36 @@ out vec2 mTexCoord; /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - return vec2(vertex.xy / vertex.w) * Viewport; + return vec2(vertex.xy / vertex.w) * Viewport; } void main(void) { - vec4 P0 = gl_in[0].gl_Position; - vec2 sp0 = toScreenSpace(P0); + vec4 P0 = gl_in[0].gl_Position; + vec2 sp0 = toScreenSpace(P0); - float size = finalThickness[0]; + 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(); + /* 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(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, 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(); + mTexCoord = vec2(1, 0); + mColor = finalColor[0]; + gl_Position = vec4(vec2(sp0.x + size, sp0.y - size) / Viewport, 0, 1.0); + EmitVertex(); - EndPrimitive(); + 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 index 77fdf58bea0..eea28755ae6 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_vert.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_edit_point_vert.glsl @@ -9,7 +9,7 @@ out float finalThickness; void main() { - gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 ); - finalColor = color; - finalThickness = size; + gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); + finalColor = color; + finalThickness = size; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl index 7f3bbf17222..632c63a39aa 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl @@ -39,146 +39,172 @@ uniform vec4 wire_color; #define GP_DRAWMODE_2D 0 #define GP_DRAWMODE_3D 1 -#define OB_WIRE 2 +#define OB_WIRE 2 #define OB_SOLID 3 -#define V3D_SHADING_MATERIAL_COLOR 0 -#define V3D_SHADING_TEXTURE_COLOR 3 +#define V3D_SHADING_MATERIAL_COLOR 0 +#define V3D_SHADING_TEXTURE_COLOR 3 in vec4 finalColor; in vec2 texCoord_interp; out vec4 fragColor; #define texture2D texture -void set_color(in vec4 color, in vec4 color2, in vec4 tcolor, in float mixv, in float factor, - in int tmix, in int flip, out vec4 ocolor) +void set_color(in vec4 color, + in vec4 color2, + in vec4 tcolor, + in float mixv, + in float factor, + in int tmix, + in int flip, + out vec4 ocolor) { - /* full color A */ - if (mixv == 1.0) { - if (tmix == 1) { - ocolor = (flip == 0) ? color : tcolor; - } - else { - ocolor = (flip == 0) ? color : color2; - } - } - /* full color B */ - else if (mixv == 0.0) { - if (tmix == 1) { - ocolor = (flip == 0) ? tcolor : color; - } - else { - ocolor = (flip == 0) ? color2 : color; - } - } - /* mix of colors */ - else { - if (tmix == 1) { - ocolor = (flip == 0) ? mix(color, tcolor, factor) : mix(tcolor, color, factor); - } - else { - ocolor = (flip == 0) ? mix(color, color2, factor) : mix(color2, color, factor); - } - } - ocolor.a *= layer_opacity; + /* full color A */ + if (mixv == 1.0) { + if (tmix == 1) { + ocolor = (flip == 0) ? color : tcolor; + } + else { + ocolor = (flip == 0) ? color : color2; + } + } + /* full color B */ + else if (mixv == 0.0) { + if (tmix == 1) { + ocolor = (flip == 0) ? tcolor : color; + } + else { + ocolor = (flip == 0) ? color2 : color; + } + } + /* mix of colors */ + else { + if (tmix == 1) { + ocolor = (flip == 0) ? mix(color, tcolor, factor) : mix(tcolor, color, factor); + } + else { + ocolor = (flip == 0) ? mix(color, color2, factor) : mix(color2, color, factor); + } + } + ocolor.a *= layer_opacity; } void main() { - vec2 t_center = vec2(0.5, 0.5); - mat2 matrot_tex = mat2(cos(texture_angle), -sin(texture_angle), sin(texture_angle), cos(texture_angle)); - vec2 rot_tex = (matrot_tex * (texCoord_interp - t_center)) + t_center + texture_offset; - vec4 tmp_color; - tmp_color = (texture_clamp == 0) ? texture2D(myTexture, rot_tex * texture_scale) : texture2D(myTexture, clamp(rot_tex * texture_scale, 0.0, 1.0)); - vec4 text_color = vec4(tmp_color[0], tmp_color[1], tmp_color[2], tmp_color[3] * texture_opacity); - vec4 chesscolor; - - /* wireframe with x-ray discard */ - if ((viewport_xray == 1) && (shading_type[0] == OB_WIRE)) { - discard; - } - - /* solid fill */ - if (fill_type == SOLID) { - fragColor = finalColor; - } - else { - vec2 center = vec2(0.5, 0.5) + gradient_shift; - mat2 matrot = mat2(cos(gradient_angle), -sin(gradient_angle), sin(gradient_angle), cos(gradient_angle)); - vec2 rot = (((matrot * (texCoord_interp - center)) + center) * gradient_scale) + gradient_shift; - /* gradient */ - if (fill_type == GRADIENT) { - set_color(finalColor, color2, text_color, mix_factor, rot.x - mix_factor + 0.5, texture_mix, texture_flip, fragColor); - } - /* radial gradient */ - if (fill_type == RADIAL) { - float in_rad = gradient_radius * mix_factor; - float ex_rad = gradient_radius - in_rad; - float intensity = 0; - float distance = length((center - texCoord_interp) * gradient_scale); - if (distance > gradient_radius) { - discard; - } - if (distance > in_rad) { - intensity = clamp(((distance - in_rad) / ex_rad), 0.0, 1.0); - } - set_color(finalColor, color2, text_color, mix_factor, intensity, texture_mix, texture_flip, fragColor); - } - /* chessboard */ - if (fill_type == CHESS) { - vec2 pos = rot / pattern_gridsize; - if ((fract(pos.x) < 0.5 && fract(pos.y) < 0.5) || (fract(pos.x) > 0.5 && fract(pos.y) > 0.5)) { - chesscolor = (texture_flip == 0) ? finalColor : color2; - } - else { - chesscolor = (texture_flip == 0) ? color2 : finalColor; - } - /* mix with texture */ - fragColor = (texture_mix == 1) ? mix(chesscolor, text_color, mix_factor) : chesscolor; - fragColor.a *= layer_opacity; - } - /* texture */ - if (fill_type == TEXTURE) { - fragColor = (texture_mix == 1) ? mix(text_color, finalColor, mix_factor) : text_color; - fragColor.a *= layer_opacity; - } - /* pattern */ - if (fill_type == PATTERN) { - fragColor = finalColor; - fragColor.a = min(text_color.a, finalColor.a) * layer_opacity; - } - } - - /* set zdepth */ - if (xraymode == GP_XRAY_FRONT) { - gl_FragDepth = 0.000001; - } - else if (xraymode == GP_XRAY_3DSPACE) { - /* if 3D mode, move slightly the fill to avoid z-fighting between stroke and fill on same stroke */ - if (drawmode == GP_DRAWMODE_3D) { - gl_FragDepth = gl_FragCoord.z * 1.0001; - } - else { - gl_FragDepth = gl_FragCoord.z; - } - } - else { - gl_FragDepth = 0.000001; - } - - /* if wireframe override colors */ - if (shading_type[0] == OB_WIRE) { - fragColor = wire_color; - } - - /* for solid override color */ - if (shading_type[0] == OB_SOLID) { - if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) { - fragColor = wire_color; - } - if (viewport_xray == 1) { - fragColor.a *= 0.5; - } - } - + vec2 t_center = vec2(0.5, 0.5); + mat2 matrot_tex = mat2( + cos(texture_angle), -sin(texture_angle), sin(texture_angle), cos(texture_angle)); + vec2 rot_tex = (matrot_tex * (texCoord_interp - t_center)) + t_center + texture_offset; + vec4 tmp_color; + tmp_color = (texture_clamp == 0) ? + texture2D(myTexture, rot_tex * texture_scale) : + texture2D(myTexture, clamp(rot_tex * texture_scale, 0.0, 1.0)); + vec4 text_color = vec4(tmp_color[0], tmp_color[1], tmp_color[2], tmp_color[3] * texture_opacity); + vec4 chesscolor; + + /* wireframe with x-ray discard */ + if ((viewport_xray == 1) && (shading_type[0] == OB_WIRE)) { + discard; + } + + /* solid fill */ + if (fill_type == SOLID) { + fragColor = finalColor; + } + else { + vec2 center = vec2(0.5, 0.5) + gradient_shift; + mat2 matrot = mat2( + cos(gradient_angle), -sin(gradient_angle), sin(gradient_angle), cos(gradient_angle)); + vec2 rot = (((matrot * (texCoord_interp - center)) + center) * gradient_scale) + + gradient_shift; + /* gradient */ + if (fill_type == GRADIENT) { + set_color(finalColor, + color2, + text_color, + mix_factor, + rot.x - mix_factor + 0.5, + texture_mix, + texture_flip, + fragColor); + } + /* radial gradient */ + if (fill_type == RADIAL) { + float in_rad = gradient_radius * mix_factor; + float ex_rad = gradient_radius - in_rad; + float intensity = 0; + float distance = length((center - texCoord_interp) * gradient_scale); + if (distance > gradient_radius) { + discard; + } + if (distance > in_rad) { + intensity = clamp(((distance - in_rad) / ex_rad), 0.0, 1.0); + } + set_color(finalColor, + color2, + text_color, + mix_factor, + intensity, + texture_mix, + texture_flip, + fragColor); + } + /* chessboard */ + if (fill_type == CHESS) { + vec2 pos = rot / pattern_gridsize; + if ((fract(pos.x) < 0.5 && fract(pos.y) < 0.5) || + (fract(pos.x) > 0.5 && fract(pos.y) > 0.5)) { + chesscolor = (texture_flip == 0) ? finalColor : color2; + } + else { + chesscolor = (texture_flip == 0) ? color2 : finalColor; + } + /* mix with texture */ + fragColor = (texture_mix == 1) ? mix(chesscolor, text_color, mix_factor) : chesscolor; + fragColor.a *= layer_opacity; + } + /* texture */ + if (fill_type == TEXTURE) { + fragColor = (texture_mix == 1) ? mix(text_color, finalColor, mix_factor) : text_color; + fragColor.a *= layer_opacity; + } + /* pattern */ + if (fill_type == PATTERN) { + fragColor = finalColor; + fragColor.a = min(text_color.a, finalColor.a) * layer_opacity; + } + } + + /* set zdepth */ + if (xraymode == GP_XRAY_FRONT) { + gl_FragDepth = 0.000001; + } + else if (xraymode == GP_XRAY_3DSPACE) { + /* if 3D mode, move slightly the fill to avoid z-fighting between stroke and fill on same stroke */ + if (drawmode == GP_DRAWMODE_3D) { + gl_FragDepth = gl_FragCoord.z * 1.0001; + } + else { + gl_FragDepth = gl_FragCoord.z; + } + } + else { + gl_FragDepth = 0.000001; + } + + /* if wireframe override colors */ + if (shading_type[0] == OB_WIRE) { + fragColor = wire_color; + } + + /* for solid override color */ + if (shading_type[0] == OB_SOLID) { + if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && + (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) { + fragColor = wire_color; + } + if (viewport_xray == 1) { + fragColor.a *= 0.5; + } + } } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_vert.glsl index 52da354a562..d71f57eb98c 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_vert.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_vert.glsl @@ -8,7 +8,7 @@ out vec2 texCoord_interp; void main(void) { - gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 ); - finalColor = color; - texCoord_interp = texCoord; + gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); + finalColor = color; + texCoord_interp = texCoord; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl index c2e3f787bec..3c1424f98ff 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_paper_frag.glsl @@ -5,5 +5,5 @@ out vec4 FragColor; void main() { - FragColor = vec4(color, opacity); + FragColor = vec4(color, opacity); } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl index ca8c888fe21..c8af822bc9e 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_frag.glsl @@ -11,62 +11,62 @@ out vec4 fragColor; #define texture2D texture -#define GPENCIL_MODE_LINE 0 -#define GPENCIL_MODE_DOTS 1 -#define GPENCIL_MODE_BOX 2 +#define GPENCIL_MODE_LINE 0 +#define GPENCIL_MODE_DOTS 1 +#define GPENCIL_MODE_BOX 2 /* keep this list synchronized with list in gpencil_engine.h */ -#define GPENCIL_COLOR_SOLID 0 +#define GPENCIL_COLOR_SOLID 0 #define GPENCIL_COLOR_TEXTURE 1 #define GPENCIL_COLOR_PATTERN 2 /* Function to check the point inside ellipse */ -float checkpoint(vec2 pt, vec2 radius) -{ - float p = (pow(pt.x, 2) / pow(radius.x, 2)) + (pow(pt.y, 2) / pow(radius.y, 2)); - - return p; -} +float checkpoint(vec2 pt, vec2 radius) +{ + float p = (pow(pt.x, 2) / pow(radius.x, 2)) + (pow(pt.y, 2) / pow(radius.y, 2)); + + return p; +} void main() { - vec2 centered = mTexCoord - vec2(0.5); - float ellip = checkpoint(centered, vec2(gradient_s / 2.0)); + vec2 centered = mTexCoord - vec2(0.5); + float ellip = checkpoint(centered, vec2(gradient_s / 2.0)); + + if (mode != GPENCIL_MODE_BOX) { + if (ellip > 1.0) { + discard; + } + } + + vec4 tmp_color = texture2D(myTexture, mTexCoord); - if (mode != GPENCIL_MODE_BOX) { - if (ellip > 1.0) { - discard; - } - } + /* Solid */ + if (color_type == GPENCIL_COLOR_SOLID) { + fragColor = mColor; + } + /* texture */ + if (color_type == GPENCIL_COLOR_TEXTURE) { + fragColor = texture2D(myTexture, mTexCoord); + /* mult both alpha factor to use strength factor with texture */ + fragColor.a = min(fragColor.a * mColor.a, fragColor.a); + } + /* pattern */ + if (color_type == GPENCIL_COLOR_PATTERN) { + vec4 text_color = texture2D(myTexture, mTexCoord); + fragColor = mColor; + /* mult both alpha factor to use strength factor with color alpha limit */ + fragColor.a = min(text_color.a * mColor.a, mColor.a); + } - vec4 tmp_color = texture2D(myTexture, mTexCoord); + if ((mode == GPENCIL_MODE_DOTS) && (gradient_f < 1.0)) { + float dist = length(centered) * 2; + float decay = dist * (1.0 - gradient_f) * fragColor.a; + fragColor.a = clamp(fragColor.a - decay, 0.0, 1.0); + fragColor.a = fragColor.a * (1.0 - ellip); + } - /* Solid */ - if (color_type == GPENCIL_COLOR_SOLID) { - fragColor = mColor; - } - /* texture */ - if (color_type == GPENCIL_COLOR_TEXTURE) { - fragColor = texture2D(myTexture, mTexCoord); - /* mult both alpha factor to use strength factor with texture */ - fragColor.a = min(fragColor.a * mColor.a, fragColor.a); - } - /* pattern */ - if (color_type == GPENCIL_COLOR_PATTERN) { - vec4 text_color = texture2D(myTexture, mTexCoord); - fragColor = mColor; - /* mult both alpha factor to use strength factor with color alpha limit */ - fragColor.a = min(text_color.a * mColor.a, mColor.a); - } - - if ((mode == GPENCIL_MODE_DOTS) && (gradient_f < 1.0)) { - float dist = length(centered) * 2; - float decay = dist * (1.0 - gradient_f) * fragColor.a; - fragColor.a = clamp(fragColor.a - decay, 0.0, 1.0); - fragColor.a = fragColor.a * (1.0 - ellip); - } - - if(fragColor.a < 0.0035) { - discard; - } + if (fragColor.a < 0.0035) { + discard; + } } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl index 32aaa057298..2fb48ac5147 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_geom.glsl @@ -17,124 +17,124 @@ out vec2 mTexCoord; #define GP_XRAY_FRONT 0 #define GP_XRAY_3DSPACE 1 -#define M_PI 3.14159265358979323846 /* pi */ -#define M_2PI 6.28318530717958647692 /* 2*pi */ -#define FALSE 0 +#define M_PI 3.14159265358979323846 /* pi */ +#define M_2PI 6.28318530717958647692 /* 2*pi */ +#define FALSE 0 /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - return vec2(vertex.xy / vertex.w) * Viewport; + return vec2(vertex.xy / vertex.w) * Viewport; } /* get zdepth value */ float getZdepth(vec4 point) { - if (xraymode == GP_XRAY_FRONT) { - return 0.000001; - } - if (xraymode == GP_XRAY_3DSPACE) { - return (point.z / point.w); - } - - /* in front by default */ - return 0.000001; + if (xraymode == GP_XRAY_FRONT) { + return 0.000001; + } + if (xraymode == GP_XRAY_3DSPACE) { + return (point.z / point.w); + } + + /* in front by default */ + return 0.000001; } vec2 rotateUV(vec2 uv, float angle) { - /* translate center of rotation to the center of texture */ - vec2 new_uv = uv - vec2(0.5f, 0.5f); - vec2 rot_uv; - rot_uv.x = new_uv.x * cos(angle) - new_uv.y * sin(angle); - rot_uv.y = new_uv.y * cos(angle) + new_uv.x * sin(angle); - return rot_uv + vec2(0.5f, 0.5f); + /* translate center of rotation to the center of texture */ + vec2 new_uv = uv - vec2(0.5f, 0.5f); + vec2 rot_uv; + rot_uv.x = new_uv.x * cos(angle) - new_uv.y * sin(angle); + rot_uv.y = new_uv.y * cos(angle) + new_uv.x * sin(angle); + return rot_uv + vec2(0.5f, 0.5f); } vec2 rotatePoint(vec2 center, vec2 point, float angle) { - /* translate center of rotation to the center */ - vec2 new_point = point - center; - vec2 rot_point; - rot_point.x = new_point.x * cos(angle) - new_point.y * sin(angle); - rot_point.y = new_point.y * cos(angle) + new_point.x * sin(angle); - return rot_point + center; + /* translate center of rotation to the center */ + vec2 new_point = point - center; + vec2 rot_point; + rot_point.x = new_point.x * cos(angle) - new_point.y * sin(angle); + rot_point.y = new_point.y * cos(angle) + new_point.x * sin(angle); + return rot_point + center; } /* Calculate angle of the stroke using previous point as reference. * The angle is calculated using the x axis (1, 0) as 0 degrees */ float getAngle(vec2 pt0, vec2 pt1) { - /* do not rotate one point only (no reference to rotate) */ - if (pt0 == pt1) { - return 0.0; - } - - if (use_follow_path == FALSE) { - return 0.0; - } - - /* default horizontal line (x-axis) in screen space */ - vec2 v0 = vec2(1.0, 0.0); - - /* vector of direction */ - vec2 vn = vec2(normalize(pt1 - pt0)); - - /* angle signed (function ported from angle_signed_v2v2) */ - float perp_dot = (v0[1] * vn[0]) - (v0[0] * vn[1]); - float angle = atan(perp_dot, dot(v0, vn)); - - /* get full circle rotation */ - if (angle > 0.0) { - angle = M_PI + (M_PI - angle); - } - else { - angle *= -1.0; - } - - return angle; + /* do not rotate one point only (no reference to rotate) */ + if (pt0 == pt1) { + return 0.0; + } + + if (use_follow_path == FALSE) { + return 0.0; + } + + /* default horizontal line (x-axis) in screen space */ + vec2 v0 = vec2(1.0, 0.0); + + /* vector of direction */ + vec2 vn = vec2(normalize(pt1 - pt0)); + + /* angle signed (function ported from angle_signed_v2v2) */ + float perp_dot = (v0[1] * vn[0]) - (v0[0] * vn[1]); + float angle = atan(perp_dot, dot(v0, vn)); + + /* get full circle rotation */ + if (angle > 0.0) { + angle = M_PI + (M_PI - angle); + } + else { + angle *= -1.0; + } + + return angle; } void main(void) { - /* receive points */ - vec4 P0 = gl_in[0].gl_Position; - vec2 sp0 = toScreenSpace(P0); - - vec4 P1 = finalprev_pos[0]; - vec2 sp1 = toScreenSpace(P1); - vec2 point; - - float size = finalThickness[0]; - vec2 center = vec2(sp0.x, sp0.y); - - /* get angle of stroke to rotate texture */ - float angle = getAngle(sp0, sp1); - - /* generate the triangle strip */ - mTexCoord = rotateUV(vec2(0, 1), finaluvdata[0].y); - mColor = finalColor[0]; - point = rotatePoint(center, vec2(sp0.x - size, sp0.y + size), angle); - gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); - EmitVertex(); - - mTexCoord = rotateUV(vec2(0, 0), finaluvdata[0].y); - mColor = finalColor[0]; - point = rotatePoint(center, vec2(sp0.x - size, sp0.y - size), angle); - gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); - EmitVertex(); - - mTexCoord = rotateUV(vec2(1, 1), finaluvdata[0].y); - mColor = finalColor[0]; - point = rotatePoint(center, vec2(sp0.x + size, sp0.y + size), angle); - gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); - EmitVertex(); - - mTexCoord = rotateUV(vec2(1, 0), finaluvdata[0].y); - mColor = finalColor[0]; - point = rotatePoint(center, vec2(sp0.x + size, sp0.y - size), angle); - gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); - EmitVertex(); - - EndPrimitive(); + /* receive points */ + vec4 P0 = gl_in[0].gl_Position; + vec2 sp0 = toScreenSpace(P0); + + vec4 P1 = finalprev_pos[0]; + vec2 sp1 = toScreenSpace(P1); + vec2 point; + + float size = finalThickness[0]; + vec2 center = vec2(sp0.x, sp0.y); + + /* get angle of stroke to rotate texture */ + float angle = getAngle(sp0, sp1); + + /* generate the triangle strip */ + mTexCoord = rotateUV(vec2(0, 1), finaluvdata[0].y); + mColor = finalColor[0]; + point = rotatePoint(center, vec2(sp0.x - size, sp0.y + size), angle); + gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); + EmitVertex(); + + mTexCoord = rotateUV(vec2(0, 0), finaluvdata[0].y); + mColor = finalColor[0]; + point = rotatePoint(center, vec2(sp0.x - size, sp0.y - size), angle); + gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); + EmitVertex(); + + mTexCoord = rotateUV(vec2(1, 1), finaluvdata[0].y); + mColor = finalColor[0]; + point = rotatePoint(center, vec2(sp0.x + size, sp0.y + size), angle); + gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); + EmitVertex(); + + mTexCoord = rotateUV(vec2(1, 0), finaluvdata[0].y); + mColor = finalColor[0]; + point = rotatePoint(center, vec2(sp0.x + size, sp0.y - size), angle); + gl_Position = vec4(point / Viewport, getZdepth(P0), 1.0); + EmitVertex(); + + EndPrimitive(); } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl index 7deca544176..92c9acf1f2a 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl @@ -1,7 +1,7 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ProjectionMatrix; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform int keep_size; uniform float objscale; uniform float pixfactor; @@ -22,42 +22,44 @@ out vec4 finalprev_pos; #define TRUE 1 -#define OB_WIRE 2 +#define OB_WIRE 2 #define OB_SOLID 3 -#define V3D_SHADING_MATERIAL_COLOR 0 -#define V3D_SHADING_TEXTURE_COLOR 3 +#define V3D_SHADING_MATERIAL_COLOR 0 +#define V3D_SHADING_TEXTURE_COLOR 3 float defaultpixsize = pixsize * (1000.0 / pixfactor); void main() { - gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); - finalprev_pos = ModelViewProjectionMatrix * vec4(prev_pos, 1.0); - finalColor = color; - - if (keep_size == TRUE) { - finalThickness = thickness; - } - else { - float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize); - finalThickness = max(size * objscale, 4.0); /* minimum 4 pixels */ - } - - /* for wireframe override size and color */ - if (shading_type[0] == OB_WIRE) { - finalThickness = 2.0; - finalColor = wire_color; - } - /* for solid override color */ - if (shading_type[0] == OB_SOLID) { - if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) { - finalColor = wire_color; - } - if (viewport_xray == 1) { - finalColor.a *= 0.5; - } - } - - finaluvdata = uvdata; + gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); + finalprev_pos = ModelViewProjectionMatrix * vec4(prev_pos, 1.0); + finalColor = color; + + if (keep_size == TRUE) { + finalThickness = thickness; + } + else { + float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : + (thickness / defaultpixsize); + finalThickness = max(size * objscale, 4.0); /* minimum 4 pixels */ + } + + /* for wireframe override size and color */ + if (shading_type[0] == OB_WIRE) { + finalThickness = 2.0; + finalColor = wire_color; + } + /* for solid override color */ + if (shading_type[0] == OB_SOLID) { + if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && + (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) { + finalColor = wire_color; + } + if (viewport_xray == 1) { + finalColor.a *= 0.5; + } + } + + finaluvdata = uvdata; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_simple_mix_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_simple_mix_frag.glsl index dd54e38c3d0..2f4429a858f 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_simple_mix_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_simple_mix_frag.glsl @@ -6,10 +6,10 @@ uniform sampler2D strokeColor; uniform sampler2D strokeDepth; void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, uv, 0).r; - vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba; + ivec2 uv = ivec2(gl_FragCoord.xy); + float stroke_depth = texelFetch(strokeDepth, uv, 0).r; + vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba; - FragColor = stroke_color; - gl_FragDepth = stroke_depth; + FragColor = stroke_color; + gl_FragDepth = stroke_depth; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl index a49a6e84f17..35d07306361 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl @@ -12,7 +12,7 @@ out vec4 fragColor; #define texture2D texture /* keep this list synchronized with list in gpencil_engine.h */ -#define GPENCIL_COLOR_SOLID 0 +#define GPENCIL_COLOR_SOLID 0 #define GPENCIL_COLOR_TEXTURE 1 #define GPENCIL_COLOR_PATTERN 2 @@ -20,53 +20,53 @@ out vec4 fragColor; void main() { - - vec4 tColor = vec4(mColor); - /* if uvfac[1] == 1, then encap */ - if (uvfac[1] == ENDCAP) { - vec2 center = vec2(uvfac[0], 0.5); - float dist = length(mTexCoord - center); - if (dist > 0.50) { - discard; - } - } - /* Solid */ - if (color_type == GPENCIL_COLOR_SOLID) { - fragColor = tColor; - } - /* texture for endcaps */ - vec4 text_color; - if (uvfac[1] == ENDCAP) { - text_color = texture2D(myTexture, vec2(mTexCoord.x, mTexCoord.y)); - } - else { - text_color = texture2D(myTexture, mTexCoord); - } + vec4 tColor = vec4(mColor); + /* if uvfac[1] == 1, then encap */ + if (uvfac[1] == ENDCAP) { + vec2 center = vec2(uvfac[0], 0.5); + float dist = length(mTexCoord - center); + if (dist > 0.50) { + discard; + } + } + /* Solid */ + if (color_type == GPENCIL_COLOR_SOLID) { + fragColor = tColor; + } - /* texture */ - if (color_type == GPENCIL_COLOR_TEXTURE) { - fragColor = text_color; - /* mult both alpha factor to use strength factor */ - fragColor.a = min(fragColor.a * tColor.a, fragColor.a); - } - /* pattern */ - if (color_type == GPENCIL_COLOR_PATTERN) { - fragColor = tColor; - /* mult both alpha factor to use strength factor with color alpha limit */ - fragColor.a = min(text_color.a * tColor.a, tColor.a); - } + /* texture for endcaps */ + vec4 text_color; + if (uvfac[1] == ENDCAP) { + text_color = texture2D(myTexture, vec2(mTexCoord.x, mTexCoord.y)); + } + else { + text_color = texture2D(myTexture, mTexCoord); + } - /* gradient */ - /* keep this disabled while the line glitch bug exists - if (gradient_f < 1.0) { - float d = abs(mTexCoord.y - 0.5) * (1.1 - gradient_f); - float alpha = 1.0 - clamp((fragColor.a - (d * 2.0)), 0.03, 1.0); - fragColor.a = smoothstep(fragColor.a, 0.0, alpha); - - } - */ + /* texture */ + if (color_type == GPENCIL_COLOR_TEXTURE) { + fragColor = text_color; + /* mult both alpha factor to use strength factor */ + fragColor.a = min(fragColor.a * tColor.a, fragColor.a); + } + /* pattern */ + if (color_type == GPENCIL_COLOR_PATTERN) { + fragColor = tColor; + /* mult both alpha factor to use strength factor with color alpha limit */ + fragColor.a = min(text_color.a * tColor.a, tColor.a); + } - if(fragColor.a < 0.0035) - discard; + /* gradient */ + /* keep this disabled while the line glitch bug exists + if (gradient_f < 1.0) { + float d = abs(mTexCoord.y - 0.5) * (1.1 - gradient_f); + float alpha = 1.0 - clamp((fragColor.a - (d * 2.0)), 0.03, 1.0); + fragColor.a = smoothstep(fragColor.a, 0.0, alpha); + + } + */ + + if (fragColor.a < 0.0035) + discard; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl index aa38ff26a62..7e62d6f0d64 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl @@ -19,7 +19,7 @@ out vec2 uvfac; #define GP_XRAY_3DSPACE 1 /* keep this list synchronized with list in gpencil_engine.h */ -#define GPENCIL_COLOR_SOLID 0 +#define GPENCIL_COLOR_SOLID 0 #define GPENCIL_COLOR_TEXTURE 1 #define GPENCIL_COLOR_PATTERN 2 @@ -28,222 +28,229 @@ out vec2 uvfac; /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { - return vec2(vertex.xy / vertex.w) * Viewport; + return vec2(vertex.xy / vertex.w) * Viewport; } /* get zdepth value */ float getZdepth(vec4 point) { - if (xraymode == GP_XRAY_FRONT) { - return 0.000001; - } - if (xraymode == GP_XRAY_3DSPACE) { - return (point.z / point.w); - } - - /* in front by default */ - return 0.000001; + if (xraymode == GP_XRAY_FRONT) { + return 0.000001; + } + if (xraymode == GP_XRAY_3DSPACE) { + return (point.z / point.w); + } + + /* in front by default */ + return 0.000001; } /* check equality but with a small tolerance */ bool is_equal(vec4 p1, vec4 p2) { - float limit = 0.0001; - float x = abs(p1.x - p2.x); - float y = abs(p1.y - p2.y); - float z = abs(p1.z - p2.z); + float limit = 0.0001; + float x = abs(p1.x - p2.x); + float y = abs(p1.y - p2.y); + float z = abs(p1.z - p2.z); - if ((x < limit) && (y < limit) && (z < limit)) { - return true; - } + if ((x < limit) && (y < limit) && (z < limit)) { + return true; + } - return false; + return false; } void main(void) { - float MiterLimit = 0.75; - uvfac = vec2(0.0, 0.0); - - /* receive 4 points */ - vec4 P0 = gl_in[0].gl_Position; - vec4 P1 = gl_in[1].gl_Position; - vec4 P2 = gl_in[2].gl_Position; - vec4 P3 = gl_in[3].gl_Position; - - /* get the four vertices passed to the shader */ - vec2 sp0 = toScreenSpace(P0); // start of previous segment - vec2 sp1 = toScreenSpace(P1); // end of previous segment, start of current segment - vec2 sp2 = toScreenSpace(P2); // end of current segment, start of next segment - vec2 sp3 = toScreenSpace(P3); // end of next segment - - /* culling outside viewport */ - vec2 area = Viewport * 4.0; - if (sp1.x < -area.x || sp1.x > area.x) return; - if (sp1.y < -area.y || sp1.y > area.y) return; - if (sp2.x < -area.x || sp2.x > area.x) return; - if (sp2.y < -area.y || sp2.y > area.y) return; - - /* culling behind camera */ - if (P1.w < 0 || P2.w < 0) return; - - /* determine the direction of each of the 3 segments (previous, current, next) */ - vec2 v0 = normalize(sp1 - sp0); - vec2 v1 = normalize(sp2 - sp1); - vec2 v2 = normalize(sp3 - sp2); - - /* determine the normal of each of the 3 segments (previous, current, next) */ - vec2 n0 = vec2(-v0.y, v0.x); - vec2 n1 = vec2(-v1.y, v1.x); - vec2 n2 = vec2(-v2.y, v2.x); - - /* determine miter lines by averaging the normals of the 2 segments */ - vec2 miter_a = normalize(n0 + n1); // miter at start of current segment - vec2 miter_b = normalize(n1 + n2); // miter at end of current segment - - /* determine the length of the miter by projecting it onto normal and then inverse it */ - float an1 = dot(miter_a, n1); - float bn1 = dot(miter_b, n2); - if (an1 == 0) an1 = 1; - if (bn1 == 0) bn1 = 1; - float length_a = finalThickness[1] / an1; - float length_b = finalThickness[2] / bn1; - if (length_a <= 0.0) length_a = 0.01; - if (length_b <= 0.0) length_b = 0.01; - - /* prevent excessively long miters at sharp corners */ - if (dot(v0, v1) < -MiterLimit) { - miter_a = n1; - length_a = finalThickness[1]; - - /* close the gap */ - if (dot(v0, n1) > 0) { - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = vec2(0, 0); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = vec2(0, 0.5); - mColor = finalColor[1]; - gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - EndPrimitive(); - } - else { - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = vec2(0, 1); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = vec2(0, 0.5); - mColor = finalColor[1]; - gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - EndPrimitive(); - } - } - - if (dot(v1, v2) < -MiterLimit) { - miter_b = n1; - length_b = finalThickness[2]; - } - - /* generate the start endcap */ - if ((caps_mode[0] != GPENCIL_FLATCAP) && is_equal(P0,P2)) - { - vec4 cap_color = finalColor[1]; - - mTexCoord = vec2(2.0, 0.5); - mColor = cap_color; - vec2 svn1 = normalize(sp1 - sp2) * length_a * 4.0; - uvfac = vec2(0.0, 1.0); - gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = vec2(0.0, -0.5); - mColor = cap_color; - uvfac = vec2(0.0, 1.0); - gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = vec2(0.0, 1.5); - mColor = cap_color; - uvfac = vec2(0.0, 1.0); - gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - } - - float y_a = 0.0; - float y_b = 1.0; - - /* invert uv (vertical) */ - if (finaluvdata[2].x > 1.0) { - if ((finaluvdata[1].y != 0.0) && (finaluvdata[2].y != 0.0)) { - float d = ceil(finaluvdata[2].x) - 1.0; - if (floor(d / 2.0) == (d / 2.0)) { - y_a = 1.0; - y_b = 0.0; - } - } - } - /* generate the triangle strip */ - uvfac = vec2(0.0, 0.0); - mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(0, 0) : vec2(finaluvdata[1].x, y_a); - mColor = finalColor[1]; - gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(0, 1) : vec2(finaluvdata[1].x, y_b); - mColor = finalColor[1]; - gl_Position = vec4((sp1 - length_a * miter_a) / Viewport, getZdepth(P1), 1.0); - EmitVertex(); - - mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(1, 0) : vec2(finaluvdata[2].x, y_a); - mColor = finalColor[2]; - gl_Position = vec4((sp2 + length_b * miter_b) / Viewport, getZdepth(P2), 1.0); - EmitVertex(); - - mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(1, 1) : vec2(finaluvdata[2].x, y_b); - mColor = finalColor[2]; - gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0); - EmitVertex(); - - /* generate the end endcap */ - if ((caps_mode[1] != GPENCIL_FLATCAP) && is_equal(P1,P3) && (finaluvdata[2].x > 0)) - { - vec4 cap_color = finalColor[2]; - - mTexCoord = vec2(finaluvdata[2].x, 1.5); - mColor = cap_color; - uvfac = vec2(finaluvdata[2].x, 1.0); - gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); - EmitVertex(); - - mTexCoord = vec2(finaluvdata[2].x, -0.5); - mColor = cap_color; - uvfac = vec2(finaluvdata[2].x, 1.0); - gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); - EmitVertex(); - - mTexCoord = vec2(finaluvdata[2].x + 2, 0.5); - mColor = cap_color; - uvfac = vec2(finaluvdata[2].x, 1.0); - vec2 svn2 = normalize(sp2 - sp1) * length_b * 4.0; - gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0); - EmitVertex(); - } - - EndPrimitive(); + float MiterLimit = 0.75; + uvfac = vec2(0.0, 0.0); + + /* receive 4 points */ + vec4 P0 = gl_in[0].gl_Position; + vec4 P1 = gl_in[1].gl_Position; + vec4 P2 = gl_in[2].gl_Position; + vec4 P3 = gl_in[3].gl_Position; + + /* get the four vertices passed to the shader */ + vec2 sp0 = toScreenSpace(P0); // start of previous segment + vec2 sp1 = toScreenSpace(P1); // end of previous segment, start of current segment + vec2 sp2 = toScreenSpace(P2); // end of current segment, start of next segment + vec2 sp3 = toScreenSpace(P3); // end of next segment + + /* culling outside viewport */ + vec2 area = Viewport * 4.0; + if (sp1.x < -area.x || sp1.x > area.x) + return; + if (sp1.y < -area.y || sp1.y > area.y) + return; + if (sp2.x < -area.x || sp2.x > area.x) + return; + if (sp2.y < -area.y || sp2.y > area.y) + return; + + /* culling behind camera */ + if (P1.w < 0 || P2.w < 0) + return; + + /* determine the direction of each of the 3 segments (previous, current, next) */ + vec2 v0 = normalize(sp1 - sp0); + vec2 v1 = normalize(sp2 - sp1); + vec2 v2 = normalize(sp3 - sp2); + + /* determine the normal of each of the 3 segments (previous, current, next) */ + vec2 n0 = vec2(-v0.y, v0.x); + vec2 n1 = vec2(-v1.y, v1.x); + vec2 n2 = vec2(-v2.y, v2.x); + + /* determine miter lines by averaging the normals of the 2 segments */ + vec2 miter_a = normalize(n0 + n1); // miter at start of current segment + vec2 miter_b = normalize(n1 + n2); // miter at end of current segment + + /* determine the length of the miter by projecting it onto normal and then inverse it */ + float an1 = dot(miter_a, n1); + float bn1 = dot(miter_b, n2); + if (an1 == 0) + an1 = 1; + if (bn1 == 0) + bn1 = 1; + float length_a = finalThickness[1] / an1; + float length_b = finalThickness[2] / bn1; + if (length_a <= 0.0) + length_a = 0.01; + if (length_b <= 0.0) + length_b = 0.01; + + /* prevent excessively long miters at sharp corners */ + if (dot(v0, v1) < -MiterLimit) { + miter_a = n1; + length_a = finalThickness[1]; + + /* close the gap */ + if (dot(v0, n1) > 0) { + mTexCoord = vec2(0, 0); + mColor = finalColor[1]; + gl_Position = vec4((sp1 + finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = vec2(0, 0); + mColor = finalColor[1]; + gl_Position = vec4((sp1 + finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = vec2(0, 0.5); + mColor = finalColor[1]; + gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + EndPrimitive(); + } + else { + mTexCoord = vec2(0, 1); + mColor = finalColor[1]; + gl_Position = vec4((sp1 - finalThickness[1] * n1) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = vec2(0, 1); + mColor = finalColor[1]; + gl_Position = vec4((sp1 - finalThickness[1] * n0) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = vec2(0, 0.5); + mColor = finalColor[1]; + gl_Position = vec4(sp1 / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + EndPrimitive(); + } + } + + if (dot(v1, v2) < -MiterLimit) { + miter_b = n1; + length_b = finalThickness[2]; + } + + /* generate the start endcap */ + if ((caps_mode[0] != GPENCIL_FLATCAP) && is_equal(P0, P2)) { + vec4 cap_color = finalColor[1]; + + mTexCoord = vec2(2.0, 0.5); + mColor = cap_color; + vec2 svn1 = normalize(sp1 - sp2) * length_a * 4.0; + uvfac = vec2(0.0, 1.0); + gl_Position = vec4((sp1 + svn1) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = vec2(0.0, -0.5); + mColor = cap_color; + uvfac = vec2(0.0, 1.0); + gl_Position = vec4((sp1 - (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = vec2(0.0, 1.5); + mColor = cap_color; + uvfac = vec2(0.0, 1.0); + gl_Position = vec4((sp1 + (length_a * 2.0) * miter_a) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + } + + float y_a = 0.0; + float y_b = 1.0; + + /* invert uv (vertical) */ + if (finaluvdata[2].x > 1.0) { + if ((finaluvdata[1].y != 0.0) && (finaluvdata[2].y != 0.0)) { + float d = ceil(finaluvdata[2].x) - 1.0; + if (floor(d / 2.0) == (d / 2.0)) { + y_a = 1.0; + y_b = 0.0; + } + } + } + /* generate the triangle strip */ + uvfac = vec2(0.0, 0.0); + mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(0, 0) : vec2(finaluvdata[1].x, y_a); + mColor = finalColor[1]; + gl_Position = vec4((sp1 + length_a * miter_a) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(0, 1) : vec2(finaluvdata[1].x, y_b); + mColor = finalColor[1]; + gl_Position = vec4((sp1 - length_a * miter_a) / Viewport, getZdepth(P1), 1.0); + EmitVertex(); + + mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(1, 0) : vec2(finaluvdata[2].x, y_a); + mColor = finalColor[2]; + gl_Position = vec4((sp2 + length_b * miter_b) / Viewport, getZdepth(P2), 1.0); + EmitVertex(); + + mTexCoord = (color_type == GPENCIL_COLOR_SOLID) ? vec2(1, 1) : vec2(finaluvdata[2].x, y_b); + mColor = finalColor[2]; + gl_Position = vec4((sp2 - length_b * miter_b) / Viewport, getZdepth(P2), 1.0); + EmitVertex(); + + /* generate the end endcap */ + if ((caps_mode[1] != GPENCIL_FLATCAP) && is_equal(P1, P3) && (finaluvdata[2].x > 0)) { + vec4 cap_color = finalColor[2]; + + mTexCoord = vec2(finaluvdata[2].x, 1.5); + mColor = cap_color; + uvfac = vec2(finaluvdata[2].x, 1.0); + gl_Position = vec4((sp2 + (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); + EmitVertex(); + + mTexCoord = vec2(finaluvdata[2].x, -0.5); + mColor = cap_color; + uvfac = vec2(finaluvdata[2].x, 1.0); + gl_Position = vec4((sp2 - (length_b * 2.0) * miter_b) / Viewport, getZdepth(P2), 1.0); + EmitVertex(); + + mTexCoord = vec2(finaluvdata[2].x + 2, 0.5); + mColor = cap_color; + uvfac = vec2(finaluvdata[2].x, 1.0); + vec2 svn2 = normalize(sp2 - sp1) * length_b * 4.0; + gl_Position = vec4((sp2 + svn2) / Viewport, getZdepth(P2), 1.0); + EmitVertex(); + } + + EndPrimitive(); } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl index 62740f37ae8..946b39c006a 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl @@ -1,7 +1,7 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 ProjectionMatrix; -uniform float pixsize; /* rv3d->pixsize */ +uniform float pixsize; /* rv3d->pixsize */ uniform int keep_size; uniform float objscale; uniform float pixfactor; @@ -20,41 +20,43 @@ out vec2 finaluvdata; #define TRUE 1 -#define OB_WIRE 2 +#define OB_WIRE 2 #define OB_SOLID 3 -#define V3D_SHADING_MATERIAL_COLOR 0 -#define V3D_SHADING_TEXTURE_COLOR 3 +#define V3D_SHADING_MATERIAL_COLOR 0 +#define V3D_SHADING_TEXTURE_COLOR 3 float defaultpixsize = pixsize * (1000.0 / pixfactor); void main(void) { - gl_Position = ModelViewProjectionMatrix * vec4( pos, 1.0 ); - finalColor = color; - - if (keep_size == TRUE) { - finalThickness = thickness; - } - else { - float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : (thickness / defaultpixsize); - finalThickness = max(size * objscale, 1.0); - } - - /* for wireframe override size and color */ - if (shading_type[0] == OB_WIRE) { - finalThickness = 1.0; - finalColor = wire_color; - } - /* for solid override color */ - if (shading_type[0] == OB_SOLID) { - if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) { - finalColor = wire_color; - } - if (viewport_xray == 1) { - finalColor.a *= 0.5; - } - } - - finaluvdata = uvdata; + gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0); + finalColor = color; + + if (keep_size == TRUE) { + finalThickness = thickness; + } + else { + float size = (ProjectionMatrix[3][3] == 0.0) ? (thickness / (gl_Position.z * defaultpixsize)) : + (thickness / defaultpixsize); + finalThickness = max(size * objscale, 1.0); + } + + /* for wireframe override size and color */ + if (shading_type[0] == OB_WIRE) { + finalThickness = 1.0; + finalColor = wire_color; + } + /* for solid override color */ + if (shading_type[0] == OB_SOLID) { + if ((shading_type[1] != V3D_SHADING_MATERIAL_COLOR) && + (shading_type[1] != V3D_SHADING_TEXTURE_COLOR)) { + finalColor = wire_color; + } + if (viewport_xray == 1) { + finalColor.a *= 0.5; + } + } + + finaluvdata = uvdata; } diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl index a32fd87a446..be645548402 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl @@ -10,65 +10,65 @@ uniform int do_select; float srgb_to_linearrgb(float c) { - if (c < 0.04045) { - return (c < 0.0) ? 0.0 : c * (1.0 / 12.92); - } - else { - return pow((c + 0.055) * (1.0 / 1.055), 2.4); - } + if (c < 0.04045) { + return (c < 0.0) ? 0.0 : c * (1.0 / 12.92); + } + else { + return pow((c + 0.055) * (1.0 / 1.055), 2.4); + } } float linearrgb_to_srgb(float c) { - if (c < 0.0031308) { - return (c < 0.0) ? 0.0 : c * 12.92; - } - else { - return 1.055 * pow(c, 1.0 / 2.4) - 0.055; - } + if (c < 0.0031308) { + return (c < 0.0) ? 0.0 : c * 12.92; + } + else { + return 1.055 * pow(c, 1.0 / 2.4) - 0.055; + } } bool check_borders(ivec2 uv, int size) { - for (int x = -size; x <= size; x++) { - for (int y = -size; y <= size; y++) { - vec4 stroke_color = texelFetch(strokeColor, ivec2(uv.x + x, uv.y + y), 0).rgba; - if (stroke_color.a > 0) { - return true; - } - } - } + for (int x = -size; x <= size; x++) { + for (int y = -size; y <= size; y++) { + vec4 stroke_color = texelFetch(strokeColor, ivec2(uv.x + x, uv.y + y), 0).rgba; + if (stroke_color.a > 0) { + return true; + } + } + } - return false; + return false; } void main() { - ivec2 uv = ivec2(gl_FragCoord.xy); - float stroke_depth = texelFetch(strokeDepth, uv, 0).r; - vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba; + ivec2 uv = ivec2(gl_FragCoord.xy); + float stroke_depth = texelFetch(strokeDepth, uv, 0).r; + vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba; - /* premult alpha factor to remove double blend effects */ - if (stroke_color.a > 0) { - stroke_color = vec4(vec3(stroke_color.rgb / stroke_color.a), stroke_color.a); - } + /* premult alpha factor to remove double blend effects */ + if (stroke_color.a > 0) { + stroke_color = vec4(vec3(stroke_color.rgb / stroke_color.a), stroke_color.a); + } - /* apply color correction for render only */ - if (tonemapping == 1) { - stroke_color.r = srgb_to_linearrgb(stroke_color.r); - stroke_color.g = srgb_to_linearrgb(stroke_color.g); - stroke_color.b = srgb_to_linearrgb(stroke_color.b); - } + /* apply color correction for render only */ + if (tonemapping == 1) { + stroke_color.r = srgb_to_linearrgb(stroke_color.r); + stroke_color.g = srgb_to_linearrgb(stroke_color.g); + stroke_color.b = srgb_to_linearrgb(stroke_color.b); + } - FragColor = clamp(stroke_color, 0.0, 1.0); - gl_FragDepth = clamp(stroke_depth, 0.0, 1.0); + FragColor = clamp(stroke_color, 0.0, 1.0); + gl_FragDepth = clamp(stroke_depth, 0.0, 1.0); - if (do_select == 1) { - if (stroke_color.a == 0) { - if (check_borders(uv, 2)) { - FragColor = select_color; - gl_FragDepth = 0.000001; - } - } - } + if (do_select == 1) { + if (stroke_color.a == 0) { + if (check_borders(uv, 2)) { + FragColor = select_color; + gl_FragDepth = 0.000001; + } + } + } } |