SceneDebug.glslp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2009-2018, 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. #pragma anki input const U32 INSTANCE_COUNT
  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(ANKI_UBO_BINDING(1, 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(ANKI_TEX_BINDING(1, 0)) uniform sampler2D u_tex;
  37. #endif
  38. layout(ANKI_UBO_BINDING(1, 0), row_major) uniform u0_
  39. {
  40. Mat4 u_mvp[INSTANCE_COUNT];
  41. Vec4 u_color;
  42. };
  43. // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
  44. #if DITHERED_DEPTH_TEST == 1 || 1
  45. layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_depthRt;
  46. #endif
  47. layout(location = 0) out Vec4 out_color;
  48. void main()
  49. {
  50. // Check if we should skip the frag
  51. #if DITHERED_DEPTH_TEST == 1
  52. Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
  53. F32 depthRef = textureLod(u_depthRt, uv, 0.0).r;
  54. Bool depthTestFailed = gl_FragCoord.z >= depthRef;
  55. IVec2 fragCoordi = IVec2(gl_FragCoord.xy);
  56. if(depthTestFailed && ((fragCoordi.x + fragCoordi.y) % 8) != 0)
  57. {
  58. discard;
  59. }
  60. #endif
  61. // Write the color
  62. #if COLOR_TEXTURE == 1
  63. out_color = texture(u_tex, in_uv) * u_color;
  64. #else
  65. out_color = u_color;
  66. #endif
  67. }
  68. #pragma anki end