[orx-fx] Use the appropriate FilterNto1 interfaces

* Fix webgl 2 compatibility
 * Add LumaLaplacian, ACESTonemap, ReinhardTonemap, DirectionalHashBlur
This commit is contained in:
Edwin Jakobs
2022-12-28 13:57:27 +01:00
parent beb53bbde7
commit 750b5ef67e
87 changed files with 578 additions and 175 deletions

View File

@@ -11,15 +11,19 @@ uniform int sourceLevel;
out vec4 o_color;
void main() {
vec2 s = 1.0 / textureSize(tex0, sourceLevel).xy;
vec2 s = 1.0 / vec2(textureSize(tex0, sourceLevel).xy);
int w = window;
vec4 sum = vec4(0.0);
float weight = 0;
float weight = 0.0;
for (int x = -w; x <= w; ++x) {
float lw = exp( -(x*x) / (2 * sigma * sigma) ) ;
vec2 tc = v_texCoord0 + x * blurDirection * s;// * spread;
float lw = exp( float(-(x*x)) / (2.0 * sigma * sigma) ) ;
vec2 tc = v_texCoord0 + float(x) * blurDirection * s;// * spread;
#ifndef OR_WEBGL2
sum += textureLod(tex0, tc, sourceLevel) * lw;
#else
sum += texture(tex0, tc);
#endif
weight += lw;
}
o_color = (sum / weight) * gain;

View File

@@ -1,11 +1,8 @@
#ifdef OR_IN_OUT
in vec2 v_texCoord0;
#else
varying vec2 v_texCoord0;
#endif
uniform sampler2D tex0; // image
uniform sampler2D tex1; // blurDirection
uniform bool centerWindow;
uniform sampler2D tex0;// image
uniform sampler2D tex1;// blurDirection
uniform vec2 textureSize0;
uniform int window;
@@ -16,10 +13,7 @@ uniform bool wrapX;
uniform bool wrapY;
uniform bool perpendicular;
#ifndef OR_GL_FRAGCOLOR
out vec4 o_color;
#endif
vec2 wrap(vec2 uv) {
vec2 res = uv;
@@ -36,30 +30,22 @@ void main() {
vec2 s = textureSize0;
s = vec2(1.0 / s.x, 1.0 / s.y);
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
#ifndef OR_GL_TEXTURE2D
vec2 blurDirection = texture(tex1, v_texCoord0).xy;
if (perpendicular) {
blurDirection = vec2(-blurDirection.y, blurDirection.x);
}
float weight = 0.0;
int start = centerWindow? -window/2 : 0;
int end = centerWindow? window/2 + 1 : window;
for (int x = 0; x < window; ++x) {
sum += texture(tex0, wrap(v_texCoord0 + float(x) * blurDirection * s * spread));
weight += 1.0;
}
#else
vec2 blurDirection = texture2D(tex1, v_texCoord0);
float weight = 0.0;
sum += texture2D(tex0, wrap(v_texCoord0 * blurDirection * s * spread));
#endif
vec4 result = (sum/weight) * gain;
#ifdef OR_GL_FRAGCOLOR
gl_FragColor = result;
#else
o_color = result;
#endif
}

View File

@@ -0,0 +1,79 @@
// based on Hashed blur by David Hoskins.
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
in vec2 v_texCoord0;
layout(binding = 0) uniform sampler2D tex0;
layout(binding = 1) uniform sampler2D tex1;
#ifdef RADIUS_FROM_TEXTURE
layout(binding = 2) uniform sampler2D tex2;
#endif
uniform vec2 textureSize0;
uniform float radius;
uniform float spread;
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 sampleOffset(inout vec2 r, vec2 direction) {
r = fract(r * vec2(33.3983, 43.4427));
return (r.x+.001) * direction;
}
vec2 sampleCircle(inout vec2 r) {
r = fract(r * vec2(33.3983, 43.4427));
return sqrt(r.x+.001) * vec2(sin(r.y * TAU), cos(r.y * TAU))*.5; // <<=== circular sampling.
}
//-------------------------------------------------------------------------------------------
vec4 blur(vec2 uv, float r) {
float radius = r;
#ifdef RADIUS_FROM_TEXTURE
radius *= texture(tex2, uv).r;
#endif
vec2 direction = texture(tex1, uv).xy;
vec2 line = vec2(spread) * (vec2(1.0) / textureSize0);
vec2 circle = vec2(radius) * (vec2(1.0) / textureSize0);
vec2 randomL = hash22(uv + vec2(time));
vec2 randomC = hash22(uv + vec2(time));
vec4 acc = vec4(0.0);
for (int i = 0; i < samples; i++) {
vec2 lineOffset = line * sampleOffset(randomL, direction);
vec2 circleOffset = circle * sampleCircle(randomC);
acc += textureLod(tex0, uv + circleOffset + lineOffset, 0 );
}
return acc / float(samples);
}
//-------------------------------------------------------------------------------------------
void main() {
vec2 uv = v_texCoord0;
float radiusSqr = pow(radius, 2.0);
vec4 result = blur(uv, radiusSqr);
result.rgb *= gain;
o_color = result;
}

View File

@@ -4,7 +4,6 @@ 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

@@ -8,11 +8,13 @@ varying vec2 v_texCoord0;
#endif
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform vec2 textureSize0;
uniform float radius;
uniform float time;
uniform int samples;
uniform float gain;
uniform bool dynamic;
#ifndef OR_GL_FRAGCOLOR
out vec4 o_color;
@@ -37,18 +39,18 @@ vec2 sampleTexture(inout vec2 r) {
//-------------------------------------------------------------------------------------------
vec4 blur(vec2 uv, float radius) {
vec2 circle = vec2(radius) * (vec2(1.0) / textureSize0);
float r = radius;
if (dynamic) {
r *= texture(tex1, uv).r;
}
vec2 circle = vec2(r) * (vec2(1.0) / textureSize0);
vec2 random = hash22(uv + vec2(time));
vec4 acc = vec4(0.0);
for (int i = 0; i < 100; i++) {
if (i > samples) break;
#ifndef OR_GL_TEXTURE2D
for (int i = 0; i < samples; i++) {
acc += texture(tex0, uv + circle * sampleTexture(random));
#else
acc += texture2D(tex0, uv + circle * sampleTexture(random));
#endif
}
return acc / float(samples);
}

View File

@@ -6,7 +6,7 @@ uniform float spread;
void main() {
ivec2 size = textureSize(tex0, 0);
vec2 pixelSize = vec2(1.0/size.x, 1.0/size.y);
vec2 pixelSize = vec2(1.0/float(size.x), 1.0/float(size.y));
vec2 halfPixelSize = pixelSize / 2.0f;
vec2 d = (pixelSize.xy * vec2(iteration, iteration)) + halfPixelSize.xy;
d *= spread;

View File

@@ -18,7 +18,7 @@ void main() {
}
vec2 vt = (v_texCoord0 - vec2(0.5, 0.5) + center) * radius + vec2(0.5, 0.5) - center;
vec2 size = textureSize(tex0, 0);
vec2 size = vec2(textureSize(tex0, 0));
vec2 l = (v_texCoord0 - vec2(0.5, 0.5) + center) * vec2(1.0, size.y/size.x);
float d = length(l);
@@ -31,7 +31,7 @@ void main() {
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;
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));
}
@@ -44,6 +44,4 @@ void main() {
if (!linearOutput) {
o_output.rgb = pow(o_output.rgb, vec3(1.0 / 2.2));
}
}