Upgrade shaders from GLSL 110 to 150 (OpenGL 3.2)

This commit is contained in:
Simran Brucherseifer
2020-04-22 11:28:33 +02:00
parent 26b928597c
commit 5da9848de7
14 changed files with 208 additions and 174 deletions
+8 -6
View File
@@ -133,7 +133,7 @@ QString MathNode::ShaderFragmentCode(const NodeValueDatabase &input) const
NodeParam* tex_in = (type_a == NodeParam::kTexture) ? param_a_in_ : param_b_in_; NodeParam* tex_in = (type_a == NodeParam::kTexture) ? param_a_in_ : param_b_in_;
NodeParam* mat_in = (type_a == NodeParam::kTexture) ? param_b_in_ : param_a_in_; NodeParam* mat_in = (type_a == NodeParam::kTexture) ? param_b_in_ : param_a_in_;
operation = QStringLiteral("texture2D(%1, (vec4(ove_texcoord, 0.0, 1.0) * %2).xy)").arg(tex_in->id(), mat_in->id()); operation = QStringLiteral("texture(%1, (vec4(ove_texcoord, 0.0, 1.0) * %2).xy)").arg(tex_in->id(), mat_in->id());
} else { } else {
switch (GetOperation()) { switch (GetOperation()) {
@@ -158,15 +158,17 @@ QString MathNode::ShaderFragmentCode(const NodeValueDatabase &input) const
GetShaderVariableCall(param_b_in_->id(), type_b)); GetShaderVariableCall(param_b_in_->id(), type_b));
} }
return QStringLiteral("#version 110\n" return QStringLiteral("#version 150\n"
"\n"
"varying vec2 ove_texcoord;\n"
"\n" "\n"
"uniform %1 %3;\n" "uniform %1 %3;\n"
"uniform %2 %4;\n" "uniform %2 %4;\n"
"\n" "\n"
"in vec2 ove_texcoord;\n"
"\n"
"out vec4 fragColor;\n"
"\n"
"void main(void) {\n" "void main(void) {\n"
" gl_FragColor = %5;\n" " fragColor = %5;\n"
"}\n").arg(GetShaderUniformType(type_a), "}\n").arg(GetShaderUniformType(type_a),
GetShaderUniformType(type_b), GetShaderUniformType(type_b),
param_a_in_->id(), param_a_in_->id(),
@@ -397,7 +399,7 @@ QString MathNode::GetShaderUniformType(const NodeParam::DataType &type)
QString MathNode::GetShaderVariableCall(const QString &input_id, const NodeParam::DataType &type, const QString& coord_op) QString MathNode::GetShaderVariableCall(const QString &input_id, const NodeParam::DataType &type, const QString& coord_op)
{ {
if (type == NodeParam::kTexture) { if (type == NodeParam::kTexture) {
return QStringLiteral("texture2D(%1, ove_texcoord%2)").arg(input_id, coord_op); return QStringLiteral("texture(%1, ove_texcoord%2)").arg(input_id, coord_op);
} }
return input_id; return input_id;
+28 -25
View File
@@ -152,7 +152,7 @@ OpenGLShaderPtr OpenGLShader::CreateOCIO(QOpenGLContext* ctx,
QString OpenGLShader::CodeDefaultFragment(const QString &function_name, const QString &shader_code) QString OpenGLShader::CodeDefaultFragment(const QString &function_name, const QString &shader_code)
{ {
QString frag_code = QStringLiteral("#version 110\n" QString frag_code = QStringLiteral("#version 150\n"
"\n" "\n"
"#ifdef GL_ES\n" "#ifdef GL_ES\n"
"precision highp int;\n" "precision highp int;\n"
@@ -162,7 +162,10 @@ QString OpenGLShader::CodeDefaultFragment(const QString &function_name, const QS
"uniform sampler2D ove_maintex;\n" "uniform sampler2D ove_maintex;\n"
"uniform bool color_only;\n" "uniform bool color_only;\n"
"uniform vec4 color_only_color;\n" "uniform vec4 color_only_color;\n"
"varying vec2 ove_texcoord;\n" "\n"
"in vec2 ove_texcoord;\n"
"\n"
"out vec4 fragColor;\n"
"\n"); "\n");
// Finish the function with the main function // Finish the function with the main function
@@ -174,12 +177,12 @@ QString OpenGLShader::CodeDefaultFragment(const QString &function_name, const QS
frag_code.append(QStringLiteral("\n" frag_code.append(QStringLiteral("\n"
"void main() {\n" "void main() {\n"
" if (color_only) {\n" " if (color_only) {\n"
" gl_FragColor = color_only_color;" " fragColor = color_only_color;"
" } else {\n" " } else {\n"
" vec4 color = texture2D(ove_maintex, ove_texcoord);\n" " vec4 color = texture(ove_maintex, ove_texcoord);\n"
" gl_FragColor = color;\n" " fragColor = color;\n"
" }\n" " }\n"
"}\n")); "}\n"));
} else { } else {
@@ -193,8 +196,8 @@ QString OpenGLShader::CodeDefaultFragment(const QString &function_name, const QS
frag_code.append(QStringLiteral("\n" frag_code.append(QStringLiteral("\n"
"void main() {\n" "void main() {\n"
" vec4 color = %1(texture2D(ove_maintex, ove_texcoord));\n" " vec4 color = %1(texture(ove_maintex, ove_texcoord));\n"
" gl_FragColor = color;\n" " fragColor = color;\n"
"}\n").arg(function_name)); "}\n").arg(function_name));
} }
@@ -205,7 +208,7 @@ QString OpenGLShader::CodeDefaultFragment(const QString &function_name, const QS
QString OpenGLShader::CodeDefaultVertex() QString OpenGLShader::CodeDefaultVertex()
{ {
// Generate vertex shader // Generate vertex shader
return QStringLiteral("#version 110\n" return QStringLiteral("#version 150\n"
"\n" "\n"
"#ifdef GL_ES\n" "#ifdef GL_ES\n"
"precision highp int;\n" "precision highp int;\n"
@@ -214,41 +217,41 @@ QString OpenGLShader::CodeDefaultVertex()
"\n" "\n"
"uniform mat4 ove_mvpmat;\n" "uniform mat4 ove_mvpmat;\n"
"\n" "\n"
"attribute vec4 a_position;\n" "in vec4 a_position;\n"
"attribute vec2 a_texcoord;\n" "in vec2 a_texcoord;\n"
"\n" "\n"
"varying vec2 ove_texcoord;\n" "out vec2 ove_texcoord;\n"
"\n" "\n"
"void main() {\n" "void main() {\n"
" gl_Position = ove_mvpmat * a_position;\n" " gl_Position = ove_mvpmat * a_position;\n"
" ove_texcoord = a_texcoord;\n" " ove_texcoord = a_texcoord;\n"
"}\n"); "}\n");
} }
QString OpenGLShader::CodeAlphaDisassociate(const QString &function_name) QString OpenGLShader::CodeAlphaDisassociate(const QString &function_name)
{ {
return QStringLiteral("vec4 %1(vec4 col) {\n" return QStringLiteral("vec4 %1(vec4 col) {\n"
" if (col.a > 0.0) {\n" " if (col.a > 0.0) {\n"
" return vec4(col.rgb / col.a, col.a);" " return vec4(col.rgb / col.a, col.a);"
" }\n" " }\n"
" return col;\n" " return col;\n"
"}\n").arg(function_name); "}\n").arg(function_name);
} }
QString OpenGLShader::CodeAlphaReassociate(const QString &function_name) QString OpenGLShader::CodeAlphaReassociate(const QString &function_name)
{ {
return QStringLiteral("vec4 %1(vec4 col) {\n" return QStringLiteral("vec4 %1(vec4 col) {\n"
" if (col.a > 0.0) {\n" " if (col.a > 0.0) {\n"
" return vec4(col.rgb * col.a, col.a);" " return vec4(col.rgb * col.a, col.a);"
" }\n" " }\n"
" return col;\n" " return col;\n"
"}\n").arg(function_name); "}\n").arg(function_name);
} }
QString OpenGLShader::CodeAlphaAssociate(const QString &function_name) QString OpenGLShader::CodeAlphaAssociate(const QString &function_name)
{ {
return QStringLiteral("vec4 %1(vec4 col) {\n" return QStringLiteral("vec4 %1(vec4 col) {\n"
" return vec4(col.rgb * col.a, col.a);\n" " return vec4(col.rgb * col.a, col.a);\n"
"}\n").arg(function_name); "}\n").arg(function_name);
} }
+24 -22
View File
@@ -1,33 +1,35 @@
#version 110 #version 150
varying vec2 ove_texcoord;
uniform sampler2D base_in; uniform sampler2D base_in;
uniform sampler2D blend_in; uniform sampler2D blend_in;
uniform bool base_in_enabled; uniform bool base_in_enabled;
uniform bool blend_in_enabled; uniform bool blend_in_enabled;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
vec4 base_col = texture2D(base_in, ove_texcoord); vec4 base_col = texture(base_in, ove_texcoord);
vec4 blend_col = texture2D(blend_in, ove_texcoord); vec4 blend_col = texture(blend_in, ove_texcoord);
if (!base_in_enabled && !blend_in_enabled) { if (!base_in_enabled && !blend_in_enabled) {
gl_FragColor = vec4(0.0); fragColor = vec4(0.0);
return; return;
} }
if (!base_in_enabled) { if (!base_in_enabled) {
gl_FragColor = blend_col; fragColor = blend_col;
return; return;
} }
if (!blend_in_enabled) { if (!blend_in_enabled) {
gl_FragColor = base_col; fragColor = base_col;
return; return;
} }
base_col *= 1.0 - blend_col.a; base_col *= 1.0 - blend_col.a;
base_col += blend_col; base_col += blend_col;
gl_FragColor = base_col; fragColor = base_col;
} }
+19 -16
View File
@@ -1,8 +1,4 @@
#version 110 #version 150
uniform vec2 ove_resolution;
varying vec2 ove_texcoord;
uniform int ove_iteration;
uniform sampler2D tex_in; uniform sampler2D tex_in;
uniform int method_in; uniform int method_in;
@@ -11,6 +7,13 @@ uniform bool horiz_in;
uniform bool vert_in; uniform bool vert_in;
uniform bool repeat_edge_pixels_in; uniform bool repeat_edge_pixels_in;
uniform vec2 ove_resolution;
uniform int ove_iteration;
in vec2 ove_texcoord;
out vec4 fragColor;
// Gaussian function uses PI // Gaussian function uses PI
#define M_PI 3.1415926535897932384626433832795 #define M_PI 3.1415926535897932384626433832795
@@ -33,12 +36,12 @@ void main(void) {
if (radius_in == 0.0 if (radius_in == 0.0
|| (ove_iteration == 0 && !horiz_in) || (ove_iteration == 0 && !horiz_in)
|| (ove_iteration == 1 && !vert_in)) { || (ove_iteration == 1 && !vert_in)) {
gl_FragColor = texture2D(tex_in, ove_texcoord); fragColor = texture(tex_in, ove_texcoord);
return; return;
} }
// We only sample on hard pixels, so we don't accept decimal radii // We only sample on hard pixels, so we don't accept decimal radii
float real_radius = ceil(radius_in); float real_radius = ceil(radius_in);
vec4 composite = vec4(0.0); vec4 composite = vec4(0.0);
@@ -58,26 +61,26 @@ void main(void) {
// Use gaussian formula to calculate the weight of all pixels // Use gaussian formula to calculate the weight of all pixels
divider = 0.0; divider = 0.0;
for (float i=-real_radius+0.5;i<=real_radius;i+=2.0) { for (float i = -real_radius + 0.5; i <= real_radius; i += 2.0) {
divider += gaussian2(i, 0.0, sigma); divider += gaussian2(i, 0.0, sigma);
} }
} }
for (float i=-real_radius+0.5;i<=real_radius;i+=2.0) { for (float i = -real_radius + 0.5; i <= real_radius; i += 2.0) {
float weight; float weight;
if (method_in == METHOD_BOX_BLUR) { if (method_in == METHOD_BOX_BLUR) {
weight = divider; weight = divider;
} else if (method_in == METHOD_GAUSSIAN_BLUR) { } else if (method_in == METHOD_GAUSSIAN_BLUR) {
weight = gaussian2(i, 0.0, sigma)/divider; weight = gaussian2(i, 0.0, sigma) / divider;
} }
vec2 pixel_coord = ove_texcoord; vec2 pixel_coord = ove_texcoord;
if (ove_iteration == 0) { if (ove_iteration == 0) {
pixel_coord.x += i/ove_resolution.x; pixel_coord.x += i / ove_resolution.x;
} else if (ove_iteration == 1) { } else if (ove_iteration == 1) {
pixel_coord.y += i/ove_resolution.y; pixel_coord.y += i / ove_resolution.y;
} }
if (repeat_edge_pixels_in if (repeat_edge_pixels_in
@@ -85,9 +88,9 @@ void main(void) {
&& pixel_coord.x < 1.0 && pixel_coord.x < 1.0
&& pixel_coord.y >= 0.0 && pixel_coord.y >= 0.0
&& pixel_coord.y < 1.0)) { && pixel_coord.y < 1.0)) {
composite += texture2D(tex_in, pixel_coord) * weight; composite += texture(tex_in, pixel_coord) * weight;
} }
} }
gl_FragColor = composite; fragColor = composite;
} }
+9 -6
View File
@@ -1,14 +1,17 @@
#version 110 #version 150
// Standard inputs
uniform vec2 ove_resolution;
varying vec2 ove_texcoord;
// Inputs // Inputs
uniform int orientation; uniform int orientation;
uniform vec3 color_a; uniform vec3 color_a;
uniform vec3 color_b; uniform vec3 color_b;
// Standard inputs
uniform vec2 ove_resolution;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
float t; float t;
@@ -21,5 +24,5 @@ void main(void) {
t = 1.0 - ove_texcoord.y; t = 1.0 - ove_texcoord.y;
} }
gl_FragColor = vec4(mix(color_a, color_b, t), 1.0); fragColor = vec4(mix(color_a, color_b, t), 1.0);
} }
+11 -8
View File
@@ -1,12 +1,15 @@
#version 110 #version 150
// Standard inputs
uniform vec2 ove_resolution;
varying vec2 ove_texcoord;
// Custom inputs // Custom inputs
uniform float hsv_value; uniform float hsv_value;
// Standard inputs
uniform vec2 ove_resolution;
in vec2 ove_texcoord;
out vec4 fragColor;
// Color wheel uses PI // Color wheel uses PI
#define M_PI 3.1415926535897932384626433832795 #define M_PI 3.1415926535897932384626433832795
@@ -46,7 +49,7 @@ vec3 hsv_to_rgb(float H, float S, float V) {
Gs = 0.0; Gs = 0.0;
Bs = X; Bs = X;
} }
return vec3(Rs + m, Gs + m, Bs + m); return vec3(Rs + m, Gs + m, Bs + m);
} }
@@ -84,8 +87,8 @@ void main(void) {
float pixel_dist = (pixel_radius / radius) * dist; float pixel_dist = (pixel_radius / radius) * dist;
float alpha = min((pixel_radius - pixel_dist), 1.0); float alpha = min((pixel_radius - pixel_dist), 1.0);
gl_FragColor = vec4(hsv_to_rgb(hue, sat, hsv_value), alpha); fragColor = vec4(hsv_to_rgb(hue, sat, hsv_value), alpha);
} else { } else {
gl_FragColor = vec4(0.0); fragColor = vec4(0.0);
} }
} }
+15 -13
View File
@@ -1,6 +1,4 @@
#version 110 #version 150
varying vec2 ove_texcoord;
uniform sampler2D out_block_in; uniform sampler2D out_block_in;
uniform sampler2D in_block_in; uniform sampler2D in_block_in;
@@ -9,17 +7,21 @@ uniform bool in_block_in_enabled;
uniform float ove_tprog_all; uniform float ove_tprog_all;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
vec4 composite = vec4(0.0); vec4 composite = vec4(0.0);
if (out_block_in_enabled) { if (out_block_in_enabled) {
composite += texture2D(out_block_in, ove_texcoord) * (1.0 - ove_tprog_all); composite += texture(out_block_in, ove_texcoord) * (1.0 - ove_tprog_all);
} }
if (in_block_in_enabled) { if (in_block_in_enabled) {
vec4 in_block_col = texture2D(in_block_in, ove_texcoord) * ove_tprog_all; vec4 in_block_col = texture(in_block_in, ove_texcoord) * ove_tprog_all;
composite += in_block_col; composite += in_block_col;
} }
gl_FragColor = composite; fragColor = composite;
} }
+19 -17
View File
@@ -1,6 +1,4 @@
#version 110 #version 150
varying vec2 ove_texcoord;
uniform sampler2D out_block_in; uniform sampler2D out_block_in;
uniform sampler2D in_block_in; uniform sampler2D in_block_in;
@@ -10,21 +8,25 @@ uniform bool in_block_in_enabled;
uniform float ove_tprog_out; uniform float ove_tprog_out;
uniform float ove_tprog_in; uniform float ove_tprog_in;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
vec4 out_block_col; vec4 out_block_col;
vec4 in_block_col; vec4 in_block_col;
if (out_block_in_enabled) { if (out_block_in_enabled) {
out_block_col = texture2D(out_block_in, ove_texcoord) * pow(ove_tprog_out, 2.0); out_block_col = texture(out_block_in, ove_texcoord) * pow(ove_tprog_out, 2.0);
} else { } else {
out_block_col = vec4(0.0); out_block_col = vec4(0.0);
} }
if (in_block_in_enabled) { if (in_block_in_enabled) {
in_block_col = texture2D(in_block_in, ove_texcoord) * pow(ove_tprog_in, 2.0); in_block_col = texture(in_block_in, ove_texcoord) * pow(ove_tprog_in, 2.0);
} else { } else {
in_block_col = vec4(0.0); in_block_col = vec4(0.0);
} }
gl_FragColor = out_block_col + in_block_col; fragColor = out_block_col + in_block_col;
} }
+17 -14
View File
@@ -1,10 +1,7 @@
#version 110 #version 150
#define M_PI 3.1415926535897932384626433832795 #define M_PI 3.1415926535897932384626433832795
uniform vec2 ove_resolution;
varying vec2 ove_texcoord;
uniform sampler2D tex_in; uniform sampler2D tex_in;
uniform vec3 color_in; uniform vec3 color_in;
uniform float softness_in; uniform float softness_in;
@@ -12,9 +9,15 @@ uniform float opacity_in;
uniform float distance_in; uniform float distance_in;
uniform float direction_in; uniform float direction_in;
uniform vec2 ove_resolution;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
// Use pythagoras with the distance (hypotenuse) to find the shadow offset // Use pythagoras with the distance (hypotenuse) to find the shadow offset
float direction_radians = direction_in * (M_PI/180.0); float direction_radians = direction_in * (M_PI / 180.0);
float opposite = sin(direction_radians) * distance_in; float opposite = sin(direction_radians) * distance_in;
float adjacent = cos(direction_radians) * distance_in; float adjacent = cos(direction_radians) * distance_in;
@@ -32,28 +35,28 @@ void main(void) {
float divider = 1.0 / pow(softness_in, 2.0); float divider = 1.0 / pow(softness_in, 2.0);
shadow_alpha = 0.0; shadow_alpha = 0.0;
for (float x=-radius+0.5;x<=radius;x+=2.0) { for (float x = -radius + 0.5; x <= radius; x += 2.0) {
for (float y=-radius+0.5;y<=radius;y+=2.0) { for (float y = -radius + 0.5; y <= radius; y += 2.0) {
vec2 pixel_coord = ove_texcoord - angle; vec2 pixel_coord = ove_texcoord - angle;
pixel_coord.x += x/ove_resolution.x; pixel_coord.x += x / ove_resolution.x;
pixel_coord.y += y/ove_resolution.y; pixel_coord.y += y / ove_resolution.y;
vec4 pixel_color = texture2D(tex_in, pixel_coord); vec4 pixel_color = texture(tex_in, pixel_coord);
shadow_alpha += pixel_color.a * divider; shadow_alpha += pixel_color.a * divider;
} }
} }
} else { } else {
// Perfectly hard shadow // Perfectly hard shadow
vec4 src_color = texture2D(tex_in, ove_texcoord - angle); vec4 src_color = texture(tex_in, ove_texcoord - angle);
shadow_alpha = src_color.a; shadow_alpha = src_color.a;
} }
vec4 shadow_px = vec4(color_in, shadow_alpha * opacity_in * 0.01); vec4 shadow_px = vec4(color_in, shadow_alpha * opacity_in * 0.01);
// Get current pixel and perform an alpha over for it over the shadow we've made // Get current pixel and perform an alpha over for it over the shadow we've made
vec4 dst_color = texture2D(tex_in, ove_texcoord); vec4 dst_color = texture(tex_in, ove_texcoord);
shadow_px *= (1.0 - dst_color.a); shadow_px *= (1.0 - dst_color.a);
shadow_px += dst_color; shadow_px += dst_color;
gl_FragColor = shadow_px; fragColor = shadow_px;
} }
+13 -10
View File
@@ -1,29 +1,32 @@
// Adapted from "RGB Waveform" by lebek // Adapted from "RGB Waveform" by lebek
// https://www.shadertoy.com/view/4dK3Wc // https://www.shadertoy.com/view/4dK3Wc
#version 110 #version 150
uniform sampler2D ove_maintex; uniform sampler2D ove_maintex;
uniform vec2 ove_resolution; uniform vec2 ove_resolution;
varying vec2 ove_texcoord;
uniform float threshold; uniform float threshold;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
vec3 col = vec3(0.0); vec3 col = vec3(0.0);
float s = ove_texcoord.y*1.8 - 0.15; float s = ove_texcoord.y * 1.8 - 0.15;
float maxb = s+threshold; float maxb = s + threshold;
float minb = s-threshold; float minb = s - threshold;
int y_lim = int(ove_resolution.y); int y_lim = int(ove_resolution.y);
for (int i = 0; i < y_lim; i++) { for (int i = 0; i < y_lim; i++) {
vec3 x = texture2D(ove_maintex, vec2(ove_texcoord.x, float(i)/float(ove_resolution.y))).rgb; vec3 x = texture(ove_maintex, vec2(ove_texcoord.x, float(i) / float(ove_resolution.y))).rgb;
col += step(x, vec3(maxb))*step(vec3(minb), x) / (ove_resolution.y * 0.125); col += step(x, vec3(maxb)) * step(vec3(minb), x) / (ove_resolution.y * 0.125);
float l = dot(x, x); float l = dot(x, x);
col += step(l, maxb*maxb)*step(minb*minb, l) / (ove_resolution.y * 0.125); col += step(l, maxb * maxb) * step(minb * minb, l) / (ove_resolution.y * 0.125);
} }
gl_FragColor = vec4(col, 1.0); fragColor = vec4(col, 1.0);
} }
+4 -2
View File
@@ -1,7 +1,9 @@
#version 110 #version 150
uniform vec4 color_in; uniform vec4 color_in;
out vec4 fragColor;
void main(void) { void main(void) {
gl_FragColor = color_in; fragColor = color_in;
} }
+13 -10
View File
@@ -1,9 +1,4 @@
#version 110 #version 150
// Standard inputs
uniform vec2 ove_resolution;
varying vec2 ove_texcoord;
uniform int ove_iteration;
// Node parameter inputs // Node parameter inputs
uniform sampler2D tex_in; uniform sampler2D tex_in;
@@ -12,8 +7,16 @@ uniform float radius_in;
uniform float opacity_in; uniform float opacity_in;
uniform bool inner_in; uniform bool inner_in;
// Standard inputs
uniform vec2 ove_resolution;
uniform int ove_iteration;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
vec4 pixel_here = texture2D(tex_in, ove_texcoord); vec4 pixel_here = texture(tex_in, ove_texcoord);
// Detect no-op situations // Detect no-op situations
if (radius_in == 0.0 if (radius_in == 0.0
@@ -21,7 +24,7 @@ void main(void) {
|| (inner_in && pixel_here.a == 0.0) || (inner_in && pixel_here.a == 0.0)
|| (!inner_in && pixel_here.a == 1.0)) { || (!inner_in && pixel_here.a == 1.0)) {
// No-op, do nothing // No-op, do nothing
gl_FragColor = pixel_here; fragColor = pixel_here;
return; return;
} }
@@ -38,7 +41,7 @@ void main(void) {
if (abs(length(vec2(i, j))) < radius) { if (abs(length(vec2(i, j))) < radius) {
// Get pixel here // Get pixel here
float alpha = texture2D(tex_in, ove_texcoord + vec2(x_coord, y_coord)).a; float alpha = texture(tex_in, ove_texcoord + vec2(x_coord, y_coord)).a;
if (inner_in) { if (inner_in) {
alpha = 1.0 - alpha; alpha = 1.0 - alpha;
@@ -76,5 +79,5 @@ void main(void) {
stroke_col = stroke_col * (1.0 - pixel_here.a) + pixel_here; stroke_col = stroke_col * (1.0 - pixel_here.a) + pixel_here;
} }
gl_FragColor = stroke_col; fragColor = stroke_col;
} }
+6 -3
View File
@@ -1,8 +1,11 @@
#version 110 #version 150
varying vec2 ove_texcoord;
uniform sampler2D footage_in; uniform sampler2D footage_in;
in vec2 ove_texcoord;
out vec4 fragColor;
void main(void) { void main(void) {
gl_FragColor = texture2D(footage_in, ove_texcoord); fragColor = texture(footage_in, ove_texcoord);
} }
+22 -22
View File
@@ -1,37 +1,37 @@
#version 110 #version 150
uniform mat4 matrix_in; uniform mat4 matrix_in;
attribute vec4 a_position;
attribute vec2 a_texcoord;
varying vec2 ove_texcoord;
uniform vec2 footage_in_resolution; uniform vec2 footage_in_resolution;
uniform vec2 ove_resolution; uniform vec2 ove_resolution;
in vec4 a_position;
in vec2 a_texcoord;
out vec2 ove_texcoord;
mat4 scale_mat4(vec3 scale) { mat4 scale_mat4(vec3 scale) {
return mat4( return mat4(
scale.x, 0.0, 0.0, 0.0, scale.x, 0.0, 0.0, 0.0,
0.0, scale.y, 0.0, 0.0, 0.0, scale.y, 0.0, 0.0,
0.0, 0.0, scale.z, 0.0, 0.0, 0.0, scale.z, 0.0,
0.0, 0.0, 0.0, 1.0 0.0, 0.0, 0.0, 1.0
); );
} }
void main() { void main() {
// Create identity matrix // Create identity matrix
mat4 transform = mat4(1.0); mat4 transform = mat4(1.0);
// Scale to square // Scale to square
transform *= scale_mat4(vec3(1.0/ove_resolution, 1.0)); transform *= scale_mat4(vec3(1.0 / ove_resolution, 1.0));
// Multiply by received matrix // Multiply by received matrix
transform *= matrix_in; transform *= matrix_in;
// Scale back out to footage size // Scale back out to footage size
transform *= scale_mat4(vec3(footage_in_resolution, 1.0)); transform *= scale_mat4(vec3(footage_in_resolution, 1.0));
gl_Position = transform * a_position; gl_Position = transform * a_position;
ove_texcoord = a_texcoord; ove_texcoord = a_texcoord;
} }