SceneDebug.ankiprog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki mutator COLOR_TEXTURE 0 1
  6. #pragma anki mutator DITHERED_DEPTH_TEST 0 1
  7. ANKI_SPECIALIZATION_CONSTANT_U32(INSTANCE_COUNT, 0, 1);
  8. #pragma anki start vert
  9. #include <shaders/Common.glsl>
  10. layout(location = 0) in Vec3 in_position;
  11. #if COLOR_TEXTURE == 1
  12. layout(location = 1) in Vec2 in_uv;
  13. layout(location = 0) out Vec2 out_uv;
  14. #endif
  15. layout(set = 1, binding = 0, row_major) uniform u0_
  16. {
  17. Mat4 u_mvp[INSTANCE_COUNT];
  18. Vec4 u_color;
  19. };
  20. out gl_PerVertex
  21. {
  22. Vec4 gl_Position;
  23. };
  24. void main()
  25. {
  26. #if COLOR_TEXTURE == 1
  27. out_uv = in_uv;
  28. #endif
  29. gl_Position = u_mvp[gl_InstanceID] * Vec4(in_position, 1.0);
  30. }
  31. #pragma anki end
  32. #pragma anki start frag
  33. #include <shaders/Common.glsl>
  34. #if COLOR_TEXTURE == 1
  35. layout(location = 0) in Vec2 in_uv;
  36. layout(set = 1, binding = 1) uniform sampler u_trilinearRepeatSampler;
  37. layout(set = 1, binding = 2) uniform texture2D u_tex;
  38. #endif
  39. layout(set = 1, binding = 0, row_major) uniform u0_
  40. {
  41. Mat4 u_mvp[INSTANCE_COUNT];
  42. Vec4 u_color;
  43. };
  44. // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
  45. #if DITHERED_DEPTH_TEST == 1
  46. layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
  47. layout(set = 0, binding = 1) uniform texture2D u_depthRt;
  48. #endif
  49. layout(location = 0) out Vec4 out_color;
  50. void main()
  51. {
  52. // Check if we should skip the frag
  53. #if DITHERED_DEPTH_TEST == 1
  54. const Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
  55. const F32 depthRef = textureLod(u_depthRt, u_nearestAnyClampSampler, uv, 0.0).r;
  56. const Bool depthTestFailed = gl_FragCoord.z >= depthRef;
  57. const IVec2 fragCoordi = IVec2(gl_FragCoord.xy);
  58. if(depthTestFailed && ((fragCoordi.x + fragCoordi.y) % 8) != 0)
  59. {
  60. discard;
  61. }
  62. #endif
  63. // Write the color
  64. #if COLOR_TEXTURE == 1
  65. out_color = texture(u_tex, u_trilinearRepeatSampler, in_uv) * u_color;
  66. #else
  67. out_color = u_color;
  68. #endif
  69. }
  70. #pragma anki end