[orx-jumpflood] Make module multiplatform
This commit is contained in:
9
orx-jumpflood/src/shaders/glsl/alpha-threshold.frag
Normal file
9
orx-jumpflood/src/shaders/glsl/alpha-threshold.frag
Normal file
@@ -0,0 +1,9 @@
|
||||
uniform sampler2D tex0;
|
||||
in vec2 v_texCoord0;
|
||||
uniform float threshold;
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float ref = step(threshold , texture(tex0, v_texCoord0).a);
|
||||
o_color = vec4(ref, ref, ref, 1.0);
|
||||
}
|
||||
20
orx-jumpflood/src/shaders/glsl/contour-points.frag
Normal file
20
orx-jumpflood/src/shaders/glsl/contour-points.frag
Normal file
@@ -0,0 +1,20 @@
|
||||
uniform sampler2D tex0;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec2 stepSize = 1.0 / vec2(textureSize(tex0, 0));
|
||||
float ref = step(0.5 , texture(tex0, v_texCoord0).r);
|
||||
|
||||
float laplacian = -4.0 * ref;
|
||||
|
||||
laplacian += step(0.5, texture(tex0, v_texCoord0 + vec2(stepSize.x, 0.0)).r);
|
||||
laplacian += step(0.5, texture(tex0, v_texCoord0 - vec2(stepSize.x, 0.0)).r);
|
||||
laplacian += step(0.5, texture(tex0, v_texCoord0 + vec2(0.0, stepSize.y)).r);
|
||||
laplacian += step(0.5, texture(tex0, v_texCoord0 - vec2(0.0, stepSize.y)).r);
|
||||
|
||||
float contour = 1.0 - step(0.0, laplacian);
|
||||
|
||||
o_color = vec4(contour, contour, contour, 1.0);
|
||||
}
|
||||
14
orx-jumpflood/src/shaders/glsl/encode-points.frag
Normal file
14
orx-jumpflood/src/shaders/glsl/encode-points.frag
Normal file
@@ -0,0 +1,14 @@
|
||||
uniform sampler2D tex0;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec4 t = texture(tex0, v_texCoord0);
|
||||
vec4 outc = vec4(-1.0, -1.0, t.r, 1.0);
|
||||
|
||||
if (t.r > 0.0) {
|
||||
outc.xy = v_texCoord0.xy;
|
||||
}
|
||||
o_color = outc;
|
||||
}
|
||||
122
orx-jumpflood/src/shaders/glsl/encode-subpixel.frag
Normal file
122
orx-jumpflood/src/shaders/glsl/encode-subpixel.frag
Normal file
@@ -0,0 +1,122 @@
|
||||
uniform sampler2D tex0;
|
||||
in vec2 v_texCoord0;
|
||||
uniform float threshold;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
float zd(float d) {
|
||||
if (d < 0.0001) {
|
||||
return 1.0;
|
||||
} else {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 stepSize = 1.0 / vec2(textureSize(tex0, 0));
|
||||
float ref = step(threshold, texture(tex0, v_texCoord0).a);
|
||||
|
||||
|
||||
vec2 o = vec2(0.0); //stepSize/2.0;
|
||||
float t00 = texture(tex0, v_texCoord0 + o + vec2(0.0, 0.0)).a;
|
||||
float t10 = texture(tex0, v_texCoord0 + o + vec2(stepSize.x, 0.0)).a;
|
||||
float t01 = texture(tex0, v_texCoord0 + o + vec2(0.0, stepSize.y)).a;
|
||||
float t11 = texture(tex0, v_texCoord0 + o + vec2(stepSize.x, stepSize.y)).a;
|
||||
|
||||
int mask = 0;
|
||||
|
||||
if (t00 >= threshold) {
|
||||
mask += 1;
|
||||
}
|
||||
if (t10 >= threshold) {
|
||||
mask += 2;
|
||||
}
|
||||
if (t01 >= threshold) {
|
||||
mask += 4;
|
||||
}
|
||||
if (t11 >= threshold) {
|
||||
mask += 8;
|
||||
}
|
||||
|
||||
vec2 offset = vec2(0.0);
|
||||
if (mask == 1) {
|
||||
offset.x = 1.0 - (threshold-t10) / zd(t00-t10);
|
||||
offset.y = 1.0 - ((threshold-t01) / zd(t00-t01));
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 2) {
|
||||
offset.x = ((threshold-t00) / zd(t10-t00));
|
||||
offset.y = 1.0-(threshold-t11) / zd(t10-t11);
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 3) { // OK
|
||||
float dy0 = 1.0 - (threshold - t01) / zd(t00 - t01);
|
||||
float dy1 = 1.0 - (threshold - t11) / zd(t10 - t11);
|
||||
offset.y = dy0 + dy1;
|
||||
offset.x = 1.0;
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 4) { // OK
|
||||
offset.x = 1.0 - (threshold-t11) / zd(t01-t11);
|
||||
offset.y = (threshold-t00) / zd(t01-t00);
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 5) { // OK
|
||||
float dx0 = 1.0- (threshold - t10) / zd(t00 - t10);
|
||||
float dx1 = 1.0-(threshold - t11) / zd(t01 - t11);
|
||||
offset.x = dx0 + dx1;
|
||||
offset.y = 1.0;
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 6 || mask == 9) {
|
||||
offset = vec2(0.5);
|
||||
}
|
||||
if (mask == 7) { // OK
|
||||
offset.x = 1.0 - (threshold-t11) / zd(t01-t11);
|
||||
offset.y = 1.0 - (threshold-t11) / zd(t10-t11);
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 8) { // OK
|
||||
offset.x = (threshold-t01) / zd(t11-t01);
|
||||
offset.y = (threshold-t10) / zd(t11-t10);
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 10) { // OK
|
||||
float dx0 = (threshold - t00) / zd(t10 - t00);
|
||||
float dx1 = (threshold - t01) / zd(t11 - t01);
|
||||
offset.x = (dx0 + dx1);
|
||||
offset.y = 1.0;
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 11) { // OK
|
||||
offset.x = (threshold-t01) / zd(t11-t01);
|
||||
offset.y = (threshold-t01) / zd(t00-t01);
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 12) { // OK
|
||||
float dy0 = (threshold - t00) / zd(t01 - t00);
|
||||
float dy1 = (threshold - t10) / zd(t11 - t10);
|
||||
offset.y = dy0 + dy1;
|
||||
offset.x = 1.0;
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 13) { // OK
|
||||
offset.x = 1.0 - (threshold-t10) / zd(t00-t10);
|
||||
offset.y = (threshold-t10) / zd(t11-t10);
|
||||
offset /= 2;
|
||||
}
|
||||
if (mask == 14) { // OK
|
||||
offset.x = (threshold-t00) / zd(t10-t00);
|
||||
offset.y = (threshold-t00) / zd(t01-t00);
|
||||
offset /= 2;
|
||||
}
|
||||
|
||||
float contour = (mask != 0 && mask != 15)?1.0:0.0;
|
||||
|
||||
//float contour = (mask == 14 || mask == 11 || mask == 7 || mask == 13) ? 1.0 : 0.0;
|
||||
if (contour > 0.0) {
|
||||
o_color = vec4(v_texCoord0 /*+ offset*stepSize*/ , ref, 1.0);
|
||||
} else {
|
||||
o_color = vec4(-1.0, -1.0, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
25
orx-jumpflood/src/shaders/glsl/id-contours.frag
Normal file
25
orx-jumpflood/src/shaders/glsl/id-contours.frag
Normal file
@@ -0,0 +1,25 @@
|
||||
uniform sampler2D tex0;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec4 colorMask = vec4(0.0, 0.0, 1.0, 0.0);
|
||||
vec2 stepSize = 1.0 / vec2(textureSize(tex0, 0));
|
||||
vec4 ref = texture(tex0, v_texCoord0);
|
||||
|
||||
float laplacian = 0.0;
|
||||
|
||||
laplacian += abs(texture(tex0, v_texCoord0 + vec2(stepSize.x, 0.0)).b-ref.b);
|
||||
laplacian += abs(texture(tex0, v_texCoord0 - vec2(stepSize.x, 0.0)).b-ref.b);
|
||||
laplacian += abs(texture(tex0, v_texCoord0 + vec2(0.0, stepSize.y)).b-ref.b);
|
||||
laplacian += abs(texture(tex0, v_texCoord0 - vec2(0.0, stepSize.y)).b-ref.b);
|
||||
|
||||
float contour = step(0.0, laplacian);
|
||||
|
||||
if (laplacian > 0.001) {
|
||||
o_color = vec4(v_texCoord0.x, v_texCoord0.y, ref.b, 1.0);
|
||||
} else {
|
||||
o_color = vec4(-1.0, -1.0, -1.0, 1.0);
|
||||
}
|
||||
}
|
||||
55
orx-jumpflood/src/shaders/glsl/inner-bevel.frag
Normal file
55
orx-jumpflood/src/shaders/glsl/inner-bevel.frag
Normal file
@@ -0,0 +1,55 @@
|
||||
uniform sampler2D tex0; // image
|
||||
uniform sampler2D tex1; // distance
|
||||
|
||||
uniform float angle;
|
||||
uniform float width;
|
||||
uniform float noise;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
#define HASHSCALE 443.8975
|
||||
vec2 hash22(vec2 p) {
|
||||
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE);
|
||||
p3 += dot(p3, p3.yzx+19.19);
|
||||
return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
float r = radians(angle);
|
||||
|
||||
vec4 color = texture(tex0, v_texCoord0);
|
||||
|
||||
|
||||
vec2 step = 1.0 / vec2(textureSize(tex0, 0));
|
||||
|
||||
vec2 distance = vec2(0.0);
|
||||
float totalWeight = 0.0;
|
||||
for (int j = 0; j < 1; ++j) {
|
||||
for (int i =0; i < 1; ++i) {
|
||||
vec2 hn = (hash22(v_texCoord0)-0.5) * noise;
|
||||
vec2 s = texture(tex1, v_texCoord0 + step * vec2(i,j)).xy + hn*0.0;
|
||||
distance += s;
|
||||
totalWeight += 1.0;
|
||||
}
|
||||
}
|
||||
distance /= totalWeight;
|
||||
|
||||
//vec2 distance = texture(tex1, v_texCoord0).xy + hn;
|
||||
|
||||
float d = length(distance);
|
||||
vec2 n = normalize(distance);
|
||||
vec2 l = vec2(cos(r), sin(r));
|
||||
|
||||
float e = smoothstep(0.0, width, d) * smoothstep(width*2.0, width, d);
|
||||
float o = max(0.0,dot(n, l))*e ;
|
||||
float o2 = max(0.0,-dot(n, l))*e ;
|
||||
//o_color = vec4(vec3(o),1.0) * color.a;
|
||||
|
||||
vec3 nc = color.a > 0.0?
|
||||
color.rgb/color.a : vec3(0.0);
|
||||
|
||||
|
||||
o_color = vec4(nc+vec3(o)-vec3(o2),1.0) * color.a;
|
||||
}
|
||||
37
orx-jumpflood/src/shaders/glsl/inner-glow.frag
Normal file
37
orx-jumpflood/src/shaders/glsl/inner-glow.frag
Normal file
@@ -0,0 +1,37 @@
|
||||
uniform sampler2D tex0; // image
|
||||
uniform sampler2D tex1; // distance
|
||||
|
||||
uniform float width;
|
||||
uniform float noise;
|
||||
uniform vec4 color;
|
||||
uniform float shape;
|
||||
uniform float imageOpacity;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
#define HASHSCALE 443.8975
|
||||
vec2 hash22(vec2 p) {
|
||||
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE);
|
||||
p3 += dot(p3, p3.yzx+19.19);
|
||||
return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 original = texture(tex0, v_texCoord0);
|
||||
vec2 step = 1.0 / vec2(textureSize(tex0, 0));
|
||||
vec2 distance = texture(tex1, v_texCoord0).rg;
|
||||
float d = length(distance);
|
||||
vec2 n = normalize(distance);
|
||||
|
||||
vec2 h = hash22(v_texCoord0)*10.0;
|
||||
float e = exp(-( pow((d+h.x*noise)*1.0/width, shape)) );
|
||||
|
||||
vec3 norginal = original.a > 0.0 ? original.rgb / original.a : vec3(0.0);
|
||||
|
||||
vec3 add = norginal + color.rgb * e * color.a;
|
||||
o_color = vec4(add, 1.0) * original.a;
|
||||
|
||||
// //o_color = original * imageOpacity + original.a* vec4(color.rgb, 1.0) * e * color.a;
|
||||
// o_color.rgb = max(vec3(0.0), o_color.rgb);
|
||||
// o_color.a = min(o_color.a, 1.0);
|
||||
}
|
||||
47
orx-jumpflood/src/shaders/glsl/inpaint.frag
Normal file
47
orx-jumpflood/src/shaders/glsl/inpaint.frag
Normal file
@@ -0,0 +1,47 @@
|
||||
uniform sampler2D tex0;// image
|
||||
uniform sampler2D tex1;// distance
|
||||
|
||||
uniform float width;
|
||||
uniform float noise;
|
||||
uniform float shape;
|
||||
uniform float imageOpacity;
|
||||
uniform float opacity;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
#define HASHSCALE 443.8975
|
||||
vec2 hash22(vec2 p) {
|
||||
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE);
|
||||
p3 += dot(p3, p3.yzx+19.19);
|
||||
return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 original = texture(tex0, v_texCoord0);
|
||||
vec2 ts = vec2(textureSize(tex0, 0));
|
||||
vec2 step = 1.0 / ts;
|
||||
vec2 distance = texture(tex1, v_texCoord0).rg;
|
||||
|
||||
vec2 n = normalize(distance);
|
||||
|
||||
vec2 uvOff = distance * step * vec2(1.0, -1.0);
|
||||
|
||||
vec4 border = vec4(0.0);
|
||||
|
||||
float w = 0.0;
|
||||
for (int j = -1; j <= 1; ++j) {
|
||||
for (int i = -1; i <= 1; ++i) {
|
||||
vec4 smp = texture(tex0, v_texCoord0 + uvOff + step * vec2(i, j));
|
||||
border += smp;
|
||||
}
|
||||
}
|
||||
|
||||
vec4 nborder = border.a>0.0?vec4(border.rgb/border.a, 1.0):vec4(0.0);
|
||||
float d = length(distance);
|
||||
|
||||
vec2 h = hash22(v_texCoord0)*10.0;
|
||||
float rwidth = max(ts.x, ts.y) * width;
|
||||
float e = shape > 0.0 ? exp(-( pow((d+h.x*noise)*1.0/rwidth, shape))) : 1.0;
|
||||
o_color = original * imageOpacity + (1.0-original.a)* nborder * e * opacity;
|
||||
|
||||
}
|
||||
38
orx-jumpflood/src/shaders/glsl/jumpflood.frag
Normal file
38
orx-jumpflood/src/shaders/glsl/jumpflood.frag
Normal file
@@ -0,0 +1,38 @@
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
uniform sampler2D tex0;
|
||||
uniform int maxSteps;
|
||||
uniform int step;
|
||||
|
||||
out vec4 o_color;
|
||||
void main() {
|
||||
|
||||
float stepwidth = 1.0 / pow(2.0, min(float(maxSteps), float(step+1)));
|
||||
|
||||
float bestDistance = 1E10;
|
||||
vec2 bestCoord = vec2(-100.0);
|
||||
vec2 bestColor = vec2(-1.0);
|
||||
|
||||
vec2 is = vec2(1.0) / vec2(textureSize(tex0, 0));
|
||||
|
||||
float found = 0.0;
|
||||
for (int y = -1; y <= 1; ++y) {
|
||||
for (int x = -1; x <= 1; ++x) {
|
||||
vec2 sampleCoord = v_texCoord0 + vec2(stepwidth) * vec2(x,y);
|
||||
vec4 data = texture( tex0, sampleCoord);
|
||||
vec2 seedCoord = data.xy;
|
||||
vec2 seedColor = data.zw;
|
||||
float dist = length(seedCoord - v_texCoord0);
|
||||
if ((seedCoord.x >= 0.0 && seedCoord.y >= 0.0) && dist <= bestDistance)
|
||||
{
|
||||
found = 1.0;
|
||||
bestDistance = dist;
|
||||
bestCoord = seedCoord;
|
||||
bestColor = seedColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
o_color = vec4(bestCoord, bestColor.r, 1.0);
|
||||
|
||||
}
|
||||
29
orx-jumpflood/src/shaders/glsl/outer-glow.frag
Normal file
29
orx-jumpflood/src/shaders/glsl/outer-glow.frag
Normal file
@@ -0,0 +1,29 @@
|
||||
uniform sampler2D tex0; // image
|
||||
uniform sampler2D tex1; // distance
|
||||
|
||||
uniform float width;
|
||||
uniform float noise;
|
||||
uniform vec4 color;
|
||||
uniform float shape;
|
||||
uniform float imageOpacity;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
#define HASHSCALE 443.8975
|
||||
vec2 hash22(vec2 p) {
|
||||
vec3 p3 = fract(vec3(p.xyx) * HASHSCALE);
|
||||
p3 += dot(p3, p3.yzx+19.19);
|
||||
return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 original = texture(tex0, v_texCoord0);
|
||||
vec2 step = 1.0 / vec2(textureSize(tex0, 0));
|
||||
vec2 distance = texture(tex1, v_texCoord0).rg;
|
||||
float d = length(distance);
|
||||
vec2 n = normalize(distance);
|
||||
|
||||
vec2 h = hash22(v_texCoord0)*10.0;
|
||||
float e = exp(-( pow((d+h.x*noise)*1.0/width, shape)) );
|
||||
o_color = original * imageOpacity + (1.0-original.a)* vec4(color.rgb, 1.0) * e * color.a;
|
||||
}
|
||||
59
orx-jumpflood/src/shaders/glsl/pixel-direction.frag
Normal file
59
orx-jumpflood/src/shaders/glsl/pixel-direction.frag
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
/*
|
||||
use #define OUTPUT_DISTANCE to output distance
|
||||
use #define OUTPUT_DIRECTION to output direction
|
||||
*/
|
||||
|
||||
uniform sampler2D tex0;
|
||||
uniform sampler2D tex1;
|
||||
uniform vec2 originalSize;
|
||||
uniform vec2 directionalField;
|
||||
uniform float distanceScale;
|
||||
uniform bool normalizedDistance;
|
||||
uniform bool unitDirection;
|
||||
uniform bool flipV;
|
||||
uniform bool outputIds;
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec2 sizeDF = vec2(textureSize(tex0, 0)); // this is always square
|
||||
vec2 sizeTF = vec2(textureSize(tex1, 0)); // this can be non-square
|
||||
|
||||
vec2 pixelPosition = v_texCoord0;
|
||||
vec4 textureData = texture(tex0, v_texCoord0);
|
||||
vec2 centroidPixelPosition = textureData.xy;
|
||||
|
||||
|
||||
vec2 pixelDistance = (centroidPixelPosition - pixelPosition) * sizeDF;
|
||||
|
||||
if (flipV) {
|
||||
pixelDistance *= vec2(1.0, -1.0);
|
||||
}
|
||||
|
||||
if (unitDirection) {
|
||||
float length = length(pixelDistance);
|
||||
if (length >= 1E-6) {
|
||||
pixelDistance /= length;
|
||||
}
|
||||
}
|
||||
|
||||
vec2 dfTf = sizeDF / sizeTF; // texture adjusment factor
|
||||
|
||||
float outputData = (!outputIds) ? texture(tex1, v_texCoord0 * dfTf).r : textureData.b;
|
||||
|
||||
#ifdef OUTPUT_DIRECTION
|
||||
if (!normalizedDistance) {
|
||||
o_color = vec4(pixelDistance * distanceScale, outputData, 1.0);
|
||||
} else if (!unitDirection) {
|
||||
o_color = vec4(pixelDistance / originalSize, outputData, 1.0);
|
||||
}
|
||||
#else
|
||||
if (!normalizedDistance) {
|
||||
o_color = vec4( length(pixelDistance * distanceScale).xx, outputData, 1.0);
|
||||
} else if (!unitDirection) {
|
||||
o_color = vec4( length(pixelDistance / originalSize).xx, outputData, 1.0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
37
orx-jumpflood/src/shaders/glsl/pixel-distance.frag
Normal file
37
orx-jumpflood/src/shaders/glsl/pixel-distance.frag
Normal file
@@ -0,0 +1,37 @@
|
||||
uniform sampler2D tex0;
|
||||
uniform sampler2D tex1;
|
||||
|
||||
uniform vec2 originalSize;
|
||||
uniform float distanceScale;
|
||||
uniform bool signedBit;
|
||||
uniform bool signedDistance;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec2 sizeDF = vec2(textureSize(tex0, 0)); // this is always square
|
||||
vec2 sizeTF = vec2(textureSize(tex1, 0)); // this can be non-square
|
||||
|
||||
vec2 pixelPosition = v_texCoord0;
|
||||
vec2 centroidPixelPosition = texture(tex0, v_texCoord0).xy;
|
||||
vec2 pixelDistance = (centroidPixelPosition - pixelPosition) * sizeDF * vec2(1.0, -1.0);
|
||||
|
||||
vec2 dfTf = sizeDF / sizeTF; // texture adjusment factor
|
||||
|
||||
float threshold = texture(tex1, v_texCoord0 * dfTf).r;
|
||||
float distance = length(pixelDistance) * distanceScale;
|
||||
|
||||
if (signedDistance) {
|
||||
if (threshold > 0.5) {
|
||||
distance *= -1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if (signedBit) {
|
||||
o_color = vec4(distance, threshold, 0.0, 1.0);
|
||||
} else {
|
||||
o_color = vec4(vec3(distance), 1.0);
|
||||
}
|
||||
}
|
||||
13
orx-jumpflood/src/shaders/glsl/sdf-blend.frag
Normal file
13
orx-jumpflood/src/shaders/glsl/sdf-blend.frag
Normal file
@@ -0,0 +1,13 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform sampler2D tex1;// signed distance
|
||||
uniform float factor;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float d0 = texture(tex0, v_texCoord0).r;
|
||||
float d1 = texture(tex1, v_texCoord0).r;
|
||||
float d = mix(d0, d1, factor);
|
||||
o_color = vec4(d, 0.0, 0.0, 1.0);
|
||||
}
|
||||
10
orx-jumpflood/src/shaders/glsl/sdf-onion.frag
Normal file
10
orx-jumpflood/src/shaders/glsl/sdf-onion.frag
Normal file
@@ -0,0 +1,10 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform float radius;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float d0 = texture(tex0, v_texCoord0).r;
|
||||
o_color = vec4(abs(d0)- radius, 0.0, 0.0, 1.0);
|
||||
}
|
||||
10
orx-jumpflood/src/shaders/glsl/sdf-round.frag
Normal file
10
orx-jumpflood/src/shaders/glsl/sdf-round.frag
Normal file
@@ -0,0 +1,10 @@
|
||||
uniform sampler2D tex0; // signed distance
|
||||
uniform float radius;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float d0 = texture(tex0, v_texCoord0).r - radius;
|
||||
o_color = vec4(d0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
17
orx-jumpflood/src/shaders/glsl/sdf-smooth-difference.frag
Normal file
17
orx-jumpflood/src/shaders/glsl/sdf-smooth-difference.frag
Normal file
@@ -0,0 +1,17 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform sampler2D tex1;// signed distance
|
||||
uniform float radius;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
float opSmoothDifference( float d1, float d2, float k ) {
|
||||
float h = clamp( 0.5 - 0.5*(d2+d1)/k, 0.0, 1.0 );
|
||||
return mix( d2, -d1, h ) + k*h*(1.0-h); }
|
||||
|
||||
|
||||
void main() {
|
||||
float d0 = texture(tex0, v_texCoord0).r;
|
||||
float d1 = texture(tex1, v_texCoord0).r;
|
||||
o_color = vec4(opSmoothDifference(d0, d1, radius), 0.0, 0.0, 1.0);
|
||||
}
|
||||
17
orx-jumpflood/src/shaders/glsl/sdf-smooth-intersection.frag
Normal file
17
orx-jumpflood/src/shaders/glsl/sdf-smooth-intersection.frag
Normal file
@@ -0,0 +1,17 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform sampler2D tex1;// signed distance
|
||||
uniform float radius;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
float opSmoothIntersection(float d1, float d2, float k) {
|
||||
float h = clamp(0.5 - 0.5*(d2-d1)/k, 0.0, 1.0);
|
||||
return mix(d2, d1, h) + k*h*(1.0-h); }
|
||||
|
||||
|
||||
void main() {
|
||||
float d0 = texture(tex0, v_texCoord0).r;
|
||||
float d1 = texture(tex1, v_texCoord0).r;
|
||||
o_color = vec4(opSmoothIntersection(d0, d1, radius), 0.0, 0.0, 1.0);
|
||||
}
|
||||
17
orx-jumpflood/src/shaders/glsl/sdf-smooth-union.frag
Normal file
17
orx-jumpflood/src/shaders/glsl/sdf-smooth-union.frag
Normal file
@@ -0,0 +1,17 @@
|
||||
uniform sampler2D tex0; // signed distance
|
||||
uniform sampler2D tex1; // signed distance
|
||||
uniform float radius;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
float opSmoothUnion(float d1, float d2, float k) {
|
||||
float h = clamp(0.5 + 0.5*(d2-d1)/k, 0.0, 1.0);
|
||||
return mix(d2, d1, h) - k*h*(1.0-h);
|
||||
}
|
||||
|
||||
void main() {
|
||||
float d0 = texture(tex0, v_texCoord0).r;
|
||||
float d1 = texture(tex1, v_texCoord0).r;
|
||||
o_color = vec4(opSmoothUnion(d0, d1, radius), 0.0, 0.0, 1.0);
|
||||
}
|
||||
22
orx-jumpflood/src/shaders/glsl/sdf-stroke-fill.frag
Normal file
22
orx-jumpflood/src/shaders/glsl/sdf-stroke-fill.frag
Normal file
@@ -0,0 +1,22 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform float radius;
|
||||
|
||||
uniform vec4 strokeColor;
|
||||
uniform float strokeWeight;
|
||||
uniform float strokeFeather;
|
||||
|
||||
uniform float fillFeather;
|
||||
uniform vec4 fillColor;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float d = texture(tex0, v_texCoord0).r;
|
||||
float strokeFactor = smoothstep(strokeWeight + strokeFeather, strokeWeight, abs(d));
|
||||
float fillFactor = smoothstep(0.0, fillFeather, -d);
|
||||
|
||||
vec4 fc = (fillColor * fillColor.a) * fillFactor;
|
||||
fc = fc * (1.0 - strokeFactor) + strokeFactor * (strokeColor * strokeColor.a);
|
||||
o_color = fc;
|
||||
}
|
||||
109
orx-jumpflood/src/shaders/glsl/shape-sdf.frag
Normal file
109
orx-jumpflood/src/shaders/glsl/shape-sdf.frag
Normal file
@@ -0,0 +1,109 @@
|
||||
in vec2 v_texCoord0;
|
||||
uniform float iTime;
|
||||
out vec4 o_color;
|
||||
|
||||
uniform bool useUV;
|
||||
uniform bool rectify;
|
||||
|
||||
uniform mat4 modelViewMatrixInverse;
|
||||
|
||||
uniform samplerBuffer toBuffer;
|
||||
uniform samplerBuffer fromBuffer;
|
||||
uniform int segmentCount;
|
||||
uniform vec2 targetSize;
|
||||
|
||||
uniform sampler2D tex0; // uv-map
|
||||
|
||||
float isLeft( vec2 P0, vec2 P1, vec2 P2 ) {
|
||||
return ( (P1.x - P0.x) * (P2.y - P0.y)
|
||||
- (P2.x - P0.x) * (P1.y - P0.y) );
|
||||
}
|
||||
|
||||
float length_squared( vec2 v, vec2 w ) {
|
||||
return dot(w-v, w-v);
|
||||
}
|
||||
|
||||
int winding_number( vec2 v, vec2 w, vec2 p ) {
|
||||
if (v.y <= p.y) { // start y <= P.y
|
||||
if (w.y > p.y) // an upward crossing
|
||||
if (isLeft( v, w, p) > 0.0) // P left of edge
|
||||
return 1; // ++wn; // have a valid up intersect
|
||||
}
|
||||
else { // start y > P.y (no test needed)
|
||||
if (w.y <= p.y) // a downward crossing
|
||||
if (isLeft( v,w,p) < 0.0) // P right of edge
|
||||
return -1; //--wn; // have a valid down intersect
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float minimum_distance(vec2 v, vec2 w, vec2 p) {
|
||||
// Return minimum distance between line segment vw and point p
|
||||
float l2 = length_squared(v, w); // i.e. |w-v|^2 - avoid a sqrt
|
||||
if (l2 == 0.0) return distance(p, v); // v == w case
|
||||
// Consider the line extending the segment, parameterized as v + t (w - v).
|
||||
// We find projection of point p onto the line.
|
||||
// It falls where t = [(p-v) . (w-v)] / |w-v|^2
|
||||
// We clamp t from [0,1] to handle points outside the segment vw.
|
||||
float t = max(0.0, min(1.0, dot(p - v, w - v) / l2));
|
||||
vec2 projection = v + t * (w - v); // Projection falls on the segment
|
||||
return distance(p, projection);
|
||||
}
|
||||
|
||||
vec3 minimum_distance_and_perpendicular(vec4 v, vec4 w, vec2 p) {
|
||||
// Return minimum distance between line segment vw and point p
|
||||
float l2 = length_squared(v.xy, w.xy); // i.e. |w-v|^2 - avoid a sqrt
|
||||
if (l2 == 0.0) return vec3(distance(p, v.xy), v.z, v.w); // v == w case
|
||||
// Consider the line extending the segment, parameterized as v + t (w - v).
|
||||
// We find projection of point p onto the line.
|
||||
// It falls where t = [(p-v) . (w-v)] / |w-v|^2
|
||||
// We clamp t from [0,1] to handle points outside the segment vw.
|
||||
float t = max(0.0, min(1.0, dot(p - v.xy, w.xy - v.xy) / l2));
|
||||
vec3 projection = v.xyz + t * (w.xyz - v.xyz); // Projection falls on the segment
|
||||
return vec3(distance(p.xy, projection.xy), projection.z, v.w);
|
||||
}
|
||||
|
||||
float shapeDistance(vec2 uv, out float perpDistOut, out float contourLengthOut ) {
|
||||
float mindist = 10E10;
|
||||
float perpdist = 0.0;
|
||||
float contourLength = 0.0;
|
||||
int windingNr = 0;
|
||||
for (int i = 0; i < segmentCount; i++) {
|
||||
vec4 from = texelFetch(fromBuffer, i);
|
||||
vec4 to = texelFetch(toBuffer, i);
|
||||
vec3 distline_and_perp = minimum_distance_and_perpendicular(from, to, uv.xy);
|
||||
windingNr += winding_number( from.xy, to.xy, uv.xy );
|
||||
float distline = distline_and_perp.x;
|
||||
if (abs(distline) <= mindist) {
|
||||
mindist = distline;
|
||||
perpdist = distline_and_perp.y;
|
||||
contourLength = distline_and_perp.z;
|
||||
}
|
||||
}
|
||||
float signedDistance = mindist * (windingNr==0 ? 1.0 : -1.0);
|
||||
contourLengthOut = contourLength;
|
||||
perpDistOut = perpdist;
|
||||
return signedDistance;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = v_texCoord0;
|
||||
|
||||
vec2 fixDistance = vec2(1.0);
|
||||
|
||||
if (useUV) {
|
||||
vec2 o = 0.5 / vec2(textureSize(tex0, 0));
|
||||
uv = texture(tex0, v_texCoord0 + o).xy;
|
||||
if (rectify) {
|
||||
fixDistance = (fwidth(uv))*vec2(1280.0, 720.0);
|
||||
}
|
||||
}
|
||||
uv.y = 1.0 - uv.y;
|
||||
uv *= targetSize;
|
||||
uv = (modelViewMatrixInverse * vec4(uv, 0.0, 1.0)).xy;
|
||||
|
||||
float perpdist;
|
||||
float contourLength;
|
||||
float signedDistance = shapeDistance(uv, perpdist, contourLength);
|
||||
o_color = vec4(signedDistance / length(fixDistance), perpdist/contourLength, contourLength, 1.0);
|
||||
}
|
||||
42
orx-jumpflood/src/shaders/glsl/skeleton.frag
Normal file
42
orx-jumpflood/src/shaders/glsl/skeleton.frag
Normal file
@@ -0,0 +1,42 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform vec4 skeletonColor;
|
||||
uniform vec4 backgroundColor;
|
||||
uniform vec4 foregroundColor;
|
||||
uniform float angleTreshold;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float centerDistance = texture(tex0, v_texCoord0).r;
|
||||
vec2 step = 1.0 / vec2(textureSize(tex0, 0));
|
||||
|
||||
float minDistance = 1000.0;
|
||||
|
||||
float nd = texture(tex0, v_texCoord0 + step * vec2(0.0, -1.0)).r;
|
||||
float ed = texture(tex0, v_texCoord0 + step * vec2(1.0, 0.0)).r;
|
||||
float wd = texture(tex0, v_texCoord0 + step * vec2(-1.0, 0.0)).r;
|
||||
float sd = texture(tex0, v_texCoord0 + step * vec2(0.0, 1.0)).r;
|
||||
|
||||
float nd2 = texture(tex0, v_texCoord0 + step * vec2(-1.0, -1.0)).r;
|
||||
float ed2 = texture(tex0, v_texCoord0 + step * vec2(-1.0, 1.0)).r;
|
||||
float wd2 = texture(tex0, v_texCoord0 + step * vec2(1.0, -1.0)).r;
|
||||
float sd2 = texture(tex0, v_texCoord0 + step * vec2(1.0, 1.0)).r;
|
||||
|
||||
float r = -centerDistance * 8.0 + nd + ed + wd + sd + nd2 + ed2 + wd2 + sd2;
|
||||
|
||||
vec4 fc = vec4(0.0);
|
||||
|
||||
if (centerDistance < 0.0) {
|
||||
fc += foregroundColor * foregroundColor.a;
|
||||
} else {
|
||||
fc += backgroundColor * backgroundColor.a;
|
||||
}
|
||||
|
||||
if (r > 0.0 && centerDistance < 0.0) {
|
||||
fc = fc * (1.0 - skeletonColor.a) + (skeletonColor * skeletonColor.a);
|
||||
}
|
||||
|
||||
o_color = fc;
|
||||
}
|
||||
46
orx-jumpflood/src/shaders/glsl/straight-skeleton.frag
Normal file
46
orx-jumpflood/src/shaders/glsl/straight-skeleton.frag
Normal file
@@ -0,0 +1,46 @@
|
||||
uniform sampler2D tex0;// signed distance
|
||||
uniform vec4 skeletonColor;
|
||||
uniform vec4 backgroundColor;
|
||||
uniform vec4 foregroundColor;
|
||||
uniform float angleTreshold;
|
||||
|
||||
in vec2 v_texCoord0;
|
||||
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
vec4 ct = texture(tex0, v_texCoord0);
|
||||
vec2 cd = normalize(ct.xy);
|
||||
vec2 step = 1.0 / vec2(textureSize(tex0, 0));
|
||||
|
||||
float minDistance = 1000.0;
|
||||
|
||||
vec4 nt = texture(tex0, v_texCoord0 + step * vec2(0.0, -1.0));
|
||||
vec2 nd = normalize(nt.xy);
|
||||
vec4 et = texture(tex0, v_texCoord0 + step * vec2(1.0, 0.0));
|
||||
vec2 ed = normalize(et.xy);
|
||||
vec4 wt = texture(tex0, v_texCoord0 + step * vec2(-1.0, 0.0));
|
||||
vec2 wd = normalize(wt.xy);
|
||||
vec4 st = texture(tex0, v_texCoord0 + step * vec2(0.0, 1.0));
|
||||
vec2 sd = normalize(st.xy);
|
||||
|
||||
float d0 = dot(cd, nd);
|
||||
float d1 = dot(cd, ed);
|
||||
float d2 = dot(cd, wd);
|
||||
float d3 = dot(cd, sd);
|
||||
|
||||
float r = (d0+d1+d2+d3);
|
||||
|
||||
vec4 fc = vec4(0.0);
|
||||
|
||||
if (ct.z > 0.0) {
|
||||
fc += foregroundColor * foregroundColor.a;
|
||||
} else {
|
||||
fc += backgroundColor * backgroundColor.a;
|
||||
}
|
||||
|
||||
if ((d0 < angleTreshold || d1 < angleTreshold || d2 < angleTreshold || d3 < angleTreshold) && ct.z > 0.0 && length(ct.xy) > 4) {
|
||||
fc = fc * (1.0 - skeletonColor.a) + (skeletonColor * skeletonColor.a);
|
||||
}
|
||||
o_color = fc;
|
||||
}
|
||||
9
orx-jumpflood/src/shaders/glsl/threshold.frag
Normal file
9
orx-jumpflood/src/shaders/glsl/threshold.frag
Normal file
@@ -0,0 +1,9 @@
|
||||
uniform sampler2D tex0;
|
||||
in vec2 v_texCoord0;
|
||||
uniform float threshold;
|
||||
out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
float ref = step(threshold , dot( vec3(1.0/3.0), texture(tex0, v_texCoord0).rgb ));
|
||||
o_color = vec4(ref, ref, ref, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user