Common.glsl 1.8 KB

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