2
0

LensFlareUpdateIndirectInfo.ankiprog 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!--
  2. Copyright (C) 2009-2018, Panagiotis Christopoulos Charitos and contributors.
  3. All rights reserved.
  4. Code licensed under the BSD License.
  5. http://www.anki3d.org/LICENSE
  6. -->
  7. <shaderProgram>
  8. <inputs>
  9. <input name="IN_DEPTH_MAP_SIZE" type="vec2" const="1"/>
  10. </inputs>
  11. <shaders>
  12. <shader type="comp">
  13. <source><![CDATA[
  14. #include "shaders/Common.glsl"
  15. const uint WORKGROUP_SIZE = 8;
  16. layout(local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
  17. struct DrawArraysIndirectInfo
  18. {
  19. uint count;
  20. uint instanceCount;
  21. uint first;
  22. uint baseInstance;
  23. };
  24. layout(ANKI_SS_BINDING(0, 0), std430, row_major) readonly buffer ss0_
  25. {
  26. mat4 u_mvp;
  27. vec4 u_flarePositions[];
  28. };
  29. layout(ANKI_SS_BINDING(0, 1), std430) writeonly buffer ss1_
  30. {
  31. DrawArraysIndirectInfo u_indirectInfo[];
  32. };
  33. layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthMap;
  34. shared uint s_maxDepth;
  35. void main()
  36. {
  37. // Init the s_maxDepth
  38. if(gl_LocalInvocationIndex == 0)
  39. {
  40. s_maxDepth = 0;
  41. }
  42. memoryBarrierShared();
  43. barrier();
  44. // Project the flare
  45. uint flareIdx = gl_WorkGroupID.x;
  46. vec4 posClip = u_mvp * u_flarePositions[flareIdx];
  47. vec3 posNdc = posClip.xyz / posClip.w;
  48. float depth = posNdc.z;
  49. // Compute the UVs to sample the depth map
  50. vec2 displacement = vec2(gl_LocalInvocationID.xy) - vec2(WORKGROUP_SIZE / 2u); // [-WORKGROUP_SIZE, WORKGROUP_SIZE]
  51. const vec2 TEXEL_SIZE = 1.0 / IN_DEPTH_MAP_SIZE;
  52. vec2 uv = NDC_TO_UV(posNdc.xy) + displacement * TEXEL_SIZE;
  53. // Sample and store depth
  54. float refDepth = textureLod(u_depthMap, uv, 0.0).r;
  55. atomicMax(s_maxDepth, uint(refDepth * float(MAX_U32)));
  56. // Sync
  57. memoryBarrierShared();
  58. barrier();
  59. if(gl_LocalInvocationIndex == 0)
  60. {
  61. float refDepth = float(s_maxDepth) / float(MAX_U32);
  62. u_indirectInfo[flareIdx].count = (depth > refDepth) ? 0u : 4u;
  63. u_indirectInfo[flareIdx].instanceCount = 1u;
  64. u_indirectInfo[flareIdx].first = 0u;
  65. u_indirectInfo[flareIdx].baseInstance = 0u;
  66. }
  67. }
  68. ]]></source>
  69. </shader>
  70. </shaders>
  71. </shaderProgram>