PPDownsample.bsl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "$ENGINE$\PPBase.bslinc"
  2. Parameters =
  3. {
  4. float2 gInvTexSize;
  5. Sampler2D gInputSamp : alias("gInputTex");
  6. Texture2D gInputTex;
  7. };
  8. Blocks =
  9. {
  10. Block Input;
  11. };
  12. Technique : inherits("PPBase") =
  13. {
  14. Language = "HLSL11";
  15. Pass =
  16. {
  17. Fragment =
  18. {
  19. cbuffer Input
  20. {
  21. float2 gInvTexSize;
  22. }
  23. SamplerState gInputSamp;
  24. Texture2D gInputTex;
  25. float4 main(VStoFS input) : SV_Target0
  26. {
  27. float2 UV[4];
  28. // Blur using a 4x4 kernel. It's assumed current position is right in the middle of a 2x2 kernel (because the output
  29. // texture should be 1/2 the size of the output texture), and moving by one in each direction will sample areas
  30. // between a 2x2 kernel as well if bilinear filtering is enabled.
  31. UV[0] = input.uv0 + gInvTexSize * float2(-1, -1);
  32. UV[1] = input.uv0 + gInvTexSize * float2( 1, -1);
  33. UV[2] = input.uv0 + gInvTexSize * float2(-1, 1);
  34. UV[3] = input.uv0 + gInvTexSize * float2( 1, 1);
  35. float4 sample[4];
  36. for(uint i = 0; i < 4; i++)
  37. sample[i] = gInputTex.Sample(gInputSamp, UV[i]);
  38. return (sample[0] + sample[1] + sample[2] + sample[3]) * 0.25f;
  39. }
  40. };
  41. };
  42. };
  43. Technique : inherits("PPBase") =
  44. {
  45. Language = "GLSL";
  46. Pass =
  47. {
  48. Fragment =
  49. {
  50. in VStoFS
  51. {
  52. vec2 uv0;
  53. } input;
  54. uniform Input
  55. {
  56. vec2 gInvTexSize;
  57. };
  58. uniform sampler2D gInputTex;
  59. out vec4 fragColor;
  60. void main()
  61. {
  62. vec2 UV[4];
  63. // Blur using a 4x4 kernel. It's assumed current position is right in the middle of a 2x2 kernel (because the output
  64. // texture should be 1/2 the size of the output texture), and moving by one in each direction will sample areas
  65. // between a 2x2 kernel as well if bilinear filtering is enabled.
  66. UV[0] = input.uv0 + gInvTexSize * vec2(-1, -1);
  67. UV[1] = input.uv0 + gInvTexSize * vec2( 1, -1);
  68. UV[2] = input.uv0 + gInvTexSize * vec2(-1, 1);
  69. UV[3] = input.uv0 + gInvTexSize * vec2( 1, 1);
  70. vec4 samples[4];
  71. for(uint i = 0; i < 4; i++)
  72. samples[i] = texture2D(gInputTex, UV[i]);
  73. fragColor = (samples[0] + samples[1] + samples[2] + samples[3]) * 0.25f;
  74. }
  75. };
  76. };
  77. };