ported some glsl effects to gles

This commit is contained in:
itsmattkc
2019-03-27 01:05:05 +11:00
parent fe9eb8754f
commit ad1013e60b
28 changed files with 112 additions and 188 deletions
+13 -1
View File
@@ -307,6 +307,8 @@ Effect::Effect(Clip* c, const EffectMeta *em) :
shader_frag_path_ = attr.value().toString();
} else if (attr.name() == "iterations") {
setIterations(attr.value().toInt());
} else if (attr.name() == "function") {
shader_function_name_ = attr.value().toString();
}
}
}/* else if (reader.name() == "superimpose" && reader.isStartElement()) {
@@ -757,7 +759,17 @@ void Effect::open() {
}
if (!frag_shader_str.isEmpty()) {
shader_program_ = olive::shader::GetPipeline("process", frag_shader_str);
QString shader_func;
if (!shader_function_name_.isEmpty()) {
shader_func = shader_function_name_;
} else {
shader_func = "process";
}
shader_program_ = olive::shader::GetPipeline(shader_func, frag_shader_str);
}
/*
+1
View File
@@ -226,6 +226,7 @@ protected:
QOpenGLShaderProgramPtr shader_program_;
QString shader_vert_path_;
QString shader_frag_path_;
QString shader_function_name_;
// superimpose effect
QImage img;
+8 -14
View File
@@ -1,16 +1,10 @@
#version 110
uniform sampler2D image;
uniform float radius;
uniform vec2 resolution;
uniform bool horiz_blur;
uniform bool vert_blur;
uniform int iteration;
uniform vec2 resolution;
varying vec2 vTexCoord;
void main(void) {
vec4 process(vec4 col) {
float rad = ceil(radius);
float divider = 1.0 / rad;
@@ -19,15 +13,15 @@ void main(void) {
if (iteration == 0 && horiz_blur && !radius_is_zero) {
for (float x=-rad+0.5;x<=rad;x+=2.0) {
color += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y))/resolution)*(divider);
color += texture2D(texture, vec2(gl_FragCoord.x+x, gl_FragCoord.y)/resolution)*(divider);
}
gl_FragColor = color;
return color;
} else if (iteration == 1 && vert_blur && !radius_is_zero) {
for (float x=-rad+0.5;x<=rad;x+=2.0) {
color += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+x))/resolution)*(divider);
color += texture2D(texture, vec2(gl_FragCoord.x, gl_FragCoord.y+x)/resolution)*(divider);
}
gl_FragColor = color;
return color;
} else {
gl_FragColor = texture2D(image, vTexCoord);
return col;
}
}
}
+1 -1
View File
@@ -9,5 +9,5 @@
<row name="Vertical">
<field type="bool" default="1" id="vert_blur"/>
</row>
<shader vert="common.vert" frag="boxblur.frag" iterations="2"/>
<shader vert="common.vert" frag="boxblur.frag" iterations="2" />
</effect>
+7 -12
View File
@@ -1,22 +1,17 @@
#version 110
uniform vec2 resolution;
uniform sampler2D tex;
varying vec2 vTexCoord;
uniform float red_amount;
uniform float green_amount;
uniform float blue_amount;
void main(void) {
uniform vec2 resolution;
vec4 process(vec4 col) {
vec2 rOffset = vec2(red_amount*0.01)/resolution;
vec2 gOffset = vec2(green_amount*0.01)/resolution;
vec2 bOffset = vec2(blue_amount*0.01)/resolution;
vec4 rValue = texture2D(tex, vTexCoord - rOffset);
vec4 gValue = texture2D(tex, vTexCoord - gOffset);
vec4 bValue = texture2D(tex, vTexCoord - bOffset);
vec4 rValue = texture2D(texture, v_texcoord - rOffset);
vec4 gValue = texture2D(texture, v_texcoord - gOffset);
vec4 bValue = texture2D(texture, v_texcoord - bOffset);
gl_FragColor = vec4(rValue.r, gValue.g, bValue.b, texture2D(tex, vTexCoord).a);
return vec4(rValue.r, gValue.g, bValue.b, col.a);
}
+8 -18
View File
@@ -1,5 +1,3 @@
#version 110
uniform float left;
uniform float top;
uniform float right;
@@ -7,28 +5,20 @@ uniform float bottom;
uniform float feather;
uniform mediump float amount_val;
uniform sampler2D myTexture;
varying vec2 vTexCoord;
void main(void) {
vec4 textureColor = texture2D(myTexture, vec2(vTexCoord.x, vTexCoord.y));
float alpha = textureColor.a;
vec4 process(vec4 col) {
float alpha = col.a;
if (feather == 0.0) {
if (vTexCoord.x < (left*0.01) || vTexCoord.y < (top*0.01) || vTexCoord.x > (1.0-(right*0.01)) || vTexCoord.y > (1.0-(bottom*0.01))) {
if (v_texcoord.x < (left*0.01) || v_texcoord.y < (top*0.01) || v_texcoord.x > (1.0-(right*0.01)) || v_texcoord.y > (1.0-(bottom*0.01))) {
alpha = 0.0;
}
} else {
float f = pow(2.0, 10.0-(feather*0.1));
if (left > 0.0) alpha = alpha * clamp(((vTexCoord.x+(0.5/f))-(left*0.01))*f, 0.0, 1.0); // left
if (top > 0.0) alpha = alpha * clamp(((vTexCoord.y+(0.5/f))-(top*0.01))*f, 0.0, 1.0); // top
if (right > 0.0) alpha = alpha * clamp((((1.0-vTexCoord.x)+(0.5/f))-(right*0.01))*f, 0.0, 1.0); // right
if (bottom > 0.0) alpha = alpha * clamp((((1.0-vTexCoord.y)+(0.5/f))-(bottom*0.01))*f, 0.0, 1.0); // bottom
if (left > 0.0) alpha = alpha * clamp(((v_texcoord.x+(0.5/f))-(left*0.01))*f, 0.0, 1.0); // left
if (top > 0.0) alpha = alpha * clamp(((v_texcoord.y+(0.5/f))-(top*0.01))*f, 0.0, 1.0); // top
if (right > 0.0) alpha = alpha * clamp((((1.0-v_texcoord.x)+(0.5/f))-(right*0.01))*f, 0.0, 1.0); // right
if (bottom > 0.0) alpha = alpha * clamp((((1.0-v_texcoord.y)+(0.5/f))-(bottom*0.01))*f, 0.0, 1.0); // bottom
}
gl_FragColor = vec4(
textureColor.r*alpha,
textureColor.g*alpha,
textureColor.b*alpha,
alpha
);
return vec4(col.rgb*alpha, alpha);
}
+4 -8
View File
@@ -1,15 +1,11 @@
#version 110
#define M_PI 3.1415926535897932384626433832795
uniform sampler2D image;
uniform float angle; // degrees
uniform float length;
uniform vec2 resolution;
void main(void) {
vec4 process(vec4 col) {
if (length > 0.0) {
float ceillen = ceil(length);
float radians = (angle*M_PI)/180.0;
@@ -21,10 +17,10 @@ void main(void) {
for (float i=-ceillen+0.5;i<=ceillen;i+=2.0) {
float y = sin_angle * i;
float x = cos_angle * i;
color += texture2D(image, vec2(gl_FragCoord.x+x, gl_FragCoord.y+y)/resolution)*(divider);
color += texture2D(texture, vec2(gl_FragCoord.x+x, gl_FragCoord.y+y)/resolution)*(divider);
}
gl_FragColor = color;
return color;
} else {
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution);
return col;
}
}
+7
View File
@@ -0,0 +1,7 @@
uniform float amount;
vec4 process(vec4 col) {
float amount_val = amount * 0.01;
vec3 color = col.rgb+((vec3(1.0)-col.rgb-col.rgb)*vec3(amount_val));
return vec4(color, col.a);
}
@@ -1,19 +1,13 @@
#version 110
uniform sampler2D sceneTex; // 0
uniform float gamma_cent; // 0.6
uniform float numColors; // 8.0
varying vec2 vTexCoord;
void main() {
vec4 process(vec4 color) {
float gamma = gamma_cent*0.01;
vec4 color = texture2D(sceneTex, vTexCoord);
vec3 c = color.rgb;
c = pow(c, vec3(gamma, gamma, gamma));
c = c * numColors;
c = floor(c);
c = c / numColors;
c = pow(c, vec3(1.0/gamma));
gl_FragColor = vec4(c, color.a);
return vec4(c, color.a);
}
@@ -0,0 +1,15 @@
uniform float amount;
uniform vec2 resolution; // screen resolution
vec4 process(vec4 col) {
float alpha = texture2D(texture, v_texcoord)[3];
vec3 p = gl_FragCoord.xyz/vec3(resolution, 1.0)-.5;
vec4 color = texture2D(texture,.5+(p.xy*=.992));
vec3 o = color.rgb;
for (float i=0.;i<amount;i++) {
p.z += pow(max(0.,.5-length(color.rg)),2.)*exp(-i*.08);
}
return vec4(o*o+p.z, alpha);
}
+6 -13
View File
@@ -1,18 +1,11 @@
#version 110
#define M_PI 3.1415926535897932384626433832795
uniform sampler2D image;
// uniform float radius;
uniform float sigma;
uniform vec2 resolution;
uniform bool horiz_blur;
uniform bool vert_blur;
uniform int iteration;
varying vec2 vTexCoord;
float gaussian(float x, float sigma) {
return (1.0/(sigma*sqrt(2.0*M_PI)))*exp(-0.5*pow(x/sigma, 2.0));
}
@@ -21,7 +14,7 @@ float gaussian2(float x, float y, float sigma) {
return (1.0/(pow(sigma, 2.0)*2.0*M_PI))*exp(-0.5*((pow(x, 2.0) + pow(y, 2.0))/pow(sigma, 2.0)));
}
void main(void) {
vec4 process(vec4 col) {
float rad = ceil(sigma);
float sum = 0.0;
@@ -39,16 +32,16 @@ void main(void) {
if (iteration == 0 && horiz_blur && !radius_is_zero) {
for (float x=-rad+0.5;x<=rad;x+=2.0) {
float weight = (gaussian2(x, 0.0, sigma)/sum);
color += texture2D(image, (vec2(gl_FragCoord.x+x, gl_FragCoord.y))/resolution)*(weight);
color += texture2D(texture, vec2(gl_FragCoord.x+x, gl_FragCoord.y)/resolution)*(weight);
}
gl_FragColor = color;
return color;
} else if (iteration == 1 && vert_blur && !radius_is_zero) {
for (float x=-rad+0.5;x<=rad;x+=2.0) {
float weight = (gaussian2(0.0, x, sigma)/sum);
color += texture2D(image, (vec2(gl_FragCoord.x, gl_FragCoord.y+x))/resolution)*(weight);
color += texture2D(texture, vec2(gl_FragCoord.x, gl_FragCoord.y+x)/resolution)*(weight);
}
gl_FragColor = color;
return color;
} else {
gl_FragColor = texture2D(image, vTexCoord);
return col;
}
}
-13
View File
@@ -1,13 +0,0 @@
#version 110
uniform float amount;
uniform sampler2D myTexture;
varying vec2 vTexCoord;
void main(void) {
vec4 textureColor = texture2D(myTexture, vTexCoord);
float amount_val = amount * 0.01;
vec3 col = textureColor.rgb+((vec3(1.0)-textureColor.rgb-textureColor.rgb)*vec3(amount_val));
gl_FragColor = vec4(col, textureColor.a);
}
+5 -19
View File
@@ -1,5 +1,3 @@
#version 110
uniform vec2 resolution;
uniform float time;
@@ -7,9 +5,6 @@ uniform float amount;
uniform bool color;
uniform bool blend;
uniform sampler2D myTexture;
varying vec2 vTexCoord;
// precision lowp float;
float PHI = 1.61803398874989484820459 * 00000.1; // Golden Ratio
@@ -20,28 +15,19 @@ float gold_noise(vec2 coordinate, float seed){
return fract(tan(distance(coordinate*(seed+PHI), vec2(PHI, PI)))*SQ2)*(amount*0.01);
}
void main(void) {
vec4 process(vec4 col) {
vec3 noise;
if (color) {
noise = vec3(gold_noise(vTexCoord, time + 42069.0), gold_noise(vTexCoord, time + 69220.0), gold_noise(vTexCoord, time + 1337.0));
noise = vec3(gold_noise(v_texcoord, time + 42069.0), gold_noise(v_texcoord, time + 69220.0), gold_noise(v_texcoord, time + 1337.0));
} else {
noise = vec3(gold_noise(vTexCoord, time + 69420.0));
noise = vec3(gold_noise(v_texcoord, time + 69420.0));
}
if (blend) {
noise = (noise - vec3(amount*0.005))*vec3(2.0);
vec4 textureColor = texture2D(myTexture, vec2(vTexCoord.x, vTexCoord.y));
gl_FragColor = vec4(textureColor.rgb+noise, textureColor.a);
return vec4(col.rgb+noise, col.a);
} else {
gl_FragColor = vec4(noise, 1.0);
return vec4(noise, 1.0);
}
}
/*void main(void) {
vec4 textureColor = texture2D(myTexture, vec2(vTexCoord.x, vTexCoord.y));
textureColor.r += gold_noise(resolution);
textureColor.g += gold_noise(resolution);
textureColor.b += gold_noise(resolution);
gl_FragColor = textureColor;
}*/
+4 -8
View File
@@ -1,20 +1,16 @@
#version 110
varying vec2 vTexCoord;
uniform sampler2D texture;
uniform float pixels_x;
uniform float pixels_y;
uniform bool bypass;
void main(void) {
vec4 process(vec4 col) {
if (bypass) {
gl_FragColor = texture2D(texture, vTexCoord);
return col;
} else {
vec2 p = vTexCoord;
vec2 p = v_texcoord;
p.x -= mod(p.x, 1.0 / pixels_x);
p.y -= mod(p.y, 1.0 / pixels_y);
gl_FragColor = texture2D(texture, p);
return texture2D(texture, p);
}
}
+4 -7
View File
@@ -1,15 +1,12 @@
#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) {
vec4 process(vec4 col) {
if (radius > 0.0) {
vec2 distance = vec2((gl_FragCoord.x - (resolution.x/2.0) - center_x), (gl_FragCoord.y - (resolution.y/2.0) - center_y));
@@ -28,10 +25,10 @@ void main(void) {
for (float i=-limit+0.5;i<=limit;i+=2.0) {
float y = sin_angle * i;
float x = cos_angle * i;
color += texture2D(image, vec2(gl_FragCoord.x+x, gl_FragCoord.y+y)/resolution)*(divider);
color += texture2D(texture, vec2(gl_FragCoord.x+x, gl_FragCoord.y+y)/resolution)*(divider);
}
gl_FragColor = color;
return color;
} else {
gl_FragColor = texture2D(image, gl_FragCoord.xy/resolution);
return col;
}
}
+4 -9
View File
@@ -1,7 +1,3 @@
#version 110
varying vec2 vTexCoord;
uniform float speed;
uniform float intensity;
uniform float frequency;
@@ -12,10 +8,9 @@ uniform bool stretch;
uniform vec2 resolution; // Screen resolution
uniform float time; // time in seconds
uniform sampler2D tex0; // scene buffer
void main(void) {
vec2 texCoord = vTexCoord;
vec4 process(vec4 col) {
vec2 texCoord = v_texcoord;
vec2 center = vec2(1.0);
if (!stretch) {
@@ -29,6 +24,6 @@ void main(void) {
vec2 p = 2.0 * texCoord - center;
float len = length(p);
vec2 uv = vTexCoord + (p/len)*cos((frequency*0.01)*(len*12.0-real_time*(speed*0.05)))*(intensity*0.0005);
gl_FragColor = texture2D(tex0,uv);
vec2 uv = v_texcoord + (p/len)*cos((frequency*0.01)*(len*12.0-real_time*(speed*0.05)))*(intensity*0.0005);
return texture2D(texture, uv);
}
+6 -11
View File
@@ -1,9 +1,4 @@
#version 110
varying vec2 vTexCoord;
uniform vec2 resolution; // Screen resolution
uniform sampler2D tex0; // scene buffer
uniform float xoff;
uniform float yoff;
@@ -12,8 +7,8 @@ uniform bool tile;
uniform bool hide_edges;
uniform bool stretch;
void main(void) {
vec2 texCoord = vTexCoord;
vec4 process(vec4 col) {
vec2 texCoord = v_texcoord;
vec2 offset = vec2(1.0);
@@ -28,7 +23,7 @@ void main(void) {
}
vec2 p = 2.0 * texCoord - offset;
vec2 adj_tc = 2.0 * vTexCoord - 1.0;
vec2 adj_tc = 2.0 * v_texcoord - 1.0;
float r = dot(p,p);
if (r > 1.0) discard;
float f = (1.0-sqrt(1.0-r))/(r);
@@ -39,7 +34,7 @@ void main(void) {
uv.x = mod(uv.x, 1.0);
uv.y = mod(uv.y, 1.0);
} else if (hide_edges && (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)) {
discard;
return vec4(0.0);
}
gl_FragColor = vec4(texture2D(tex0,uv));
}
return vec4(texture2D(texture,uv));
}
+3 -9
View File
@@ -1,5 +1,3 @@
#version 110
// Swirl effect parameters
uniform float radius;
uniform float angle;
@@ -7,13 +5,10 @@ uniform float center_x;
uniform float center_y;
uniform vec2 resolution;
uniform sampler2D myTexture;
varying vec2 vTexCoord;
void main(void) {
vec4 process(vec4 col) {
vec2 center = vec2((resolution.x*0.5)+center_x, (resolution.y*0.5)+center_y);
vec2 uv = vTexCoord.st;
vec2 uv = v_texcoord.st;
vec2 tc = uv * resolution;
tc -= center;
@@ -26,6 +21,5 @@ void main(void) {
tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
}
tc += center;
vec3 color = texture2D(myTexture, tc / resolution).rgb;
gl_FragColor = vec4(color, 1.0);
return texture2D(texture, tc / resolution);
}
-19
View File
@@ -1,19 +0,0 @@
#version 110
uniform float amount;
uniform sampler2D tex0;
uniform vec2 resolution; // screen resolution
varying vec2 vTexCoord;
#define T texture2D(tex0,.5+(p.xy*=.992))
void main() {
float alpha = texture2D(tex0, vTexCoord)[3];
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, alpha);
}
+7 -18
View File
@@ -1,32 +1,21 @@
#version 110
uniform float frequency;
uniform float intensity;
uniform float evolution;
uniform bool vertical;
uniform sampler2D myTexture;
varying vec2 vTexCoord;
void main(void) {
float x = vTexCoord.x;
float y = vTexCoord.y;
vec4 process(vec4 col) {
float x = v_texcoord.x;
float y = v_texcoord.y;
if (vertical) {
x -= sin((vTexCoord.y-(evolution*0.01))*frequency)*intensity*0.01;
x -= sin((v_texcoord.y-(evolution*0.01))*frequency)*intensity*0.01;
} else {
y -= sin((vTexCoord.x-(evolution*0.01))*frequency)*intensity*0.01;
y -= sin((v_texcoord.x-(evolution*0.01))*frequency)*intensity*0.01;
}
if (y < 0.0 || y > 1.0 || x < 0.0 || x > 1.0) {
discard;
return vec4(0.0);
} else {
vec4 textureColor = texture2D(myTexture, vec2(x, y));
gl_FragColor = vec4(
textureColor.r,
textureColor.g,
textureColor.b,
textureColor.a
);
return texture2D(texture, vec2(x, y));
}
}
+1
View File
@@ -1115,6 +1115,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only,
stream.writeAttribute("speed", QString::number(f->speed));
stream.writeAttribute("alphapremul", QString::number(f->alpha_is_associated));
stream.writeAttribute("startnumber", QString::number(f->start_number));
stream.writeAttribute("colorspace", f->Colorspace());
stream.writeAttribute("proxy", QString::number(f->proxy));
stream.writeAttribute("proxypath", f->proxy_path);
+2
View File
@@ -356,6 +356,8 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
f->proxy_path = attr.value().toString();
} else if (attr.name() == "startnumber") {
f->start_number = attr.value().toInt();
} else if (attr.name() == "colorspace") {
f->SetColorspace(attr.value().toString());
}
}
+4
View File
@@ -573,6 +573,10 @@ bool Clip::Retrieve()
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// set texture wrapping to clamp
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// queue an allocation ahead
allocate_data = true;