ClearTextureCompute.ankiprog 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. // A slow compute program to clear an image with a contant color
  6. #pragma anki mutator TEXTURE_DIMENSIONS 2 3
  7. #pragma anki mutator COMPONENT_TYPE 0 1 // 0 is float, 1 is uint
  8. #pragma anki start comp
  9. #include <AnKi/Shaders/Common.glsl>
  10. layout(local_size_x = 8, local_size_y = 8, local_size_z = (TEXTURE_DIMENSIONS == 2) ? 1 : 8) in;
  11. layout(push_constant) uniform pc_
  12. {
  13. #if COMPONENT_TYPE == 0
  14. Vec4 u_clearColor;
  15. # define CLEAR_COLOR u_clearColor
  16. #else
  17. UVec4 u_uclearColor;
  18. # define CLEAR_COLOR u_uclearColor
  19. #endif
  20. };
  21. #if TEXTURE_DIMENSIONS == 2
  22. # if COMPONENT_TYPE == 0
  23. layout(set = 0, binding = 0) uniform writeonly image2D u_img2d;
  24. # define IMAGE u_img2d
  25. # else
  26. layout(set = 0, binding = 0) uniform writeonly uimage2D u_uimg2d;
  27. # define IMAGE u_uimg2d
  28. # endif
  29. #else
  30. # if COMPONENT_TYPE == 0
  31. layout(set = 0, binding = 0) uniform writeonly image3D u_img3d;
  32. # define IMAGE u_img3d
  33. # else
  34. layout(set = 0, binding = 0) uniform writeonly uimage3D u_uimg3d;
  35. # define IMAGE u_uimg3d
  36. # endif
  37. #endif
  38. void main()
  39. {
  40. #if TEXTURE_DIMENSIONS == 2
  41. const UVec2 size = UVec2(imageSize(IMAGE));
  42. if(gl_GlobalInvocationID.x >= size.x || gl_GlobalInvocationID.y >= size.y)
  43. {
  44. return;
  45. }
  46. imageStore(IMAGE, IVec2(gl_GlobalInvocationID.xy), CLEAR_COLOR);
  47. #else
  48. const UVec3 size = UVec3(imageSize(IMAGE));
  49. if(gl_GlobalInvocationID.x >= size.x || gl_GlobalInvocationID.y >= size.y || gl_GlobalInvocationID.z >= size.z)
  50. {
  51. return;
  52. }
  53. imageStore(IMAGE, IVec3(gl_GlobalInvocationID), CLEAR_COLOR);
  54. #endif
  55. }
  56. #pragma anki end