BicubicVerticalUpsamplePS.hlsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
  2. // CHECK: IMax
  3. // CHECK: UMin
  4. //
  5. // Copyright (c) Microsoft. All rights reserved.
  6. // This code is licensed under the MIT License (MIT).
  7. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  8. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  9. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  10. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  11. //
  12. // Developed by Minigraph
  13. //
  14. // Author: James Stanard
  15. //
  16. //--------------------------------------------------------------------------------------
  17. // Simple bicubic filter
  18. //
  19. // http://en.wikipedia.org/wiki/Bicubic_interpolation
  20. // http://http.developer.nvidia.com/GPUGems/gpugems_ch24.html
  21. //
  22. //--------------------------------------------------------------------------------------
  23. #include "ShaderUtility.hlsli"
  24. #include "PresentRS.hlsli"
  25. Texture2D<float3> ColorTex : register(t0);
  26. cbuffer Constants : register(b0)
  27. {
  28. uint2 TextureSize;
  29. float A;
  30. }
  31. float W1(float x)
  32. {
  33. return x * x * ((A + 2) * x - (A + 3)) + 1.0;
  34. }
  35. float W2(float x)
  36. {
  37. return A * (x * (x * (x - 5) + 8) - 4);
  38. }
  39. float4 GetWeights(float d1)
  40. {
  41. return float4(W2(1.0 + d1), W1(d1), W1(1.0 - d1), W2(2.0 - d1));
  42. }
  43. float3 GetColor(uint s, uint t)
  44. {
  45. return ColorTex[uint2(s, t)];
  46. }
  47. [RootSignature(Present_RootSig)]
  48. float3 main(float4 position : SV_Position, float2 uv : TexCoord0) : SV_Target0
  49. {
  50. float2 t = uv * TextureSize + 0.5;
  51. float2 f = frac(t);
  52. int2 st = int2(position.x, t.y);
  53. uint MaxHeight = TextureSize.y - 1;
  54. uint t0 = max(st.y - 2, 0);
  55. uint t1 = max(st.y - 1, 0);
  56. uint t2 = min(st.y + 0, MaxHeight);
  57. uint t3 = min(st.y + 1, MaxHeight);
  58. float4 W = GetWeights(f.y);
  59. float3 Color =
  60. W.x * GetColor(st.x, t0) +
  61. W.y * GetColor(st.x, t1) +
  62. W.z * GetColor(st.x, t2) +
  63. W.w * GetColor(st.x, t3);
  64. #ifdef GAMMA_SPACE
  65. return Color;
  66. #else
  67. return ApplyColorProfile(Color, DISPLAY_PLANE_FORMAT);
  68. #endif
  69. }