BicubicHorizontalUpsamplePS.hlsl 1.9 KB

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