present_bicubic.frag 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #version 460 core
  4. #ifdef VULKAN
  5. #define BINDING_COLOR_TEXTURE 1
  6. #else // ^^^ Vulkan ^^^ // vvv OpenGL vvv
  7. #define BINDING_COLOR_TEXTURE 0
  8. #endif
  9. layout (location = 0) in vec2 frag_tex_coord;
  10. layout (location = 0) out vec4 color;
  11. layout (binding = BINDING_COLOR_TEXTURE) uniform sampler2D color_texture;
  12. vec4 cubic(float v) {
  13. vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v;
  14. vec4 s = n * n * n;
  15. float x = s.x;
  16. float y = s.y - 4.0 * s.x;
  17. float z = s.z - 4.0 * s.y + 6.0 * s.x;
  18. float w = 6.0 - x - y - z;
  19. return vec4(x, y, z, w) * (1.0 / 6.0);
  20. }
  21. vec4 textureBicubic( sampler2D textureSampler, vec2 texCoords ) {
  22. vec2 texSize = textureSize(textureSampler, 0);
  23. vec2 invTexSize = 1.0 / texSize;
  24. texCoords = texCoords * texSize - 0.5;
  25. vec2 fxy = fract(texCoords);
  26. texCoords -= fxy;
  27. vec4 xcubic = cubic(fxy.x);
  28. vec4 ycubic = cubic(fxy.y);
  29. vec4 c = texCoords.xxyy + vec2(-0.5, +1.5).xyxy;
  30. vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);
  31. vec4 offset = c + vec4(xcubic.yw, ycubic.yw) / s;
  32. offset *= invTexSize.xxyy;
  33. vec4 sample0 = texture(textureSampler, offset.xz);
  34. vec4 sample1 = texture(textureSampler, offset.yz);
  35. vec4 sample2 = texture(textureSampler, offset.xw);
  36. vec4 sample3 = texture(textureSampler, offset.yw);
  37. float sx = s.x / (s.x + s.y);
  38. float sy = s.z / (s.z + s.w);
  39. return mix(mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy);
  40. }
  41. void main() {
  42. color = vec4(textureBicubic(color_texture, frag_tex_coord).rgb, 1.0f);
  43. }