bilinear_lowres_scale.effect 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 float2 base_dimension_i;
  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 v_in)
  30. {
  31. float2 stepxy = base_dimension_i;
  32. float4 out_color;
  33. out_color = pixel(v_in.uv);
  34. out_color += pixel(v_in.uv + float2(-stepxy.x, -stepxy.y));
  35. out_color += pixel(v_in.uv + float2(-stepxy.x, 0.0));
  36. out_color += pixel(v_in.uv + float2(-stepxy.x, stepxy.y));
  37. out_color += pixel(v_in.uv + float2( 0.0, -stepxy.y));
  38. out_color += pixel(v_in.uv + float2( 0.0, stepxy.y));
  39. out_color += pixel(v_in.uv + float2( stepxy.x, -stepxy.y));
  40. out_color += pixel(v_in.uv + float2( stepxy.x, 0.0));
  41. out_color += pixel(v_in.uv + float2( stepxy.x, stepxy.y));
  42. return out_color / float4(9.0, 9.0, 9.0, 9.0);
  43. }
  44. float4 PSDrawLowresBilinearRGBA(VertData v_in) : TARGET
  45. {
  46. return DrawLowresBilinear(v_in);
  47. }
  48. float4 PSDrawLowresBilinearMatrix(VertData v_in) : TARGET
  49. {
  50. float3 rgb = DrawLowresBilinear(v_in);
  51. float3 yuv = mul(float4(saturate(rgb), 1.0), color_matrix).xyz;
  52. return float4(yuv, 1.0);
  53. }
  54. technique Draw
  55. {
  56. pass
  57. {
  58. vertex_shader = VSDefault(v_in);
  59. pixel_shader = PSDrawLowresBilinearRGBA(v_in);
  60. }
  61. }
  62. technique DrawMatrix
  63. {
  64. pass
  65. {
  66. vertex_shader = VSDefault(v_in);
  67. pixel_shader = PSDrawLowresBilinearMatrix(v_in);
  68. }
  69. }