present_bicubic.frag 1.5 KB

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