bilinear_lowres_scale.effect 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * bilinear low res scaling, samples 8 pixels of a larger image to scale to a
  3. * low resolution image below half size
  4. */
  5. #include "color.effect"
  6. uniform float4x4 ViewProj;
  7. uniform texture2d image;
  8. uniform float multiplier;
  9. sampler_state textureSampler {
  10. Filter = Linear;
  11. AddressU = Clamp;
  12. AddressV = Clamp;
  13. };
  14. struct VertData {
  15. float4 pos : POSITION;
  16. float2 uv : TEXCOORD0;
  17. };
  18. VertData VSDefault(VertData v_in)
  19. {
  20. VertData vert_out;
  21. vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
  22. vert_out.uv = v_in.uv;
  23. return vert_out;
  24. }
  25. float4 pixel(float2 uv)
  26. {
  27. return image.Sample(textureSampler, uv);
  28. }
  29. float4 DrawLowresBilinear(VertData f_in)
  30. {
  31. float2 uv = f_in.uv;
  32. float2 stepxy = float2(ddx(uv.x), ddy(uv.y));
  33. float2 stepxy1 = stepxy * 0.0625;
  34. float2 stepxy3 = stepxy * 0.1875;
  35. float2 stepxy5 = stepxy * 0.3125;
  36. float2 stepxy7 = stepxy * 0.4375;
  37. // Simulate Direct3D 8-sample pattern
  38. float4 out_color;
  39. out_color = pixel(uv + float2( stepxy1.x, -stepxy3.y));
  40. out_color += pixel(uv + float2(-stepxy1.x, stepxy3.y));
  41. out_color += pixel(uv + float2( stepxy5.x, stepxy1.y));
  42. out_color += pixel(uv + float2(-stepxy3.x, -stepxy5.y));
  43. out_color += pixel(uv + float2(-stepxy5.x, stepxy5.y));
  44. out_color += pixel(uv + float2(-stepxy7.x, -stepxy1.y));
  45. out_color += pixel(uv + float2( stepxy3.x, stepxy7.y));
  46. out_color += pixel(uv + float2( stepxy7.x, -stepxy7.y));
  47. return out_color * 0.125;
  48. }
  49. float4 PSDrawLowresBilinearRGBA(VertData f_in) : TARGET
  50. {
  51. return DrawLowresBilinear(f_in);
  52. }
  53. float4 PSDrawLowresBilinearRGBAMultiply(VertData f_in) : TARGET
  54. {
  55. float4 rgba = DrawLowresBilinear(f_in);
  56. rgba.rgb *= multiplier;
  57. return rgba;
  58. }
  59. float4 PSDrawLowresBilinearRGBATonemap(VertData f_in) : TARGET
  60. {
  61. float4 rgba = DrawLowresBilinear(f_in);
  62. rgba.rgb = rec709_to_rec2020(rgba.rgb);
  63. rgba.rgb = reinhard(rgba.rgb);
  64. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  65. return rgba;
  66. }
  67. float4 PSDrawLowresBilinearRGBAMultiplyTonemap(VertData f_in) : TARGET
  68. {
  69. float4 rgba = DrawLowresBilinear(f_in);
  70. rgba.rgb *= multiplier;
  71. rgba.rgb = rec709_to_rec2020(rgba.rgb);
  72. rgba.rgb = reinhard(rgba.rgb);
  73. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  74. return rgba;
  75. }
  76. technique Draw
  77. {
  78. pass
  79. {
  80. vertex_shader = VSDefault(v_in);
  81. pixel_shader = PSDrawLowresBilinearRGBA(f_in);
  82. }
  83. }
  84. technique DrawMultiply
  85. {
  86. pass
  87. {
  88. vertex_shader = VSDefault(v_in);
  89. pixel_shader = PSDrawLowresBilinearRGBAMultiply(f_in);
  90. }
  91. }
  92. technique DrawTonemap
  93. {
  94. pass
  95. {
  96. vertex_shader = VSDefault(v_in);
  97. pixel_shader = PSDrawLowresBilinearRGBATonemap(f_in);
  98. }
  99. }
  100. technique DrawMultiplyTonemap
  101. {
  102. pass
  103. {
  104. vertex_shader = VSDefault(v_in);
  105. pixel_shader = PSDrawLowresBilinearRGBAMultiplyTonemap(f_in);
  106. }
  107. }