move shaders into .glsl files and add #include feature
This commit is contained in:
21
data/shaders/atlas.glsl
Normal file
21
data/shaders/atlas.glsl
Normal file
@@ -0,0 +1,21 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
uniform vec2 tof;
|
||||
uniform vec2 tsz;
|
||||
in vec2 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = tof + uvs * tsz;
|
||||
gl_Position = mvp * vec4(pos, 0.0, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform sampler2D tex;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = texture(tex, uv);
|
||||
};
|
||||
27
data/shaders/bake-uv.glsl
Normal file
27
data/shaders/bake-uv.glsl
Normal file
@@ -0,0 +1,27 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec3 nor;
|
||||
in vec2 uvs;
|
||||
out vec3 n;
|
||||
out vec3 p;
|
||||
void main()
|
||||
{
|
||||
n = nor;
|
||||
p = vec3(mvp * pos);
|
||||
gl_Position = vec4(uvs * 2.0 - 1.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
[[fragment]]
|
||||
uniform int mode;
|
||||
in highp vec3 n;
|
||||
in highp vec3 p;
|
||||
out highp vec3 frag;
|
||||
void main()
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case 0: frag = normalize(n); break;
|
||||
case 1: frag = p; break;
|
||||
}
|
||||
}
|
||||
24
data/shaders/checkerboard.glsl
Normal file
24
data/shaders/checkerboard.glsl
Normal file
@@ -0,0 +1,24 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
}
|
||||
|
||||
[[fragment]]
|
||||
uniform bool colorize;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
const mediump vec4 c1 = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
const mediump vec4 c2 = vec4(0.9, 0.9, 0.9, 1.0);
|
||||
mediump vec2 c = floor(fract(uv * 10.0) * 2.0);
|
||||
mediump float alpha = mix(c.x, 1.0 - c.x, c.y);
|
||||
if (colorize) frag = mix(c1, c2, alpha) * vec4(fract(uv.x * 5.0), uv.y, 1.0, 1.0);
|
||||
else frag = mix(c1, c2, alpha);
|
||||
}
|
||||
22
data/shaders/color-hue.glsl
Normal file
22
data/shaders/color-hue.glsl
Normal file
@@ -0,0 +1,22 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec3 uv;
|
||||
void main()
|
||||
{
|
||||
gl_Position = mvp * pos;
|
||||
uv = vec3(uvs, pos.w);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/hsv.glsl"
|
||||
uniform mediump vec4 col;
|
||||
uniform bool dir; // 0:horizontal, 1:vertical
|
||||
in mediump vec3 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = vec4(hsv2rgb(vec3(dir?uv.y:uv.x, 1.0, 1.0)), 1.0);
|
||||
};
|
||||
|
||||
20
data/shaders/color-quad.glsl
Normal file
20
data/shaders/color-quad.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec3 uv;
|
||||
void main()
|
||||
{
|
||||
gl_Position = mvp * pos;
|
||||
uv = vec3(uvs, pos.w);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/hsv.glsl"
|
||||
uniform mediump vec4 col; // HSV
|
||||
in mediump vec3 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = vec4(hsv2rgb(vec3(col.x, uv.x, 1.0 - uv.y)), 1.0);
|
||||
};
|
||||
21
data/shaders/color-tri.glsl
Normal file
21
data/shaders/color-tri.glsl
Normal file
@@ -0,0 +1,21 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec3 uv;
|
||||
void main()
|
||||
{
|
||||
gl_Position = mvp * pos;
|
||||
uv = vec3(uvs, pos.w);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/hsv.glsl"
|
||||
uniform mediump vec4 col; // in HSV
|
||||
in mediump vec3 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump float sat = tan(atan(uv.y, uv.x)) * 0.5 + 0.5;
|
||||
frag = vec4(hsv2rgb(vec3(col.r, sat, uv.x)), 1.0);
|
||||
};
|
||||
16
data/shaders/color.glsl
Normal file
16
data/shaders/color.glsl
Normal file
@@ -0,0 +1,16 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
void main()
|
||||
{
|
||||
gl_Position = mvp * pos;
|
||||
gl_PointSize = 5.0;
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform mediump vec4 col;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = col;
|
||||
};
|
||||
74
data/shaders/comp-draw.glsl
Normal file
74
data/shaders/comp-draw.glsl
Normal file
@@ -0,0 +1,74 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/blur.glsl"
|
||||
#include "include/blend.glsl"
|
||||
#include "include/blend-stroke.glsl"
|
||||
#include "include/color.glsl"
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D tex_stroke;
|
||||
uniform sampler2D tex_mask;
|
||||
uniform mediump float alpha;
|
||||
uniform mediump float stroke_alpha;
|
||||
uniform mediump int blend_mode;
|
||||
uniform mediump vec2 resolution;
|
||||
uniform bool lock;
|
||||
uniform bool mask;
|
||||
|
||||
uniform bool use_dual;
|
||||
uniform sampler2D tex_dual;
|
||||
uniform mediump float dual_alpha;
|
||||
uniform mediump 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 mediump bool pattern_invert;
|
||||
uniform mediump int patt_blend_mode;
|
||||
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
|
||||
void main()
|
||||
{
|
||||
mediump vec4 base = texture(tex, uv);
|
||||
mediump vec4 stroke = texture(tex_stroke, uv);
|
||||
if (use_pattern)
|
||||
{
|
||||
mediump vec2 rscale = resolution / vec2(512.0);
|
||||
mediump float patt = texture(tex_pattern, uv * (0.5 / pattern_scale) * rscale + pattern_offset).r;
|
||||
if (pattern_invert)
|
||||
patt = 1.0 - patt;
|
||||
//" patt = patt * pattern_alpha + (1.0 - pattern_alpha);
|
||||
if (pattern_bright != 0.5)
|
||||
patt = brightness1(patt, 1.0 - pattern_bright);
|
||||
if (pattern_contr != 0.5)
|
||||
patt = contrast1(patt, pattern_contr);
|
||||
//" mediump float pa = (1.0 - patt) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 10.0);
|
||||
mediump float pa = pow((1.0 - patt), max(1.0, (1.0 - pattern_depth) * 10.0)) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 5.0);
|
||||
stroke.a = mix(pa * stroke.a, stroke.a, 0.0);
|
||||
}
|
||||
if (use_dual)
|
||||
{
|
||||
mediump vec4 dual = texture(tex_dual, uv);
|
||||
stroke.a = blend_stroke(stroke.a, dual.a * dual_alpha, dual_blend_mode);
|
||||
}
|
||||
stroke.a = mask ? stroke.a * stroke_alpha * blur(tex_mask, uv).r : stroke.a * stroke_alpha;
|
||||
if (!lock && base.a == 0.0) { frag = stroke * vec4(1.0, 1.0, 1.0, alpha); return; }
|
||||
mediump vec4 blended = blend(base, stroke, blend_mode);
|
||||
frag = vec4(blended.rgb, (lock ? base.a : blended.a) * alpha);
|
||||
};
|
||||
29
data/shaders/comp-erase.glsl
Normal file
29
data/shaders/comp-erase.glsl
Normal file
@@ -0,0 +1,29 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/blur.glsl"
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D tex_stroke;
|
||||
uniform sampler2D tex_mask;
|
||||
uniform mediump float alpha;
|
||||
uniform mediump float stroke_alpha;
|
||||
uniform mediump vec2 resolution;
|
||||
uniform bool mask;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump vec4 base = texture(tex, uv);
|
||||
mediump vec4 stroke = texture(tex_stroke, uv);
|
||||
stroke.a = mask ? stroke.a * stroke_alpha * blur(tex_mask, uv).r : stroke.a * stroke_alpha;
|
||||
frag = vec4(base.rgb, clamp((base.a - stroke.a) * alpha, 0.0, 1.0));
|
||||
};
|
||||
29
data/shaders/equirect.glsl
Normal file
29
data/shaders/equirect.glsl
Normal file
@@ -0,0 +1,29 @@
|
||||
[[vertex]]
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define TWO_PI 6.283185307179586476925286766559
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = (vec2(1.0) - uvs + vec2(0.25,0.0)) * vec2(TWO_PI, PI);
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
}
|
||||
|
||||
[[fragment]]
|
||||
uniform samplerCube tex;
|
||||
in highp vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
highp float anglex = uv.x;
|
||||
highp float angley = uv.y;
|
||||
highp float sx = sin(anglex);
|
||||
highp float cx = cos(anglex);
|
||||
highp vec3 dir = vec3(0.0, 0.0, 0.0);
|
||||
dir.x = sin(angley) * cx;
|
||||
dir.y = cos(angley);
|
||||
dir.z = sin(angley) * sx;
|
||||
frag = texture(tex, dir);
|
||||
}
|
||||
22
data/shaders/font.glsl
Normal file
22
data/shaders/font.glsl
Normal file
@@ -0,0 +1,22 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec2 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos, 0.0, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform mediump sampler2D tex;
|
||||
uniform mediump vec4 col;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump float a = texture(tex, uv).r;
|
||||
frag = vec4(col.rgb, a);
|
||||
};
|
||||
|
||||
9
data/shaders/include/blend-stroke.glsl
Normal file
9
data/shaders/include/blend-stroke.glsl
Normal file
@@ -0,0 +1,9 @@
|
||||
mediump float blend_stroke(mediump float base, mediump float stroke, int mode)
|
||||
{
|
||||
if (mode == 0) /* normal */ return (base + stroke) * 0.5;
|
||||
else if (mode == 1) /* multiply */ return base * stroke;
|
||||
else if (mode == 2) /* screen */ return 1.0-(1.0-base)*(1.0-stroke);
|
||||
else if (mode == 3) /* color-dodge */ return base/(1.0-stroke);
|
||||
else if (mode == 4) /* overlay */ return mix(2.0*base*stroke, 1.0-2.0*(1.0-base)*(1.0-stroke), floor(base*2.0));
|
||||
else return 1.0;
|
||||
}
|
||||
20
data/shaders/include/blend.glsl
Normal file
20
data/shaders/include/blend.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
mediump vec3 blend_normal(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
||||
{ return mix(base.rgb, stroke.rgb, stroke.a/alpha_tot); }
|
||||
mediump vec3 blend_multiply(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
||||
{ return mix(stroke.rgb, mix(base.rgb, base.rgb*stroke.rgb, stroke.a/alpha_tot), base.a/alpha_tot); }
|
||||
mediump vec3 blend_screen(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
||||
{ return mix(stroke.rgb, mix(base.rgb, 1.0-(1.0-base.rgb)*(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }
|
||||
mediump vec3 blend_colorDodge(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
||||
{ return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }
|
||||
mediump vec3 blend_overlay(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot)
|
||||
{ return mix(stroke.rgb, mix(base.rgb, mix(2.0*base.rgb*stroke.rgb, 1.0-2.0*(1.0-base.rgb)*(1.0-stroke.rgb), floor(base.rgb*2.0)), stroke.a/alpha_tot), base.a/alpha_tot); }
|
||||
mediump vec4 blend(mediump vec4 base, mediump vec4 stroke, int mode) {
|
||||
mediump float contribution = (1.0 - base.a) * stroke.a;
|
||||
mediump float alpha_tot = base.a + contribution;
|
||||
if (mode == 0) return vec4(blend_normal(base, stroke, alpha_tot), alpha_tot);
|
||||
else if (mode == 1) return vec4(blend_multiply(base, stroke, alpha_tot), alpha_tot);
|
||||
else if (mode == 2) return vec4(blend_screen(base, stroke, alpha_tot), alpha_tot);
|
||||
else if (mode == 3) return vec4(blend_colorDodge(base, stroke, alpha_tot), alpha_tot);
|
||||
else if (mode == 4) return vec4(blend_overlay(base, stroke, alpha_tot), alpha_tot);
|
||||
else return vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
13
data/shaders/include/blur.glsl
Normal file
13
data/shaders/include/blur.glsl
Normal file
@@ -0,0 +1,13 @@
|
||||
mediump vec4 blur(sampler2D t, mediump vec2 uv)
|
||||
{
|
||||
mediump 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));
|
||||
sum += textureOffset(t, uv, ivec2( 0, -1));
|
||||
sum += textureOffset(t, uv, ivec2( 0, 1));
|
||||
sum += textureOffset(t, uv, ivec2( 1, -1));
|
||||
sum += textureOffset(t, uv, ivec2( 1, 0));
|
||||
sum += textureOffset(t, uv, ivec2( 1, 1));
|
||||
return sum / vec4(9.0);
|
||||
}
|
||||
20
data/shaders/include/color.glsl
Normal file
20
data/shaders/include/color.glsl
Normal file
@@ -0,0 +1,20 @@
|
||||
mediump vec3 brightness3(mediump vec3 c, mediump float val)
|
||||
{
|
||||
return clamp(c + vec3(val * 2.0 - 1.0), vec3(0), vec3(1));
|
||||
}
|
||||
mediump vec3 contrast3(mediump vec3 c, mediump 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));
|
||||
return clamp(factor * (c - 0.5) + 0.5, vec3(0), vec3(1));
|
||||
}
|
||||
mediump float brightness1(mediump float c, mediump float val)
|
||||
{
|
||||
return clamp(c + (val * 2.0 - 1.0), 0.0, 1.0);
|
||||
}
|
||||
mediump float contrast1(mediump float c, mediump 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));
|
||||
return clamp(factor * (c - 0.5) + 0.5, 0.0, 1.0);
|
||||
}
|
||||
5
data/shaders/include/ext-fb-fetch.glsl
Normal file
5
data/shaders/include/ext-fb-fetch.glsl
Normal file
@@ -0,0 +1,5 @@
|
||||
#if defined(GL_EXT_shader_framebuffer_fetch)
|
||||
#extension GL_EXT_shader_framebuffer_fetch : enable
|
||||
#elif defined(GL_ARM_shader_framebuffer_fetch)
|
||||
#extension GL_ARM_shader_framebuffer_fetch : enable
|
||||
#endif
|
||||
15
data/shaders/include/hsv.glsl
Normal file
15
data/shaders/include/hsv.glsl
Normal file
@@ -0,0 +1,15 @@
|
||||
mediump vec3 rgb2hsv(mediump 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;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
10
data/shaders/include/rand.glsl
Normal file
10
data/shaders/include/rand.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
// http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
|
||||
highp float rand(mediump vec2 co)
|
||||
{
|
||||
highp float a = 12.9898;
|
||||
highp float b = 78.233;
|
||||
highp float c = 43758.5453;
|
||||
highp float dt= dot(co.xy, vec2(a,b));
|
||||
highp float sn= mod(dt, 3.14);
|
||||
return fract(sin(sn) * c);
|
||||
}
|
||||
23
data/shaders/lambert.glsl
Normal file
23
data/shaders/lambert.glsl
Normal file
@@ -0,0 +1,23 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec3 nor;
|
||||
in vec2 uvs;
|
||||
out vec3 n;
|
||||
void main()
|
||||
{
|
||||
n = nor;
|
||||
gl_Position = mvp * pos;
|
||||
}
|
||||
|
||||
[[fragment]]
|
||||
uniform mediump vec3 light_dir;
|
||||
uniform mediump float ambient;
|
||||
in mediump vec3 n;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump float d = max(0.0, dot(normalize(n), light_dir));
|
||||
frag = vec4(vec3(d) + ambient, 1.0);
|
||||
//frag = vec4(normalize(n) * 0.5 + 0.5, 1.0);
|
||||
}
|
||||
27
data/shaders/lightmap.glsl
Normal file
27
data/shaders/lightmap.glsl
Normal file
@@ -0,0 +1,27 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec3 nor;
|
||||
in vec2 uvs;
|
||||
out vec3 n;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
n = nor;
|
||||
uv = uvs;
|
||||
gl_Position = mvp * pos;
|
||||
}
|
||||
|
||||
[[fragment]]
|
||||
uniform mediump sampler2D tex;
|
||||
uniform mediump vec3 light_dir;
|
||||
uniform mediump float ambient;
|
||||
in mediump vec3 n;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump float d = max(0.0, dot(normalize(n), normalize(light_dir)));
|
||||
mediump vec4 c = texture(tex, uv);
|
||||
frag = vec4(c.rgb * d + ambient, 1.0);
|
||||
}
|
||||
31
data/shaders/stroke-instanced.glsl
Normal file
31
data/shaders/stroke-instanced.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
[[vertex]]
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
in mat4 a_mvp;
|
||||
in float a_flow;
|
||||
out vec3 uv;
|
||||
out float alpha;
|
||||
void main()
|
||||
{
|
||||
uv = vec3(uvs, pos.w);
|
||||
alpha = a_flow;
|
||||
gl_Position = a_mvp * vec4(pos.xyz, 1.0);
|
||||
}
|
||||
|
||||
[[fragment]]
|
||||
uniform mediump sampler2D tex;
|
||||
uniform mediump sampler2D tex_pattern;
|
||||
uniform mediump vec4 col;
|
||||
uniform mediump vec2 resolution;
|
||||
uniform mediump vec2 pattern_offset;
|
||||
uniform mediump float pattern_alpha;
|
||||
in mediump float alpha;
|
||||
in mediump vec3 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump vec2 uv2 = gl_FragCoord.st / resolution;
|
||||
mediump float pattern = 1.0 - (texture(tex_pattern, (uv2+pattern_offset)).r * 0.9) * pattern_alpha;
|
||||
mediump float a = (1.0 - texture(tex, uv.xy).r) * alpha * pattern;
|
||||
frag = vec4(col.rgb, a);
|
||||
}
|
||||
31
data/shaders/stroke-preview.glsl
Normal file
31
data/shaders/stroke-preview.glsl
Normal file
@@ -0,0 +1,31 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform sampler2D tex;
|
||||
uniform mediump vec4 col;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main() {
|
||||
mediump float stroke = 1.0 - texture(tex, uv).r;
|
||||
int zero_count = 0;
|
||||
if (textureOffset(tex, uv, ivec2(-1, -1)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2(-1, 0)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2(-1, +1)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2( 0, -1)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2( 0, 0)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2( 0, +1)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2(+1, -1)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2(+1, 0)).r > 0.99) zero_count++;
|
||||
if (textureOffset(tex, uv, ivec2(+1, +1)).r > 0.99) zero_count++;
|
||||
mediump float edge = (zero_count > 1 && zero_count < 9) ? 0.75 : 0.0;
|
||||
frag = vec4(col.rgb, edge * (1.0 - float(zero_count) / 9.f));
|
||||
};
|
||||
93
data/shaders/stroke.glsl
Normal file
93
data/shaders/stroke.glsl
Normal file
@@ -0,0 +1,93 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
in vec2 uvs2;
|
||||
out vec2 uv;
|
||||
out vec2 uv_2;
|
||||
out float q;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
uv_2 = uvs2;
|
||||
q = pos.w;
|
||||
gl_Position = mvp * vec4(pos.xy, 0.0, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/ext-fb-fetch.glsl"
|
||||
#include "include/rand.glsl"
|
||||
#include "include/color.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 noise;
|
||||
uniform mediump float mix_alpha;
|
||||
uniform mediump 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 mediump bool pattern_invert;
|
||||
|
||||
in mediump vec2 uv;
|
||||
in mediump vec2 uv_2;
|
||||
in mediump float q;
|
||||
#if defined(GL_EXT_shader_framebuffer_fetch)
|
||||
inout mediump vec4 frag;
|
||||
#else
|
||||
out mediump 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);
|
||||
if (use_pattern)
|
||||
{
|
||||
mediump vec2 rscale = resolution / vec2(512.0);
|
||||
mediump float patt = texture(tex_pattern, uv2 * (0.5 / pattern_scale) * rscale + pattern_offset).r;
|
||||
if (pattern_invert)
|
||||
patt = 1.0 - patt;
|
||||
patt = patt * pattern_depth + (1.0 - pattern_depth);
|
||||
if (pattern_bright != 0.5)
|
||||
patt = brightness1(patt, 1.0 - pattern_bright);
|
||||
if (pattern_contr != 0.5)
|
||||
patt = contrast1(patt, pattern_contr);
|
||||
fg.a = mix(fg.a, fg.a * patt, pattern_depth);
|
||||
}
|
||||
|
||||
#if defined(GL_EXT_shader_framebuffer_fetch)
|
||||
mediump vec4 bg = frag;
|
||||
#elif defined(GL_ARM_shader_framebuffer_fetch)
|
||||
mediump vec4 bg = gl_LastFragColorARM;
|
||||
#else
|
||||
mediump vec4 bg = texture(tex_bg, uv2);
|
||||
#endif
|
||||
|
||||
fg.a *= 1.0-rand(uv2+uv)*noise;
|
||||
if (fg.a == 0.0) discard;
|
||||
if (mix_alpha > 0.0)
|
||||
{
|
||||
mediump 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);
|
||||
fg.rgb = mix(fg.rgb, mbg.rgb, mix_alpha * mbg.a);
|
||||
}
|
||||
mediump float contribution = (1.0 - bg.a) * fg.a;
|
||||
mediump float alpha_tot = bg.a + contribution;
|
||||
mediump vec3 rgb = mix(bg.rgb, fg.rgb, fg.a / alpha_tot);
|
||||
mediump vec4 frag_wet = vec4(rgb, max(bg.a, fg.a * 1.2));
|
||||
mediump vec4 frag_dry = vec4(rgb, alpha_tot);
|
||||
frag = mix(frag_dry, frag_wet, wet);
|
||||
};
|
||||
|
||||
28
data/shaders/texture-alpha-sep.glsl
Normal file
28
data/shaders/texture-alpha-sep.glsl
Normal file
@@ -0,0 +1,28 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D tex_alpha;
|
||||
uniform sampler2D tex_bg;
|
||||
uniform mediump float alpha;
|
||||
uniform bool highlight;
|
||||
in mediump vec2 uv;
|
||||
out mediump 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);
|
||||
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);
|
||||
};
|
||||
24
data/shaders/texture-alpha.glsl
Normal file
24
data/shaders/texture-alpha.glsl
Normal file
@@ -0,0 +1,24 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform sampler2D tex;
|
||||
uniform mediump float alpha;
|
||||
uniform bool highlight;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
mediump 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);
|
||||
};
|
||||
38
data/shaders/texture-blend.glsl
Normal file
38
data/shaders/texture-blend.glsl
Normal file
@@ -0,0 +1,38 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
#include "include/ext-fb-fetch.glsl"
|
||||
#include "include/blend.glsl"
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D tex_alpha;
|
||||
uniform sampler2D tex_bg;
|
||||
uniform mediump float alpha;
|
||||
uniform int blend_mode;
|
||||
in mediump vec2 uv;
|
||||
#if defined(GL_EXT_shader_framebuffer_fetch)
|
||||
inout highp vec4 frag;
|
||||
#else
|
||||
out mediump vec4 frag;
|
||||
#endif
|
||||
void main() {
|
||||
#if defined(GL_EXT_shader_framebuffer_fetch)
|
||||
highp vec4 bg = frag;
|
||||
#elif defined(GL_ARM_shader_framebuffer_fetch)
|
||||
highp vec4 bg = gl_LastFragColorARM;
|
||||
#else
|
||||
mediump vec4 bg = texture(tex_bg, uv);
|
||||
#endif
|
||||
mediump 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);
|
||||
frag = vec4(blended.rgb, blended.a * alpha);
|
||||
};
|
||||
19
data/shaders/texture.glsl
Normal file
19
data/shaders/texture.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
uniform sampler2D tex;
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = texture(tex, uv);
|
||||
};
|
||||
18
data/shaders/uvs.glsl
Normal file
18
data/shaders/uvs.glsl
Normal file
@@ -0,0 +1,18 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec2 uvs;
|
||||
out vec2 uv;
|
||||
void main()
|
||||
{
|
||||
uv = uvs;
|
||||
gl_Position = mvp * vec4(pos.xyz, 1.0);
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
in mediump vec2 uv;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = vec4(uv, 0.0, 1.0);
|
||||
};
|
||||
19
data/shaders/vertex-color.glsl
Normal file
19
data/shaders/vertex-color.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
[[vertex]]
|
||||
uniform mat4 mvp;
|
||||
in vec4 pos;
|
||||
in vec4 col;
|
||||
out vec4 c;
|
||||
void main()
|
||||
{
|
||||
c = col;
|
||||
gl_Position = mvp * pos;
|
||||
gl_PointSize = 5.0;
|
||||
};
|
||||
|
||||
[[fragment]]
|
||||
in mediump vec4 c;
|
||||
out mediump vec4 frag;
|
||||
void main()
|
||||
{
|
||||
frag = c;
|
||||
};
|
||||
Reference in New Issue
Block a user