Common.glsl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // This file contains common code for all shaders. It's optional but it's recomended to include it
  6. #pragma once
  7. #include <shaders/TextureFunctions.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 F32;
  28. precision DEFAULT_INT_PRECISION I32;
  29. const F32 EPSILON = 0.000001;
  30. const F32 FLT_MAX = 3.402823e+38;
  31. const U32 MAX_U32 = 0xFFFFFFFFu;
  32. const F32 PI = 3.14159265358979323846;
  33. const U32 UBO_MAX_SIZE = 16384u;
  34. const U32 MAX_SHARED_MEMORY = 32u * 1024u;
  35. // Macros
  36. #define UV_TO_NDC(x_) ((x_)*2.0 - 1.0)
  37. #define NDC_TO_UV(x_) ((x_)*0.5 + 0.5)
  38. #define saturate(x_) clamp((x_), 0.0, 1.0)
  39. #define mad(a_, b_, c_) fma((a_), (b_), (c_))
  40. // Common locations
  41. #define POSITION_LOCATION 0
  42. #define TEXTURE_COORDINATE_LOCATION 1
  43. #define TEXTURE_COORDINATE_LOCATION_2 2
  44. #define NORMAL_LOCATION 3
  45. #define TANGENT_LOCATION 4
  46. #define COLOR_LOCATION 5
  47. #define BONE_WEIGHTS_LOCATION 6
  48. #define BONE_INDICES_LOCATION 7
  49. #define SCALE_LOCATION 1
  50. #define ALPHA_LOCATION 2
  51. // Passes
  52. #define PASS_GB 0
  53. #define PASS_FS 1
  54. #define PASS_SM 2
  55. #define PASS_EZ 3
  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