giprobe_debug.glsl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #[vertex]
  2. #version 450
  3. VERSION_DEFINES
  4. struct CellData {
  5. uint position; // xyz 10 bits
  6. uint albedo; //rgb albedo
  7. uint emission; //rgb normalized with e as multiplier
  8. uint normal; //RGB normal encoded
  9. };
  10. layout(set = 0, binding = 1, std140) buffer CellDataBuffer {
  11. CellData data[];
  12. }
  13. cell_data;
  14. layout(set = 0, binding = 2) uniform texture3D color_tex;
  15. layout(set = 0, binding = 3) uniform sampler tex_sampler;
  16. #ifdef USE_ANISOTROPY
  17. layout(set = 0, binding = 4) uniform texture3D aniso_pos_tex;
  18. layout(set = 0, binding = 5) uniform texture3D aniso_neg_tex;
  19. #endif
  20. layout(push_constant, binding = 0, std430) uniform Params {
  21. mat4 projection;
  22. uint cell_offset;
  23. float dynamic_range;
  24. float alpha;
  25. uint level;
  26. ivec3 bounds;
  27. uint pad;
  28. }
  29. params;
  30. layout(location = 0) out vec4 color_interp;
  31. void main() {
  32. const vec3 cube_triangles[36] = vec3[](
  33. vec3(-1.0f, -1.0f, -1.0f),
  34. vec3(-1.0f, -1.0f, 1.0f),
  35. vec3(-1.0f, 1.0f, 1.0f),
  36. vec3(1.0f, 1.0f, -1.0f),
  37. vec3(-1.0f, -1.0f, -1.0f),
  38. vec3(-1.0f, 1.0f, -1.0f),
  39. vec3(1.0f, -1.0f, 1.0f),
  40. vec3(-1.0f, -1.0f, -1.0f),
  41. vec3(1.0f, -1.0f, -1.0f),
  42. vec3(1.0f, 1.0f, -1.0f),
  43. vec3(1.0f, -1.0f, -1.0f),
  44. vec3(-1.0f, -1.0f, -1.0f),
  45. vec3(-1.0f, -1.0f, -1.0f),
  46. vec3(-1.0f, 1.0f, 1.0f),
  47. vec3(-1.0f, 1.0f, -1.0f),
  48. vec3(1.0f, -1.0f, 1.0f),
  49. vec3(-1.0f, -1.0f, 1.0f),
  50. vec3(-1.0f, -1.0f, -1.0f),
  51. vec3(-1.0f, 1.0f, 1.0f),
  52. vec3(-1.0f, -1.0f, 1.0f),
  53. vec3(1.0f, -1.0f, 1.0f),
  54. vec3(1.0f, 1.0f, 1.0f),
  55. vec3(1.0f, -1.0f, -1.0f),
  56. vec3(1.0f, 1.0f, -1.0f),
  57. vec3(1.0f, -1.0f, -1.0f),
  58. vec3(1.0f, 1.0f, 1.0f),
  59. vec3(1.0f, -1.0f, 1.0f),
  60. vec3(1.0f, 1.0f, 1.0f),
  61. vec3(1.0f, 1.0f, -1.0f),
  62. vec3(-1.0f, 1.0f, -1.0f),
  63. vec3(1.0f, 1.0f, 1.0f),
  64. vec3(-1.0f, 1.0f, -1.0f),
  65. vec3(-1.0f, 1.0f, 1.0f),
  66. vec3(1.0f, 1.0f, 1.0f),
  67. vec3(-1.0f, 1.0f, 1.0f),
  68. vec3(1.0f, -1.0f, 1.0f));
  69. vec3 vertex = cube_triangles[gl_VertexIndex] * 0.5 + 0.5;
  70. #ifdef MODE_DEBUG_LIGHT_FULL
  71. uvec3 posu = uvec3(gl_InstanceIndex % params.bounds.x, (gl_InstanceIndex / params.bounds.x) % params.bounds.y, gl_InstanceIndex / (params.bounds.y * params.bounds.x));
  72. #else
  73. uint cell_index = gl_InstanceIndex + params.cell_offset;
  74. uvec3 posu = uvec3(cell_data.data[cell_index].position & 0x7FF, (cell_data.data[cell_index].position >> 11) & 0x3FF, cell_data.data[cell_index].position >> 21);
  75. #endif
  76. #ifdef MODE_DEBUG_EMISSION
  77. color_interp.xyz = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff, (cell_data.data[cell_index].emission >> 9) & 0x1ff, (cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0);
  78. #endif
  79. #ifdef MODE_DEBUG_COLOR
  80. color_interp.xyz = unpackUnorm4x8(cell_data.data[cell_index].albedo).xyz;
  81. #endif
  82. #ifdef MODE_DEBUG_LIGHT
  83. #ifdef USE_ANISOTROPY
  84. #define POS_X 0
  85. #define POS_Y 1
  86. #define POS_Z 2
  87. #define NEG_X 3
  88. #define NEG_Y 4
  89. #define NEG_Z 5
  90. const uint triangle_aniso[12] = uint[](
  91. NEG_X,
  92. NEG_Z,
  93. NEG_Y,
  94. NEG_Z,
  95. NEG_X,
  96. NEG_Y,
  97. POS_Z,
  98. POS_X,
  99. POS_X,
  100. POS_Y,
  101. POS_Y,
  102. POS_Z);
  103. color_interp.xyz = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level)).xyz * params.dynamic_range;
  104. vec3 aniso_pos = texelFetch(sampler3D(aniso_pos_tex, tex_sampler), ivec3(posu), int(params.level)).xyz;
  105. vec3 aniso_neg = texelFetch(sampler3D(aniso_neg_tex, tex_sampler), ivec3(posu), int(params.level)).xyz;
  106. uint side = triangle_aniso[gl_VertexIndex / 3];
  107. float strength = 0.0;
  108. switch (side) {
  109. case POS_X:
  110. strength = aniso_pos.x;
  111. break;
  112. case POS_Y:
  113. strength = aniso_pos.y;
  114. break;
  115. case POS_Z:
  116. strength = aniso_pos.z;
  117. break;
  118. case NEG_X:
  119. strength = aniso_neg.x;
  120. break;
  121. case NEG_Y:
  122. strength = aniso_neg.y;
  123. break;
  124. case NEG_Z:
  125. strength = aniso_neg.z;
  126. break;
  127. }
  128. color_interp.xyz *= strength;
  129. #else
  130. color_interp = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level));
  131. color_interp.xyz *params.dynamic_range;
  132. #endif
  133. #endif
  134. float scale = (1 << params.level);
  135. gl_Position = params.projection * vec4((vec3(posu) + vertex) * scale, 1.0);
  136. #ifdef MODE_DEBUG_LIGHT_FULL
  137. if (color_interp.a == 0.0) {
  138. gl_Position = vec4(0.0); //force clip and not draw
  139. }
  140. #else
  141. color_interp.a = params.alpha;
  142. #endif
  143. }
  144. #[fragment]
  145. #version 450
  146. VERSION_DEFINES
  147. layout(location = 0) in vec4 color_interp;
  148. layout(location = 0) out vec4 frag_color;
  149. void main() {
  150. frag_color = color_interp;
  151. #ifdef MODE_DEBUG_LIGHT_FULL
  152. //there really is no alpha, so use dither
  153. int x = int(gl_FragCoord.x) % 4;
  154. int y = int(gl_FragCoord.y) % 4;
  155. int index = x + y * 4;
  156. float limit = 0.0;
  157. if (x < 8) {
  158. if (index == 0)
  159. limit = 0.0625;
  160. if (index == 1)
  161. limit = 0.5625;
  162. if (index == 2)
  163. limit = 0.1875;
  164. if (index == 3)
  165. limit = 0.6875;
  166. if (index == 4)
  167. limit = 0.8125;
  168. if (index == 5)
  169. limit = 0.3125;
  170. if (index == 6)
  171. limit = 0.9375;
  172. if (index == 7)
  173. limit = 0.4375;
  174. if (index == 8)
  175. limit = 0.25;
  176. if (index == 9)
  177. limit = 0.75;
  178. if (index == 10)
  179. limit = 0.125;
  180. if (index == 11)
  181. limit = 0.625;
  182. if (index == 12)
  183. limit = 1.0;
  184. if (index == 13)
  185. limit = 0.5;
  186. if (index == 14)
  187. limit = 0.875;
  188. if (index == 15)
  189. limit = 0.375;
  190. }
  191. if (frag_color.a < limit) {
  192. discard;
  193. }
  194. #endif
  195. }