diff options
Diffstat (limited to 'video')
-rw-r--r-- | video/out/gl_video.c | 6 | ||||
-rw-r--r-- | video/out/gl_video_shaders.glsl | 16 |
2 files changed, 15 insertions, 7 deletions
diff --git a/video/out/gl_video.c b/video/out/gl_video.c index ac2b8a8787..d812ad7960 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -866,9 +866,9 @@ static void shader_setup_scaler(char **shader, struct scaler *scaler, int pass) // The direction/pass assignment is rather arbitrary, but fixed in // other parts of the code (like FBO setup). const char *direction = pass == 0 ? "0, 1" : "1, 0"; - // SAMPLE_CONVOLUTION_SEP_N(NAME, DIR, N, LUT, WEIGHTS_FUNC) - APPENDF(shader, "SAMPLE_CONVOLUTION_SEP_N(%s, vec2(%s), %d, %s, %s)\n", - name, direction, size, lut_tex, lut_fn); + // SAMPLE_CONVOLUTION_SEP_N(NAME, DIR, N, LUT, WEIGHTS_FUNC, ANTIRING) + APPENDF(shader, "SAMPLE_CONVOLUTION_SEP_N(%s, vec2(%s), %d, %s, %s, %f)\n", + name, direction, size, lut_tex, lut_fn, scaler->antiring); } else { // SAMPLE_CONVOLUTION_N(NAME, N, LUT, WEIGHTS_FUNC) APPENDF(shader, "SAMPLE_CONVOLUTION_N(%s, %d, %s, %s)\n", diff --git a/video/out/gl_video_shaders.glsl b/video/out/gl_video_shaders.glsl index 74a2b5c3e6..87fb4d04b0 100644 --- a/video/out/gl_video_shaders.glsl +++ b/video/out/gl_video_shaders.glsl @@ -269,18 +269,26 @@ float[6] weights6(sampler2D lookup, float f) { } // The DIR parameter is (0, 1) or (1, 0), and we expect the shader compiler to -// remove all the redundant multiplications and additions. -#define SAMPLE_CONVOLUTION_SEP_N(NAME, DIR, N, LUT, WEIGHTS_FUNC) \ +// remove all the redundant multiplications and additions, and also to unroll +// the loop and remove the conditional completely +#define SAMPLE_CONVOLUTION_SEP_N(NAME, DIR, N, LUT, WEIGHTS_FUNC, ANTIRING) \ vec4 NAME(VIDEO_SAMPLER tex, vec2 texsize, vec2 texcoord) { \ vec2 pt = (vec2(1.0) / texsize) * DIR; \ float fcoord = dot(fract(texcoord * texsize - vec2(0.5)), DIR); \ vec2 base = texcoord - fcoord * pt - pt * vec2(N / 2 - 1); \ float weights[N] = WEIGHTS_FUNC(LUT, fcoord); \ vec4 res = vec4(0); \ + vec4 hi = vec4(0); \ + vec4 lo = vec4(1); \ for (int n = 0; n < N; n++) { \ - res += vec4(weights[n]) * texture(tex, base + pt * vec2(n)); \ + vec4 c = texture(tex, base + pt * vec2(n)); \ + res += vec4(weights[n]) * c; \ + if (n == N/2-1 || n == N/2) { \ + lo = min(lo, c); \ + hi = max(hi, c); \ + } \ } \ - return res; \ + return mix(res, clamp(res, lo, hi), ANTIRING); \ } #define SAMPLE_CONVOLUTION_N(NAME, N, LUT, WEIGHTS_FUNC) \ |