added effects and fixed some crashes

This commit is contained in:
itsmattkc
2018-11-15 21:02:08 +11:00
parent 0e924caf8e
commit f007f39dd2
17 changed files with 414 additions and 111 deletions
+23 -23
View File
@@ -1,31 +1,31 @@
#version 110
#version 120
uniform sampler2D tex0;
varying vec4 vTexCoord;
const float PI = 3.1415926535;
uniform vec2 resolution;
uniform float amount;
uniform float xoff;
uniform float yoff;
uniform sampler2D myTexture;
varying vec2 vTexCoord;
vec2 distort(vec2 p, vec2 offset) {
float theta = atan(p.y, p.x);
float radius = length(p);
radius = pow(radius, (1.0+amount*0.01));
p.x = radius * cos(theta) + offset.x;
p.y = radius * sin(theta) + offset.y;
return 0.5 * (p + 1.0);
}
void main(void) {
float x = vTexCoord.x;
float y = vTexCoord.y;
float r = sqrt(pow(x - 0.5, 2.0) + pow(y - 0.5, 2.0));
float a = atan(y - 0.5, x - 0.5);
float rn = pow(r, (amount*0.1))/0.5;
//float a = atan(x - 0.5, y - 0.5);
x = rn * cos(a) + 0.5;
y = rn * sin(a) + 0.5;
if (y < 0.0 || y > 1.0 || x < 0.0 || x > 1.0) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
vec2 offset = vec2(xoff/resolution.x, yoff/resolution.y);
vec2 xy = 2.0 * vTexCoord.xy - 1.0 - offset;
vec2 uv;
float d = length(xy);
uv = distort(xy, offset);
if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) {
gl_FragColor = texture2D(tex0, uv);
} else {
vec4 textureColor = texture2D(myTexture, vec2(x, y));
gl_FragColor = vec4(
textureColor.r,
textureColor.g,
textureColor.b,
textureColor.a
);
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
}
}
+5 -1
View File
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Bulge" category="Distort">
<row name="Amount">
<field type="double" min="0" default="25" id="amount"/>
<field type="double" default="100" id="amount"/>
</row>
<row name="Center">
<field type="double" default="0" id="xoff"/>
<field type="double" default="0" id="yoff"/>
</row>
<shader vert="common.vert" frag="bulge.frag"/>
</effect>
+4 -4
View File
@@ -24,10 +24,10 @@ void main() {
float mid_x = (c2 - c1) / (m1 - m2);
float mid_y = m1 * mid_x + c1;
float d0 = sqrt(pow(mid_x - p0.x, 2.0) + pow(mid_y - p0.y, 2.0));
float d1 = sqrt(pow(p1.x - mid_x, 2.0) + pow(mid_y - p1.y, 2.0));
float d2 = sqrt(pow(p3.x - mid_x, 2.0) + pow(p3.y - mid_y, 2.0));
float d3 = sqrt(pow(mid_x - p2.x, 2.0) + pow(p2.y - mid_y, 2.0));
float d0 = length(vec2(mid_x - p0.x, mid_y - p0.y));
float d1 = length(vec2(p1.x - mid_x, mid_y - p1.y));
float d2 = length(vec2(p3.x - mid_x, p3.y - mid_y));
float d3 = length(vec2(mid_x - p2.x, p2.y - mid_y));
float q;
+4 -4
View File
@@ -4,16 +4,16 @@
uniform sampler2D image;
uniform float angle;
uniform float angle; // degrees
uniform float length;
uniform vec2 resolution;
void main(void) {
float degrees = (angle*M_PI)/180.0;
float radians = (angle*M_PI)/180.0;
float divider = 1.0 / ((length*2.0)+1.0);
float sin_angle = sin(degrees);
float cos_angle = cos(degrees);
float sin_angle = sin(radians);
float cos_angle = cos(radians);
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution)*(divider);
for (float i=1.0;i<=length;i++) {
+27
View File
@@ -0,0 +1,27 @@
#version 120
uniform sampler2D tex0;
varying vec4 vTexCoord;
#define M_PI 3.1415926535897932384626433832795
uniform float size;
void main(void) {
float maxFactor = 2.0 - (size * 0.01);
vec2 uv;
vec2 xy = 2.0 * vTexCoord.xy - 1.0;
float d = length(xy);
if (d < (2.0-maxFactor)) {
d = length(xy * maxFactor);
float z = sqrt(1.0 - d * d);
float r = atan(d, z) / M_PI;
float phi = atan(xy.y, xy.x);
uv.x = r * cos(phi) + 0.5;
uv.y = r * sin(phi) + 0.5;
} else {
uv = vTexCoord.xy;
}
vec4 c = texture2D(tex0, uv);
gl_FragColor = c;
}
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Fisheye" category="Distort">
<row name="Size">
<field type="double" min="0" default="100" id="size"/>
</row>
<shader vert="common.vert" frag="fisheye.frag"/>
</effect>
+3 -3
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Invert" category="Color">
<effect name="Volumetric Light" category="Stylize">
<row name="Amount">
<field type="double" min="0" default="100" max="100" id="amount"/>
<field type="double" min="0" default="100" id="amount"/>
</row>
<shader vert="common.vert" frag="invert.frag"/>
<shader vert="common.vert" frag="volumetriclight.frag"/>
</effect>
+35
View File
@@ -0,0 +1,35 @@
#version 110
#define M_PI 3.1415926535897932384626433832795
uniform sampler2D image;
uniform float radius;
uniform float center_x;
uniform float center_y;
uniform vec2 resolution;
void main(void) {
vec2 distance = vec2((gl_FragCoord.x - (resolution.x/2.0) - center_x), (gl_FragCoord.y - (resolution.y/2.0) - center_y));
float angle = atan(distance.y/distance.x);
float sin_angle = sin(angle);
float cos_angle = cos(angle);
//float multiplier = pow(length((2.0 * (distance / resolution)) - 1.0), 2.0);
float multiplier = length(distance/resolution);
float limit = radius * multiplier;
float divider = 1.0 / ((floor(limit)*2.0)+1.0);
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution)*(divider);
for (float i=1.0;i<=limit;i++) {
float y = sin_angle * i;
float x = cos_angle * i;
gl_FragColor += texture2D(image, vec2(gl_FragCoord.x-x, gl_FragCoord.y-y)/resolution)*(divider);
gl_FragColor += texture2D(image, vec2(gl_FragCoord.x+x, gl_FragCoord.y+y)/resolution)*(divider);
}
}
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Radial Blur" category="Blur">
<row name="Radius">
<field type="double" min="0" default="100" id="radius"/>
</row>
<row name="Center">
<field type="double" default="0" id="center_x"/>
<field type="double" default="0" id="center_y"/>
</row>
<shader vert="common.vert" frag="radialblur.frag"/>
</effect>
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Test">
<row name="value 1">
<field type="double" default="10" id="edge_thres"/>
</row>
<row name="value 2">
<field type="double" default="10" id="edge_thres2"/>
</row>
<row name="value 3">
<field type="double" default="10" id="mouse_x_offset"/>
</row>
<row name="value 4">
<field type="double" default="10" id="aperture"/>
</row>
<row name="value 5">
<field type="double" default="10" id="xoff"/>
</row>
<row name="value 6">
<field type="double" default="10" id="yoff"/>
</row>
<shader vert="common.vert" frag="toonify.frag"/>
</effect>
+168
View File
@@ -0,0 +1,168 @@
#version 150
uniform sampler2D tex0;
in vec4 vTexCoord;
out vec4 FragColor;
uniform float colors; // 12.0
uniform float sat_levels; // 4.0
uniform float bri_levels; // 4.0
uniform float edge_thres; // 0.2;
uniform float edge_thres2; // 5.0;
vec3 RGBtoHSV( float r, float g, float b)
{
float minv, maxv, delta;
vec3 res;
minv = min(min(r, g), b);
maxv = max(max(r, g), b);
res.z = maxv; // v
delta = maxv - minv;
if( maxv != 0.0 )
res.y = delta / maxv; // s
else {
// r = g = b = 0 // s = 0, v is undefined
res.y = 0.0;
res.x = -1.0;
return res;
}
if( r == maxv )
res.x = ( g - b ) / delta; // between yellow & magenta
else if( g == maxv )
res.x = 2.0 + ( b - r ) / delta; // between cyan & yellow
else
res.x = 4.0 + ( r - g ) / delta; // between magenta & cyan
res.x = res.x * 60.0; // degrees
if( res.x < 0.0 )
res.x = res.x + 360.0;
return res;
}
vec3 HSVtoRGB(float h, float s, float v )
{
int i;
float f, p, q, t;
vec3 res;
if( s == 0.0 )
{
// achromatic (grey)
res.x = v;
res.y = v;
res.z = v;
return res;
}
h /= 60.0; // sector 0 to 5
i = int(floor( h ));
f = h - float(i); // factorial part of h
p = v * ( 1.0 - s );
q = v * ( 1.0 - s * f );
t = v * ( 1.0 - s * ( 1.0 - f ) );
switch(i)
{
case 0:
res.x = v;
res.y = t;
res.z = p;
break;
case 1:
res.x = q;
res.y = v;
res.z = p;
break;
case 2:
res.x = p;
res.y = v;
res.z = t;
break;
case 3:
res.x = p;
res.y = q;
res.z = v;
break;
case 4:
res.x = t;
res.y = p;
res.z = v;
break;
default: // case 5:
res.x = v;
res.y = p;
res.z = q;
break;
}
return res;
}
// averaged pixel intensity from 3 color channels
float avg_intensity(vec4 pix)
{
return (pix.r + pix.g + pix.b)/3.;
}
vec4 get_pixel(vec2 coords, float dx, float dy)
{
return texture(tex0,coords + vec2(dx, dy));
}
// returns pixel color
float IsEdge(in vec2 coords)
{
float dxtex = 1.0 /float(textureSize(tex0,0)) ;
float dytex = 1.0 /float(textureSize(tex0,0));
float pix[9];
int k = -1;
float delta;
// read neighboring pixel intensities
for (int i=-1; i<2; i++) {
for(int j=-1; j<2; j++) {
k++;
pix[k] = avg_intensity(get_pixel(coords,float(i)*dxtex,
float(j)*dytex));
}
}
// average color differences around neighboring pixels
delta = (abs(pix[1]-pix[7])+
abs(pix[5]-pix[3]) +
abs(pix[0]-pix[8])+
abs(pix[2]-pix[6])
)/4.;
//return clamp(5.5*delta,0.0,1.0);
return clamp(edge_thres2*delta,0.0,1.0);
}
void main() {
vec2 uv = vTexCoord.xy;
vec4 tc = vec4(1.0, 0.0, 0.0, 1.0);
vec3 colorOrg = texture(tex0, uv).rgb;
vec3 vHSV = RGBtoHSV(colorOrg.r,colorOrg.g,colorOrg.b);
// hue limiting
if (colors == 0.0) {
vHSV.y = 0.0;
} else {
float hue_divider = (360.0/colors);
vHSV.x = round(vHSV.x/hue_divider)*hue_divider;
float sat_divider = 100.0/sat_levels;
vHSV.y = round((vHSV.y*100.0)/sat_divider)*sat_divider/100.0;
}
float bri_divider = 100.0/bri_levels;
vHSV.z = round((vHSV.z*100.0)/bri_divider)*bri_divider/100.0;
float edg = IsEdge(uv);
vec3 vRGB = (edg >= (1.0-((edge_thres-1.0)*0.01)))? vec3(0.0,0.0,0.0):HSVtoRGB(vHSV.x,vHSV.y,vHSV.z);
tc = vec4(vRGB.x,vRGB.y,vRGB.z, 1);
FragColor = tc;
}
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<effect name="Toonify" category="Stylize">
<row name="Colors">
<field type="double" min="0" default="12" max="360" id="colors"/>
</row>
<row name="Saturation Levels">
<field type="double" min="0" default="4" id="sat_levels"/>
</row>
<row name="Brightness Levels">
<field type="double" min="0" default="4" id="bri_levels"/>
</row>
<row name="Edge Tolerance">
<field type="double" default="20" id="edge_thres"/>
</row>
<row name="Edge Strength">
<field type="double" default="5" id="edge_thres2"/>
</row>
<shader vert="common.vert" frag="toonify.frag"/>
</effect>
+15
View File
@@ -0,0 +1,15 @@
#version 110
uniform float amount;
uniform sampler2D tex0;
uniform vec2 resolution; // screen resolution
#define T texture2D(tex0,.5+(p.xy*=.992))
void main()
{
vec3 p = gl_FragCoord.xyz/vec3(resolution, 1.0)-.5;
vec3 o = T.rgb;
for (float i=0.;i<amount;i++)
p.z += pow(max(0.,.5-length(T.rg)),2.)*exp(-i*.08);
gl_FragColor=vec4(o*o+p.z,1);
}