bilinear_lowres_scale.effect 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * bilinear low res scaling, samples 9 pixels of a larger image to scale to a
  3. * low resolution image below half size
  4. */
  5. uniform float4x4 ViewProj;
  6. uniform texture2d image;
  7. uniform float4x4 color_matrix;
  8. uniform float3 color_range_min = {0.0, 0.0, 0.0};
  9. uniform float3 color_range_max = {1.0, 1.0, 1.0};
  10. uniform float2 base_dimension_i;
  11. sampler_state textureSampler {
  12. Filter = Linear;
  13. AddressU = Clamp;
  14. AddressV = Clamp;
  15. };
  16. struct VertData {
  17. float4 pos : POSITION;
  18. float2 uv : TEXCOORD0;
  19. };
  20. VertData VSDefault(VertData v_in)
  21. {
  22. VertData vert_out;
  23. vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
  24. vert_out.uv = v_in.uv;
  25. return vert_out;
  26. }
  27. float4 pixel(float2 uv)
  28. {
  29. return image.Sample(textureSampler, uv);
  30. }
  31. float4 DrawLowresBilinear(VertData v_in)
  32. {
  33. float2 stepxy = base_dimension_i;
  34. float4 out_color;
  35. out_color = pixel(v_in.uv);
  36. out_color += pixel(v_in.uv + float2(-stepxy.x, -stepxy.y));
  37. out_color += pixel(v_in.uv + float2(-stepxy.x, 0.0));
  38. out_color += pixel(v_in.uv + float2(-stepxy.x, stepxy.y));
  39. out_color += pixel(v_in.uv + float2( 0.0, -stepxy.y));
  40. out_color += pixel(v_in.uv + float2( 0.0, stepxy.y));
  41. out_color += pixel(v_in.uv + float2( stepxy.x, -stepxy.y));
  42. out_color += pixel(v_in.uv + float2( stepxy.x, 0.0));
  43. out_color += pixel(v_in.uv + float2( stepxy.x, stepxy.y));
  44. return out_color / float4(9.0, 9.0, 9.0, 9.0);
  45. }
  46. float4 PSDrawLowresBilinearRGBA(VertData v_in) : TARGET
  47. {
  48. return DrawLowresBilinear(v_in);
  49. }
  50. float4 PSDrawLowresBilinearMatrix(VertData v_in) : TARGET
  51. {
  52. float4 yuv = DrawLowresBilinear(v_in);
  53. yuv.xyz = clamp(yuv.xyz, color_range_min, color_range_max);
  54. return saturate(mul(float4(yuv.xyz, 1.0), color_matrix));
  55. }
  56. technique Draw
  57. {
  58. pass
  59. {
  60. vertex_shader = VSDefault(v_in);
  61. pixel_shader = PSDrawLowresBilinearRGBA(v_in);
  62. }
  63. }
  64. technique DrawMatrix
  65. {
  66. pass
  67. {
  68. vertex_shader = VSDefault(v_in);
  69. pixel_shader = PSDrawLowresBilinearMatrix(v_in);
  70. }
  71. }