FlatFramebufferToTexture.bsl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. Technique =
  2. {
  3. Language = "HLSL11";
  4. Pass =
  5. {
  6. DepthRead = false;
  7. DepthWrite = false;
  8. Common =
  9. {
  10. struct VStoFS
  11. {
  12. float4 position : SV_POSITION;
  13. float2 uv0 : TEXCOORD0;
  14. };
  15. };
  16. Vertex =
  17. {
  18. struct VertexInput
  19. {
  20. float2 screenPos : POSITION;
  21. float2 uv0 : TEXCOORD0;
  22. };
  23. VStoFS main(VertexInput input)
  24. {
  25. VStoFS output;
  26. output.position = float4(input.screenPos, 0, 1);
  27. output.uv0 = input.uv0;
  28. return output;
  29. }
  30. };
  31. Fragment =
  32. {
  33. cbuffer Params : register(b0)
  34. {
  35. uint2 gFramebufferSize;
  36. uint gSampleCount;
  37. }
  38. Buffer<float4> gInput : register(t0);
  39. uint getLinearAddress(uint2 coord, uint sampleIndex)
  40. {
  41. return (coord.y * gFramebufferSize.x + coord.x) * gSampleCount + sampleIndex;
  42. }
  43. float4 main(VStoFS input, uint sampleIndex : SV_SampleIndex) : SV_Target0
  44. {
  45. int2 pixelPos = trunc(input.uv0);
  46. uint sourceIdx = getLinearAddress(pixelPos, sampleIndex);
  47. return gInput[sourceIdx];
  48. }
  49. };
  50. };
  51. };
  52. Technique =
  53. {
  54. Language = "GLSL";
  55. Pass =
  56. {
  57. DepthRead = false;
  58. DepthWrite = false;
  59. Vertex =
  60. {
  61. layout(location = 0) in vec2 bs_position;
  62. layout(location = 1) in vec2 bs_texcoord0;
  63. layout(location = 0) out vec2 texcoord0;
  64. out gl_PerVertex
  65. {
  66. vec4 gl_Position;
  67. };
  68. void main()
  69. {
  70. gl_Position = vec4(bs_position, 0, 1);
  71. texcoord0 = bs_texcoord0;
  72. }
  73. };
  74. Fragment =
  75. {
  76. layout(location = 0) in vec2 texcoord0;
  77. layout(location = 0) out vec4 fragColor;
  78. layout(binding = 0) uniform Params
  79. {
  80. uvec2 gFramebufferSize;
  81. uint gSampleCount;
  82. };
  83. layout(binding = 1) uniform samplerBuffer gInput;
  84. uint getLinearAddress(uvec2 coord, uint sampleIndex)
  85. {
  86. return (coord.y * gFramebufferSize.x + coord.x) * gSampleCount + sampleIndex;
  87. }
  88. void main()
  89. {
  90. vec2 uv = trunc(texcoord0);
  91. ivec2 pixelPos = ivec2(uv.x, uv.y);
  92. uint sourceIdx = getLinearAddress(pixelPos, gl_SampleID);
  93. fragColor = texelFetch(gInput, int(sourceIdx));
  94. }
  95. };
  96. };
  97. };