Common.glsl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // This file contains common code for all shaders. It's optional but it's recomended to include it
  6. #ifndef ANKI_SHADERS_COMMON_GLSL
  7. #define ANKI_SHADERS_COMMON_GLSL
  8. // WORKAROUNDS
  9. #if defined(ANKI_VENDOR_NVIDIA)
  10. # define NVIDIA_LINK_ERROR_WORKAROUND 1
  11. #else
  12. # define NVIDIA_LINK_ERROR_WORKAROUND 0
  13. #endif
  14. #if defined(ANKI_VENDOR_AMD) && defined(ANKI_BACKEND_VULKAN)
  15. # define AMD_VK_READ_FIRST_INVOCATION_COMPILER_CRASH 1
  16. #else
  17. # define AMD_VK_READ_FIRST_INVOCATION_COMPILER_CRASH 0
  18. #endif
  19. // Default precision
  20. #ifndef DEFAULT_FLOAT_PRECISION
  21. # define DEFAULT_FLOAT_PRECISION highp
  22. #endif
  23. #ifndef DEFAULT_INT_PRECISION
  24. # define DEFAULT_INT_PRECISION highp
  25. #endif
  26. // Constants
  27. precision DEFAULT_FLOAT_PRECISION float;
  28. precision DEFAULT_INT_PRECISION int;
  29. const float EPSILON = 0.000001;
  30. const float FLT_MAX = 3.402823e+38;
  31. const uint MAX_U32 = 0xFFFFFFFFu;
  32. const float PI = 3.14159265358979323846;
  33. const uint UBO_MAX_SIZE = 16384u;
  34. const uint SIZEOF_VEC4 = 4 * 4;
  35. const uint SIZEOF_MAT4 = 4 * SIZEOF_VEC4;
  36. // Macros
  37. #define UV_TO_NDC(x_) ((x_)*2.0 - 1.0)
  38. #define NDC_TO_UV(x_) ((x_)*0.5 + 0.5)
  39. #define saturate(x_) clamp((x_), 0.0, 1.0)
  40. #define mad(a_, b_, c_) fma((a_), (b_), (c_))
  41. // Common locations
  42. #define POSITION_LOCATION 0
  43. #define TEXTURE_COORDINATE_LOCATION 1
  44. #define TEXTURE_COORDINATE_LOCATION_2 2
  45. #define NORMAL_LOCATION 3
  46. #define TANGENT_LOCATION 4
  47. #define COLOR_LOCATION 5
  48. #define BONE_WEIGHTS_LOCATION 6
  49. #define BONE_INDICES_LOCATION 7
  50. #define SCALE_LOCATION 1
  51. #define ALPHA_LOCATION 2
  52. // Passes
  53. #define PASS_GB_FS 0
  54. #define PASS_SM 1
  55. #define PASS_EZ 2
  56. // Other
  57. #if defined(ANKI_BACKEND_VULKAN) && ANKI_BACKEND_MAJOR >= 1 && ANKI_BACKEND_MINOR >= 1
  58. # define UNIFORM(x_) subgroupBroadcastFirst(x_)
  59. #else
  60. # define UNIFORM(x_) x_
  61. #endif
  62. #define CALC_BITANGENT_IN_VERT 1
  63. #endif