diff options
author | Niklas Haas <git@nand.wakku.to> | 2016-04-12 15:55:48 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-04-12 16:26:53 +0200 |
commit | e3e03d0f34de86085d18f92a3dceab337c3220b6 (patch) | |
tree | 169b28ddfa12e9fc938c8748d3372da77cd8b9bc /video/out/opengl/video_shaders.c | |
parent | f4142ab9ad1d929b60ff134754f482754b63043a (diff) | |
download | mpv-e3e03d0f34de86085d18f92a3dceab337c3220b6.tar.bz2 mpv-e3e03d0f34de86085d18f92a3dceab337c3220b6.tar.xz |
vo_opengl: simplify and improve up scale=oversample
Since what we're doing is a linear blend of the four colors, we can just
do it for free by using GPU sampling.
This requires significantly fewer texture fetches and calculations to
compute the final color, making it much more efficient. The code is also
much shorter and simpler.
Diffstat (limited to 'video/out/opengl/video_shaders.c')
-rw-r--r-- | video/out/opengl/video_shaders.c | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/video/out/opengl/video_shaders.c b/video/out/opengl/video_shaders.c index bea1bbf325..cf022b96dd 100644 --- a/video/out/opengl/video_shaders.c +++ b/video/out/opengl/video_shaders.c @@ -208,31 +208,15 @@ void pass_sample_oversample(struct gl_shader_cache *sc, struct scaler *scaler, GLSLF("{\n"); GLSL(vec2 pos = pos + vec2(0.5) * pt;) // round to nearest GLSL(vec2 fcoord = fract(pos * size - vec2(0.5));) - // We only need to sample from the four corner pixels since we're using - // nearest neighbour and can compute the exact transition point - GLSL(vec2 baseNW = pos - fcoord * pt;) - GLSL(vec2 baseNE = baseNW + vec2(pt.x, 0.0);) - GLSL(vec2 baseSW = baseNW + vec2(0.0, pt.y);) - GLSL(vec2 baseSE = baseNW + pt;) // Determine the mixing coefficient vector gl_sc_uniform_vec2(sc, "output_size", (float[2]){w, h}); - GLSL(vec2 coeff = vec2((baseSE - pos) * output_size);) - GLSL(coeff = clamp(coeff, 0.0, 1.0);) + GLSL(vec2 coeff = fcoord * output_size/size;) float threshold = scaler->conf.kernel.params[0]; - if (threshold > 0) { // also rules out NAN - GLSLF("coeff = mix(coeff, vec2(0.0), " - "lessThanEqual(coeff, vec2(%f)));\n", threshold); - GLSLF("coeff = mix(coeff, vec2(1.0), " - "greaterThanEqual(coeff, vec2(%f)));\n", 1.0 - threshold); - } + threshold = isnan(threshold) ? 0.0 : threshold; + GLSLF("coeff = (coeff - %f) / %f;\n", threshold, 1.0 - 2 * threshold); + GLSL(coeff = clamp(coeff, 0.0, 1.0);) // Compute the right blend of colors - GLSL(vec4 left = mix(texture(tex, baseSW), - texture(tex, baseNW), - coeff.y);) - GLSL(vec4 right = mix(texture(tex, baseSE), - texture(tex, baseNE), - coeff.y);) - GLSL(color = mix(right, left, coeff.x);) + GLSL(color = texture(tex, pos + pt * (coeff - fcoord));) GLSLF("}\n"); } |