[orx-fx] convert to MPP

This commit is contained in:
Edwin Jakobs
2021-06-27 21:07:44 +02:00
parent 7d524df2de
commit 4dfc5c31c8
144 changed files with 1197 additions and 847 deletions

View File

@@ -0,0 +1,26 @@
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform vec2 blurDirection;
uniform int window;
uniform float sigma;
uniform float spread;
uniform float gain;
uniform int sourceLevel;
out vec4 o_color;
void main() {
vec2 s = 1.0 / textureSize(tex0, sourceLevel).xy;
int w = window;
vec4 sum = vec4(0.0);
float weight = 0;
for (int x = -w; x <= w; ++x) {
float lw = exp( -(x*x) / (2 * sigma * sigma) ) ;
vec2 tc = v_texCoord0 + x * blurDirection * s;// * spread;
sum += textureLod(tex0, tc, sourceLevel) * lw;
weight += lw;
}
o_color = (sum / weight) * gain;
}

View File

@@ -0,0 +1,13 @@
out vec4 o_output;
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float gain;
uniform vec4 bias;
void main() {
o_output = texture(tex0, v_texCoord0) + texture(tex1, v_texCoord0)*gain;
o_output.a = clamp(o_output.a, 0.0, 1.0);
}

View File

@@ -0,0 +1,19 @@
out vec4 o_output;
in vec2 v_texCoord0;
uniform sampler2D tex0;
// -- based on https://github.com/excess-demogroup/even-laster-engine/blob/a451a89f6bd6d3c6017d5890b92d9f72823bc742/src/shaders/bloom.fra
void main()
{
float centerWeight = 0.16210282163712664;
vec2 diagonalOffsets = vec2(0.3842896354828526, 1.2048616327242379);
vec4 offsets = vec4(-diagonalOffsets.xy, +diagonalOffsets.xy) / textureSize(tex0, 0).xyxy;
float diagonalWeight = 0.2085034734347498;
o_output = textureLod(tex0, v_texCoord0, 0) * centerWeight +
textureLod(tex0, v_texCoord0 + offsets.xy, 0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.wx, 0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.zw, 0) * diagonalWeight +
textureLod(tex0, v_texCoord0 + offsets.yz, 0) * diagonalWeight;
}

View File

@@ -0,0 +1,81 @@
float nrand(vec2 n) {
return fract(sin(dot(n.xy, vec2(12.9898, 78.233))) * 43758.5453);
}
// -- based on https://github.com/excess-demogroup/even-laster-engine/blob/a451a89f6bd6d3c6017d5890b92d9f72823bc742/src/shaders/bloom_upscale.frag
uniform float noiseSeed;
uniform float shape;
uniform float gain;
uniform float noiseGain;
in vec2 v_texCoord0;
out vec4 o_output;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
uniform sampler2D tex4;
uniform sampler2D tex5;
vec4 sampleBloom(vec2 pos, float shape) {
vec4 sum = vec4(0);
float total = 0;
{
float weight = pow(0.0, shape);
vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed),
nrand(5 + 0.0 + pos.yx - noiseSeed));
rnd = (rnd * 2 - 1) / textureSize(tex0, 0);
sum += textureLod(tex0, pos + rnd * noiseGain, 0.0) * weight;
total += weight;
}
{
float weight = pow(1.0, shape);
vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed),
nrand(5 + 0.0 + pos.yx - noiseSeed));
rnd = (rnd * 2 - 1) / textureSize(tex1, 0);
sum += textureLod(tex1, pos + rnd * noiseGain, 0.0) * weight;
total += weight;
}
{
float weight = pow(2.0, shape);
vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed),
nrand(5 + 0.0 + pos.yx - noiseSeed));
rnd = (rnd * 2 - 1) / textureSize(tex2, 0);
sum += textureLod(tex2, pos + rnd * noiseGain, 0.0) * weight;
total += weight;
}
{
float weight = pow(3.0, shape);
vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed),
nrand(5 + 0.0 + pos.yx - noiseSeed));
rnd = (rnd * 3 - 1) / textureSize(tex3, 0);
sum += textureLod(tex3, pos + rnd * noiseGain, 0.0) * weight;
total += weight;
}
{
float weight = pow(4.0, shape);
vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed),
nrand(5 + 0.0 + pos.yx - noiseSeed));
rnd = (rnd * 3 - 1) / textureSize(tex3, 0);
sum += textureLod(tex4, pos + rnd * noiseGain, 0.0) * weight;
total += weight;
}
{
float weight = pow(5.0, shape);
vec2 rnd = vec2(nrand(3 + 0.0 + pos.xy + noiseSeed),
nrand(5 + 0.0 + pos.yx - noiseSeed));
rnd = (rnd * 3 - 1) / textureSize(tex3, 0);
sum += textureLod(tex5, pos + rnd * noiseGain, 0.0) * weight;
total += weight;
}
return sum / total;
}
void main() {
o_output = sampleBloom(v_texCoord0, shape) * gain;
}

View File

@@ -0,0 +1,18 @@
in vec2 v_texCoord0;
out vec4 o_color;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float blendFactor;
uniform float brightness;
void main() {
vec3 original = texture(tex0, v_texCoord0).rgb;
vec3 bloom = texture(tex1, v_texCoord0).rgb;
vec3 hdrColor = mix(original, bloom, blendFactor);
vec3 result = vec3(1.0) - exp(-hdrColor * brightness);
o_color = vec4(result, 1.0);
}

View File

@@ -0,0 +1,27 @@
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform vec2 blurDirection;
uniform int window;
uniform float sigma;
uniform float gain;
uniform vec4 subtract;
uniform float spread;
out vec4 o_color;
void main() {
vec2 s = textureSize(tex0, 0).xy;
s = vec2(1.0/s.x, 1.0/s.y);
int w = window;
vec4 sum = vec4(0, 0, 0, 0);
float weight = 0;
for (int x = -w; x<= w; ++x) {
float lw = 1.0;
sum += texture(tex0, v_texCoord0 + x * blurDirection * s * spread);
weight += lw;
}
o_color = (sum / weight) * gain;
// o_color.a = 1.0;
}

View File

@@ -0,0 +1,11 @@
in vec2 v_texCoord0;
uniform sampler2D tex0; // input image
uniform sampler2D tex1; // accumulator image
uniform float blend;
out vec4 o_color;
void main() {
vec4 inputColor = texture(tex0, v_texCoord0);
vec4 accumulator = texture(tex1, v_texCoord0);
o_color = accumulator * (1.0 - blend) + inputColor * blend;
}

View File

@@ -0,0 +1,29 @@
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform int window;
uniform float sigma;
uniform float spread;
uniform float gain;
out vec4 o_color;
void main() {
vec2 s = textureSize(tex0, 0).xy;
s = vec2(1.0/s.x, 1.0/s.y);
int w = window;
vec4 sum = vec4(0,0,0,0);
float weight = 0;
for (int y = -w; y<= w; ++y) {
for (int x = -w; x<= w; ++x) {
float lw = exp(-(x*x+y*y) / (2 * sigma * sigma));
sum+=texture(tex0, v_texCoord0 + vec2(x,y) * s * spread) * lw;
weight+=lw;
}
}
o_color = (sum / weight) * gain;
}

View File

@@ -0,0 +1,47 @@
// based on Hashed blur by David Hoskins.
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
uniform float radius;
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform float time;
uniform int samples;
uniform float gain;
out vec4 o_color;
#define TAU 6.28318530718
//-------------------------------------------------------------------------------------------
#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));
}
vec2 sampleTexture(inout vec2 r) {
r = fract(r * vec2(33.3983, 43.4427));
//return r-.5;
return sqrt(r.x+.001) * vec2(sin(r.y * TAU), cos(r.y * TAU))*.5; // <<=== circular sampling.
}
//-------------------------------------------------------------------------------------------
vec4 blur(vec2 uv, float radius) {
vec2 circle = vec2(radius) * (vec2(1.0) / textureSize(tex0, 0));
vec2 random = hash22(uv + vec2(time));
vec4 acc = vec4(0.0);
for (int i = 0; i < samples; i++) {
acc += texture(tex0, uv + circle * sampleTexture(random));
}
return acc / float(samples);
}
//-------------------------------------------------------------------------------------------
void main() {
vec2 uv = v_texCoord0;
float radiusSqr = pow(radius, 2.0);
o_color = blur(uv, radiusSqr);
o_color.rgb *= gain;
}

View File

@@ -0,0 +1,23 @@
out vec4 o_color;
in vec2 v_texCoord0;
uniform sampler2D tex0;
uniform int iteration;
uniform float spread;
void main() {
ivec2 size = textureSize(tex0, 0);
vec2 pixelSize = vec2(1.0/size.x, 1.0/size.y);
vec2 halfPixelSize = pixelSize / 2.0f;
vec2 d = (pixelSize.xy * vec2(iteration, iteration)) + halfPixelSize.xy;
d *= spread;
vec4 dec = vec4(2.2);
vec4 enc = vec4(1.0/2.2);
vec4 cOut = pow(texture(tex0, v_texCoord0+ vec2(-1, 1)*d), dec);
cOut += pow(texture(tex0, v_texCoord0 + vec2(1, 1)*d), dec);
cOut += pow(texture(tex0, v_texCoord0 + vec2(1, -1)*d), dec);
cOut += pow(texture(tex0, v_texCoord0+ vec2(-1, -1)*d), dec);
o_color = pow(cOut/4.0, enc);
}

View File

@@ -0,0 +1,49 @@
out vec4 o_output;
uniform sampler2D tex0;
in vec2 v_texCoord0;
uniform float radius;
uniform float amp0;
uniform float amp1;
uniform vec2 center;
uniform float vignette;
uniform float vignetteSize;
uniform float aberration;
uniform bool linearInput;
uniform bool linearOutput;
void main() {
vec4 i0 = texture(tex0, v_texCoord0);
if (!linearInput) {
i0.rgb = pow(i0.rgb, vec3(2.2));
}
vec2 vt = (v_texCoord0 - vec2(0.5, 0.5) + center) * radius + vec2(0.5, 0.5) - center;
vec2 size = textureSize(tex0, 0);
vec2 l = (v_texCoord0 - vec2(0.5, 0.5) + center) * vec2(1.0, size.y/size.x);
float d = length(l);
if (vt.x >= 0.0 && vt.y >= 0.0 && vt.x <= 1.0 && vt.y <= 1.0) {
vec4 i1r = texture(tex0, (v_texCoord0 - vec2(0.5, 0.5) + center) * (radius*(1.0 + aberration)) + vec2(0.5, 0.5) - center);
vec4 i1g = texture(tex0, (v_texCoord0 - vec2(0.5, 0.5) + center) * (radius*(1.0)) + vec2(0.5, 0.5) - center);
vec4 i1b = texture(tex0, (v_texCoord0 - vec2(0.5, 0.5) + center) * (radius*(1.0 - aberration)) + vec2(0.5, 0.5) - center);
i1r.rgb = i1r.a > 0.0 ? i1r.rgb / i1r.a : vec3(0.0);
i1g.rgb = i1g.a > 0.0 ? i1g.rgb / i1g.a : vec3(0.0);
i1b.rgb = i1b.a > 0.0 ? i1b.rgb / i1b.a : vec3(0.0);
vec4 i1 = vec4(i1r.r, i1g.g, i1b.b, 1.0) * (i1r.a + i1g.a + i1b.a)/3.0;
if (!linearInput) {
i1.rgb = pow(i1.rgb, vec3(2.2));
}
o_output = i0 * amp0 + i1 * amp1;
} else {
o_output = i0 * 0.5;
}
o_output.rgb *= mix(1.0, smoothstep(vignetteSize, 0.0, d), vignette);
if (!linearOutput) {
o_output.rgb = pow(o_output.rgb, vec3(1.0 / 2.2));
}
}

View File

@@ -0,0 +1,39 @@
in vec2 v_texCoord0;
uniform sampler2D tex0; // input
uniform vec2 center;
uniform float strength;
uniform vec2 dimensions;
out vec4 o_color;
float random(vec3 scale, float seed) {
/* use the fragment position for a different seed per-pixel */
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
}
// Implementation by Evan Wallace (glfx.js)
void main() {
vec4 color = vec4(0.0);
float total = 0.0;
vec2 toCenter = center - v_texCoord0;
/* randomize the lookup values to hide the fixed number of samples */
float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0);
for (float t = 0.0; t <= 40.0; t++) {
float percent = (t + offset) / 40.0;
float weight = 4.0 * (percent - percent * percent);
vec4 tex = texture(tex0, v_texCoord0 + toCenter * percent * strength);
/* switch to pre-multiplied alpha to correctly blur transparent images */
tex.rgb *= tex.a;
color += tex * weight;
total += weight;
}
o_color = color / total;
/* switch back from pre-multiplied alpha */
o_color.rgb /= o_color.a + 0.00001;
}