diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2021-08-17 00:12:52 +0200 |
---|---|---|
committer | Fernando Sahmkow <fsahmkow27@gmail.com> | 2021-11-16 22:11:29 +0100 |
commit | a6b88e85bfb14c45345f6443b54d15a61e3975d5 (patch) | |
tree | e5908c9c61f3da27fc5f0c5e20d2a8e9809594f9 /src/video_core/host_shaders/opengl_present_bicubic.frag | |
parent | Texture Cache: fix scaling on upload and stop scaling on base resolution. (diff) | |
download | yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.tar yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.tar.gz yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.tar.bz2 yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.tar.lz yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.tar.xz yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.tar.zst yuzu-a6b88e85bfb14c45345f6443b54d15a61e3975d5.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/host_shaders/opengl_present_bicubic.frag | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/video_core/host_shaders/opengl_present_bicubic.frag b/src/video_core/host_shaders/opengl_present_bicubic.frag new file mode 100644 index 000000000..17772095a --- /dev/null +++ b/src/video_core/host_shaders/opengl_present_bicubic.frag @@ -0,0 +1,56 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#version 460 core + +layout (location = 0) in vec2 frag_tex_coord; + +layout (location = 0) out vec4 color; + +layout (binding = 1) uniform sampler2D color_texture; + +vec4 cubic(float v) { + vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v; + vec4 s = n * n * n; + float x = s.x; + float y = s.y - 4.0 * s.x; + float z = s.z - 4.0 * s.y + 6.0 * s.x; + float w = 6.0 - x - y - z; + return vec4(x, y, z, w) * (1.0 / 6.0); +} + +vec4 textureBicubic( sampler2D textureSampler, vec2 texCoords ) { + + vec2 texSize = textureSize(textureSampler, 0); + vec2 invTexSize = 1.0 / texSize; + + texCoords = texCoords * texSize - 0.5; + + vec2 fxy = fract(texCoords); + texCoords -= fxy; + + vec4 xcubic = cubic(fxy.x); + vec4 ycubic = cubic(fxy.y); + + vec4 c = texCoords.xxyy + vec2(-0.5, +1.5).xyxy; + + vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw); + vec4 offset = c + vec4(xcubic.yw, ycubic.yw) / s; + + offset *= invTexSize.xxyy; + + vec4 sample0 = texture(textureSampler, offset.xz); + vec4 sample1 = texture(textureSampler, offset.yz); + vec4 sample2 = texture(textureSampler, offset.xw); + vec4 sample3 = texture(textureSampler, offset.yw); + + float sx = s.x / (s.x + s.y); + float sy = s.z / (s.z + s.w); + + return mix(mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy); +} + +void main() { + color = vec4(textureBicubic(color_texture, frag_tex_coord).rgb, 1.0f); +} |