SceneDebug.ankiprog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. layout(set = 1, binding = 0, row_major) uniform u0_
  9. {
  10. Mat4 u_mvp[INSTANCE_COUNT];
  11. Vec4 u_color;
  12. };
  13. #pragma anki start vert
  14. #include <shaders/Common.glsl>
  15. layout(location = 0) in Vec3 in_position;
  16. #if COLOR_TEXTURE == 1
  17. layout(location = 1) in Vec2 in_uv;
  18. layout(location = 0) out Vec2 out_uv;
  19. #endif
  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. #include <shaders/ImportanceSampling.glsl>
  35. #if COLOR_TEXTURE == 1
  36. layout(location = 0) in Vec2 in_uv;
  37. layout(set = 1, binding = 1) uniform sampler u_trilinearRepeatSampler;
  38. layout(set = 1, binding = 2) uniform texture2D u_tex;
  39. #endif
  40. // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
  41. #if DITHERED_DEPTH_TEST == 1
  42. layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
  43. layout(set = 0, binding = 1) uniform texture2D u_depthRt;
  44. #endif
  45. layout(location = 0) out Vec4 out_color;
  46. void main()
  47. {
  48. // Check if we should skip the frag
  49. #if DITHERED_DEPTH_TEST == 1
  50. const UVec2 random = rand3DPCG16(UVec3(UVec2(gl_FragCoord.xy), 1)).xy;
  51. const Vec2 noise = Vec2(random) / 65536.0;
  52. const F32 factor = noise.x * noise.y;
  53. const Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
  54. const F32 depthRef = textureLod(u_depthRt, u_nearestAnyClampSampler, uv, 0.0).r;
  55. const Bool depthTestFailed = gl_FragCoord.z >= depthRef;
  56. if(depthTestFailed && factor < 0.5)
  57. {
  58. discard;
  59. }
  60. #endif
  61. // Write the color
  62. #if COLOR_TEXTURE == 1
  63. out_color = texture(u_tex, u_trilinearRepeatSampler, in_uv) * u_color;
  64. #else
  65. out_color = u_color;
  66. #endif
  67. }
  68. #pragma anki end