use high on painting shaders

This commit is contained in:
2019-03-05 10:21:49 +01:00
parent 317292318a
commit 9e26c67de6
13 changed files with 111 additions and 111 deletions

View File

@@ -22,36 +22,36 @@ void main()
uniform sampler2D tex;
uniform sampler2D tex_stroke;
uniform sampler2D tex_mask;
uniform mediump float alpha;
uniform highp float alpha;
uniform int blend_mode;
uniform mediump vec2 resolution;
uniform highp vec2 resolution;
uniform bool lock;
uniform bool mask;
uniform bool use_fragcoord;
uniform bool use_dual;
uniform sampler2D tex_dual;
uniform mediump float dual_alpha;
uniform highp float dual_alpha;
uniform int dual_blend_mode;
uniform bool use_pattern;
uniform sampler2D tex_pattern;
uniform mediump vec2 pattern_scale;
uniform mediump float pattern_bright;
uniform mediump float pattern_contr;
uniform mediump float pattern_depth;
uniform mediump vec2 pattern_offset;
uniform highp vec2 pattern_scale;
uniform highp float pattern_bright;
uniform highp float pattern_contr;
uniform highp float pattern_depth;
uniform highp vec2 pattern_offset;
uniform bool pattern_invert;
uniform int patt_blend_mode;
in mediump vec2 uv;
out mediump vec4 frag;
in highp vec2 uv;
out highp vec4 frag;
void main()
{
mediump vec2 uv_base = use_fragcoord ? (gl_FragCoord.st / resolution) : uv;
mediump vec4 base = texture(tex, uv_base);
mediump vec4 stroke = texture(tex_stroke, uv);
highp vec2 uv_base = use_fragcoord ? (gl_FragCoord.st / resolution) : uv;
highp vec4 base = texture(tex, uv_base);
highp vec4 stroke = texture(tex_stroke, uv);
if (stroke.a == 0.0)
{
@@ -61,8 +61,8 @@ void main()
if (use_pattern)
{
mediump vec2 rscale = resolution / vec2(512.0);
mediump float patt = texture(tex_pattern, uv * (1.0 / pattern_scale) * rscale + pattern_offset).r;
highp vec2 rscale = resolution / vec2(512.0);
highp float patt = texture(tex_pattern, uv * (1.0 / pattern_scale) * rscale + pattern_offset).r;
if (pattern_invert)
patt = 1.0 - patt;
if (pattern_bright != 0.5)
@@ -74,7 +74,7 @@ void main()
if (use_dual)
{
mediump vec4 dual = texture(tex_dual, uv);
highp vec4 dual = texture(tex_dual, uv);
stroke.a = clamp(blend_stroke(stroke.a, dual.a, dual_alpha, dual_blend_mode), 0.0, 1.0);
}
@@ -85,6 +85,6 @@ void main()
return;
}
mediump vec4 blended = blend(base, stroke, blend_mode);
highp vec4 blended = blend(base, stroke, blend_mode);
frag = vec4(blended.rgb, (lock ? base.a : blended.a) * alpha);
}

View File

@@ -23,13 +23,13 @@ uniform mediump float alpha;
uniform mediump vec2 resolution;
uniform bool mask;
in mediump vec2 uv;
out mediump vec4 frag;
in highp vec2 uv;
out highp vec4 frag;
void main()
{
mediump vec4 base = texture(tex, uv);
mediump vec4 stroke = texture(tex_stroke, uv);
highp vec4 base = texture(tex, uv);
highp vec4 stroke = texture(tex_stroke, uv);
stroke.a = mask ? stroke.a * blur(tex_mask, uv).r : stroke.a;
frag = vec4(base.rgb, clamp((base.a - stroke.a) * alpha, 0.0, 1.0));
}

View File

@@ -20,7 +20,7 @@ void main()
uniform samplerCube tex;
in highp vec2 uv;
out mediump vec4 frag;
out highp vec4 frag;
void main()
{

View File

@@ -1,9 +1,9 @@
mediump float blend_stroke_screen(mediump float base, mediump float stroke)
highp float blend_stroke_screen(highp float base, highp float stroke)
{
return base + stroke - (base * stroke);
}
mediump float blend_stroke_hard_light(mediump float base, mediump float stroke)
mediump float blend_stroke_hard_light(highp float base, highp float stroke)
{
if (stroke < 0.5)
return base * (stroke * 2.0); // multiply
@@ -11,12 +11,12 @@ mediump float blend_stroke_hard_light(mediump float base, mediump float stroke)
return blend_stroke_screen(base, 2.0 * stroke - 1.0);
}
mediump float blend_stroke_hard_mix(mediump float base, mediump float stroke)
highp float blend_stroke_hard_mix(highp float base, highp float stroke)
{
return base + stroke < 0.5 ? 0.0 : base + stroke;
}
mediump float blend_stroke_color_dodge(mediump float base, mediump float stroke)
highp float blend_stroke_color_dodge(highp float base, highp float stroke)
{
if (base == 0.0)
return 0.0;
@@ -26,7 +26,7 @@ mediump float blend_stroke_color_dodge(mediump float base, mediump float stroke)
return base / (1.0 - stroke);
}
mediump float blend_stroke_color_burn(mediump float base, mediump float stroke)
highp float blend_stroke_color_burn(highp float base, highp float stroke)
{
if (base == 1.0)
return 1.0;
@@ -36,20 +36,20 @@ mediump float blend_stroke_color_burn(mediump float base, mediump float stroke)
return 1.0 - min(1.0, (1.0 - base) / stroke);
}
mediump float blend_stroke_linear_height(mediump float base, mediump float stroke, mediump float depth)
highp float blend_stroke_linear_height(highp float base, highp float stroke, highp float depth)
{
mediump float partial = (1.0 - stroke) * pow(depth, 0.25) + (base * depth * 10.0);
highp float partial = (1.0 - stroke) * pow(depth, 0.25) + (base * depth * 10.0);
return base * partial;
}
mediump float blend_stroke_height(mediump float base, mediump float stroke, mediump float depth)
highp float blend_stroke_height(highp float base, highp float stroke, highp float depth)
{
mediump float A = pow((1.0 - stroke), max(1.0, (1.0 - depth) * 10.0)) * pow(depth, 0.25);
mediump float B = (base * depth * 5.0);
highp float A = pow((1.0 - stroke), max(1.0, (1.0 - depth) * 10.0)) * pow(depth, 0.25);
highp float B = (base * depth * 5.0);
return base * (A + B);
}
mediump float blend_stroke(mediump float base, mediump float stroke, mediump float depth, int mode)
highp float blend_stroke(highp float base, highp float stroke, highp float depth, int mode)
{
if (mode == 0) /* normal */ return mix(base, stroke, depth);
else if (mode == 1) /* multiply */ return mix(base, base * stroke, depth);

View File

@@ -1,4 +1,4 @@
mediump vec3 blend_normal(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
highp vec3 blend_normal(highp vec4 base, highp vec4 stroke, highp float alpha_tot)
{
return mix(
base.rgb,
@@ -7,7 +7,7 @@ mediump vec3 blend_normal(mediump vec4 base, mediump vec4 stroke, mediump float
);
}
mediump vec3 blend_multiply(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
highp vec3 blend_multiply(highp vec4 base, highp vec4 stroke, highp float alpha_tot)
{
return mix(
stroke.rgb,
@@ -20,7 +20,7 @@ mediump vec3 blend_multiply(mediump vec4 base, mediump vec4 stroke, mediump floa
);
}
mediump vec3 blend_screen(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
highp vec3 blend_screen(highp vec4 base, highp vec4 stroke, highp float alpha_tot)
{
return mix(
stroke.rgb,
@@ -33,7 +33,7 @@ mediump vec3 blend_screen(mediump vec4 base, mediump vec4 stroke, mediump float
);
}
mediump vec3 blend_colorDodge(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
highp vec3 blend_colorDodge(highp vec4 base, highp vec4 stroke, highp float alpha_tot)
{
return mix(
stroke.rgb,
@@ -46,7 +46,7 @@ mediump vec3 blend_colorDodge(mediump vec4 base, mediump vec4 stroke, mediump fl
);
}
mediump vec3 blend_overlay(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
highp vec3 blend_overlay(highp vec4 base, highp vec4 stroke, highp float alpha_tot)
{
return mix(
stroke.rgb,
@@ -63,7 +63,7 @@ mediump vec3 blend_overlay(mediump vec4 base, mediump vec4 stroke, mediump float
);
}
mediump vec4 blend(mediump vec4 base, mediump vec4 stroke, int mode)
highp vec4 blend(highp vec4 base, highp vec4 stroke, int mode)
{
mediump float contribution = (1.0 - base.a) * stroke.a;
mediump float alpha_tot = base.a + contribution;

View File

@@ -1,6 +1,6 @@
mediump vec4 blur(sampler2D t, mediump vec2 uv)
highp vec4 blur(sampler2D t, highp vec2 uv)
{
mediump vec4 sum = texture(t, uv);
highp vec4 sum = texture(t, uv);
sum += textureOffset(t, uv, ivec2(-1, -1));
sum += textureOffset(t, uv, ivec2(-1, 0));
sum += textureOffset(t, uv, ivec2(-1, 1));

View File

@@ -1,23 +1,23 @@
mediump vec3 brightness3(mediump vec3 c, mediump float val)
highp vec3 brightness3(highp vec3 c, highp float val)
{
return clamp(c + vec3(val * 2.0 - 1.0), vec3(0), vec3(1));
}
mediump vec3 contrast3(mediump vec3 c, mediump float val)
highp vec3 contrast3(highp vec3 c, highp float val)
{
val = val * 2.0 - 1.0;
mediump float factor = ((259.0 / 255.0) * (val + 1.0)) / (1.0 * ((259.0 / 255.0) - val));
highp float v = val * 2.0 - 1.0;
highp float factor = ((259.0 / 255.0) * (v + 1.0)) / (1.0 * ((259.0 / 255.0) - v));
return clamp(factor * (c - 0.5) + 0.5, vec3(0), vec3(1));
}
mediump float brightness1(mediump float c, mediump float val)
highp float brightness1(highp float c, highp float val)
{
return clamp(c + (val * 2.0 - 1.0), 0.0, 1.0);
}
mediump float contrast1(mediump float c, mediump float val)
highp float contrast1(highp float c, highp float val)
{
val = val * 2.0 - 1.0;
mediump float factor = ((259.0 / 255.0) * (val + 1.0)) / (1.0 * ((259.0 / 255.0) - val));
highp float v = val * 2.0 - 1.0;
highp float factor = ((259.0 / 255.0) * (v + 1.0)) / (1.0 * ((259.0 / 255.0) - v));
return clamp(factor * (c - 0.5) + 0.5, 0.0, 1.0);
}

View File

@@ -1,16 +1,16 @@
mediump vec3 rgb2hsv(mediump vec3 c)
highp vec3 rgb2hsv(highp vec3 c)
{
mediump vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
mediump vec4 p = mix(vec4(c.bg, k.wz), vec4(c.gb, k.xy), step(c.b, c.g));
mediump vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
mediump float d = q.x - min(q.w, q.y);
mediump float e = 1.0e-10;
highp vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
highp vec4 p = mix(vec4(c.bg, k.wz), vec4(c.gb, k.xy), step(c.b, c.g));
highp vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
highp float d = q.x - min(q.w, q.y);
highp float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
mediump vec3 hsv2rgb(mediump vec3 c)
highp vec3 hsv2rgb(highp vec3 c)
{
mediump vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
mediump vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
highp vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
highp vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}

View File

@@ -24,41 +24,41 @@ void main()
#include "include/color.glsl"
#include "include/blend-stroke.glsl"
uniform mediump sampler2D tex;
uniform mediump sampler2D tex_bg;
uniform mediump sampler2D tex_mix;
uniform mediump vec4 col;
uniform mediump vec2 resolution;
uniform mediump float alpha;
uniform mediump float opacity;
uniform mediump float noise;
uniform mediump float mix_alpha;
uniform mediump float wet;
uniform sampler2D tex;
uniform sampler2D tex_bg;
uniform sampler2D tex_mix;
uniform highp vec4 col;
uniform highp vec2 resolution;
uniform highp float alpha;
uniform highp float opacity;
uniform highp float noise;
uniform highp float mix_alpha;
uniform highp float wet;
uniform bool use_pattern;
uniform mediump sampler2D tex_pattern;
uniform mediump vec2 pattern_scale;
uniform mediump float pattern_bright;
uniform mediump float pattern_contr;
uniform mediump float pattern_depth;
uniform mediump vec2 pattern_offset;
uniform sampler2D tex_pattern;
uniform highp vec2 pattern_scale;
uniform highp float pattern_bright;
uniform highp float pattern_contr;
uniform highp float pattern_depth;
uniform highp vec2 pattern_offset;
uniform bool pattern_invert;
uniform int patt_blend_mode;
in mediump vec2 uv;
in mediump vec2 uv_2;
in mediump float q;
in highp vec2 uv;
in highp vec2 uv_2;
in highp float q;
#if defined(GL_EXT_shader_framebuffer_fetch)
inout mediump vec4 frag;
inout highp vec4 frag;
#else
out mediump vec4 frag;
out highp vec4 frag;
#endif
void main()
{
mediump vec2 uv2 = gl_FragCoord.st / resolution;
mediump float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;
mediump vec4 fg = vec4(col.rgb, brush_alpha);
highp vec2 uv2 = gl_FragCoord.st / resolution;
highp float brush_alpha = ( 1.0 - texture(tex, uv/q).r ) * alpha;
highp vec4 fg = vec4(col.rgb, brush_alpha);
// early discard
if (fg.a == 0.0)
@@ -66,8 +66,8 @@ void main()
if (use_pattern)
{
mediump vec2 rscale = resolution / vec2(512.0);
mediump float patt = texture(tex_pattern, uv2 * (1.0 / pattern_scale) * rscale + pattern_offset).r;
highp vec2 rscale = resolution / vec2(512.0);
highp float patt = texture(tex_pattern, uv2 * (1.0 / pattern_scale) * rscale + pattern_offset).r;
if (pattern_invert)
patt = 1.0 - patt;
patt = patt * pattern_depth + (1.0 - pattern_depth);
@@ -79,11 +79,11 @@ void main()
}
#if defined(GL_EXT_shader_framebuffer_fetch)
mediump vec4 bg = frag;
highp vec4 bg = frag;
#elif defined(GL_ARM_shader_framebuffer_fetch)
mediump vec4 bg = gl_LastFragColorARM;
highp vec4 bg = gl_LastFragColorARM;
#else
mediump vec4 bg = texture(tex_bg, uv2);
highp vec4 bg = texture(tex_bg, uv2);
#endif
fg.a *= 1.0-rand(uv2+uv)*noise;
@@ -94,17 +94,17 @@ void main()
if (mix_alpha > 0.0)
{
mediump vec2 uv_mix = uv_2 / q;
highp vec2 uv_mix = uv_2 / q;
if (uv_mix.x < 0.0 || uv_mix.x > 1.0 || uv_mix.y < 0.0 || uv_mix.y > 1.0) discard;
mediump vec4 mbg = texture(tex_mix, uv_mix);
highp vec4 mbg = texture(tex_mix, uv_mix);
fg.rgb = mix(fg.rgb, mbg.rgb, mix_alpha * mbg.a);
}
mediump float contribution = max(0.0, opacity - bg.a) * fg.a;
mediump float alpha_tot = bg.a + contribution;
mediump vec3 rgb = mix(bg.rgb, fg.rgb, clamp(fg.a / alpha_tot, 0.0, 1.0));
mediump vec4 frag_wet = vec4(rgb, max(bg.a, fg.a * 1.2));
mediump vec4 frag_dry = vec4(rgb, alpha_tot);
highp float contribution = max(0.0, opacity - bg.a) * fg.a;
highp float alpha_tot = bg.a + contribution;
highp vec3 rgb = mix(bg.rgb, fg.rgb, clamp(fg.a / alpha_tot, 0.0, 1.0));
highp vec4 frag_wet = vec4(rgb, max(bg.a, fg.a * 1.2));
highp vec4 frag_dry = vec4(rgb, alpha_tot);
frag = mix(frag_dry, frag_wet, wet);
}

View File

@@ -17,17 +17,17 @@ void main()
uniform sampler2D tex;
uniform sampler2D tex_alpha;
uniform sampler2D tex_bg;
uniform mediump float alpha;
uniform highp float alpha;
uniform bool highlight;
in mediump vec2 uv;
out mediump vec4 frag;
in highp vec2 uv;
out highp vec4 frag;
void main()
{
mediump vec3 rgb = texture(tex, uv).rgb;
mediump float a = texture(tex_alpha, uv).a;
mediump vec4 c = vec4(rgb, a);
highp vec3 rgb = texture(tex, uv).rgb;
highp float a = texture(tex_alpha, uv).a;
highp vec4 c = vec4(rgb, a);
frag = highlight ?
vec4(clamp(vec3(0.3) + c.rgb, vec3(0.0), vec3(1.0)), c.a) :
texture(tex, uv) * vec4(1.0, 1.0, 1.0, alpha);

View File

@@ -15,15 +15,15 @@ void main()
[[fragment]]
uniform sampler2D tex;
uniform mediump float alpha;
uniform highp float alpha;
uniform bool highlight;
in mediump vec2 uv;
out mediump vec4 frag;
in highp vec2 uv;
out highp vec4 frag;
void main()
{
mediump vec4 c = texture(tex, uv);
highp vec4 c = texture(tex, uv);
frag = highlight ?
vec4(clamp(vec3(0.3) + c.rgb, vec3(0.0), vec3(1.0)), c.a) :
c * vec4(1.0, 1.0, 1.0, alpha);

View File

@@ -20,14 +20,14 @@ void main()
uniform sampler2D tex;
uniform sampler2D tex_alpha;
uniform sampler2D tex_bg;
uniform mediump float alpha;
uniform highp float alpha;
uniform int blend_mode;
in mediump vec2 uv;
in highp vec2 uv;
#if defined(GL_EXT_shader_framebuffer_fetch)
inout highp vec4 frag;
#else
out mediump vec4 frag;
out highp vec4 frag;
#endif
void main()
@@ -38,15 +38,15 @@ void main()
#elif defined(GL_ARM_shader_framebuffer_fetch)
highp vec4 bg = gl_LastFragColorARM;
#else
mediump vec4 bg = texture(tex_bg, uv);
highp vec4 bg = texture(tex_bg, uv);
#endif
mediump vec4 fg = vec4(texture(tex, uv).rgb, texture(tex_alpha, uv).a);
highp vec4 fg = vec4(texture(tex, uv).rgb, texture(tex_alpha, uv).a);
if (fg.a == 0.0)
{
frag = bg;
return;
}
mediump vec4 blended = blend(bg, fg, blend_mode);
highp vec4 blended = blend(bg, fg, blend_mode);
frag = vec4(blended.rgb, blended.a * alpha);
}