FlatFramebufferToTexture.bsl 2.2 KB

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