canvas_uniforms_inc.glsl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #define MAX_LIGHTS_PER_ITEM 16
  2. #define M_PI 3.14159265359
  3. #define SDF_MAX_LENGTH 16384.0
  4. #define FLAGS_INSTANCING_STRIDE_MASK 0xF
  5. #define FLAGS_INSTANCING_ENABLED (1 << 4)
  6. #define FLAGS_INSTANCING_HAS_COLORS (1 << 5)
  7. #define FLAGS_INSTANCING_COLOR_8BIT (1 << 6)
  8. #define FLAGS_INSTANCING_HAS_CUSTOM_DATA (1 << 7)
  9. #define FLAGS_INSTANCING_CUSTOM_DATA_8_BIT (1 << 8)
  10. #define FLAGS_CLIP_RECT_UV (1 << 9)
  11. #define FLAGS_TRANSPOSE_RECT (1 << 10)
  12. #define FLAGS_USING_LIGHT_MASK (1 << 11)
  13. #define FLAGS_NINEPACH_DRAW_CENTER (1 << 12)
  14. #define FLAGS_USING_PARTICLES (1 << 13)
  15. #define FLAGS_NINEPATCH_H_MODE_SHIFT 16
  16. #define FLAGS_NINEPATCH_V_MODE_SHIFT 18
  17. #define FLAGS_LIGHT_COUNT_SHIFT 20
  18. #define FLAGS_DEFAULT_NORMAL_MAP_USED (1 << 26)
  19. #define FLAGS_DEFAULT_SPECULAR_MAP_USED (1 << 27)
  20. #define SAMPLER_NEAREST_CLAMP 0
  21. #define SAMPLER_LINEAR_CLAMP 1
  22. #define SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP 2
  23. #define SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP 3
  24. #define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_CLAMP 4
  25. #define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_CLAMP 5
  26. #define SAMPLER_NEAREST_REPEAT 6
  27. #define SAMPLER_LINEAR_REPEAT 7
  28. #define SAMPLER_NEAREST_WITH_MIPMAPS_REPEAT 8
  29. #define SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT 9
  30. #define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_REPEAT 10
  31. #define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_REPEAT 11
  32. // Push Constant
  33. layout(push_constant, binding = 0, std430) uniform DrawData {
  34. vec2 world_x;
  35. vec2 world_y;
  36. vec2 world_ofs;
  37. uint flags;
  38. uint specular_shininess;
  39. #ifdef USE_PRIMITIVE
  40. vec2 points[3];
  41. vec2 uvs[3];
  42. uint colors[6];
  43. #else
  44. vec4 modulation;
  45. vec4 ninepatch_margins;
  46. vec4 dst_rect; //for built-in rect and UV
  47. vec4 src_rect;
  48. vec2 pad;
  49. #endif
  50. vec2 color_texture_pixel_size;
  51. uint lights[4];
  52. }
  53. draw_data;
  54. // In vulkan, sets should always be ordered using the following logic:
  55. // Lower Sets: Sets that change format and layout less often
  56. // Higher sets: Sets that change format and layout very often
  57. // This is because changing a set for another with a different layout or format,
  58. // invalidates all the upper ones (as likely internal base offset changes)
  59. /* SET0: Globals */
  60. // The values passed per draw primitives are cached within it
  61. layout(set = 0, binding = 1, std140) uniform CanvasData {
  62. mat4 canvas_transform;
  63. mat4 screen_transform;
  64. mat4 canvas_normal_transform;
  65. vec4 canvas_modulation;
  66. vec2 screen_pixel_size;
  67. float time;
  68. bool use_pixel_snap;
  69. vec4 sdf_to_tex;
  70. vec2 screen_to_sdf;
  71. vec2 sdf_to_screen;
  72. uint directional_light_count;
  73. float tex_to_sdf;
  74. uint pad1;
  75. uint pad2;
  76. }
  77. canvas_data;
  78. #define LIGHT_FLAGS_BLEND_MASK (3 << 16)
  79. #define LIGHT_FLAGS_BLEND_MODE_ADD (0 << 16)
  80. #define LIGHT_FLAGS_BLEND_MODE_SUB (1 << 16)
  81. #define LIGHT_FLAGS_BLEND_MODE_MIX (2 << 16)
  82. #define LIGHT_FLAGS_BLEND_MODE_MASK (3 << 16)
  83. #define LIGHT_FLAGS_HAS_SHADOW (1 << 20)
  84. #define LIGHT_FLAGS_FILTER_SHIFT 22
  85. #define LIGHT_FLAGS_FILTER_MASK (3 << 22)
  86. #define LIGHT_FLAGS_SHADOW_NEAREST (0 << 22)
  87. #define LIGHT_FLAGS_SHADOW_PCF5 (1 << 22)
  88. #define LIGHT_FLAGS_SHADOW_PCF13 (2 << 22)
  89. struct Light {
  90. mat2x4 texture_matrix; //light to texture coordinate matrix (transposed)
  91. mat2x4 shadow_matrix; //light to shadow coordinate matrix (transposed)
  92. vec4 color;
  93. uint shadow_color; // packed
  94. uint flags; //index to light texture
  95. float shadow_pixel_size;
  96. float height;
  97. vec2 position;
  98. float shadow_zfar_inv;
  99. float shadow_y_ofs;
  100. vec4 atlas_rect;
  101. };
  102. layout(set = 0, binding = 2, std140) uniform LightData {
  103. Light data[MAX_LIGHTS];
  104. }
  105. light_array;
  106. layout(set = 0, binding = 3) uniform texture2D atlas_texture;
  107. layout(set = 0, binding = 4) uniform texture2D shadow_atlas_texture;
  108. layout(set = 0, binding = 5) uniform sampler shadow_sampler;
  109. layout(set = 0, binding = 6) uniform texture2D screen_texture;
  110. layout(set = 0, binding = 7) uniform texture2D sdf_texture;
  111. layout(set = 0, binding = 8) uniform sampler material_samplers[12];
  112. layout(set = 0, binding = 9, std430) restrict readonly buffer GlobalVariableData {
  113. vec4 data[];
  114. }
  115. global_variables;
  116. /* SET1: Is reserved for the material */
  117. //
  118. /* SET2: Instancing and Skeleton */
  119. layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
  120. vec4 data[];
  121. }
  122. transforms;
  123. /* SET3: Texture */
  124. layout(set = 3, binding = 0) uniform texture2D color_texture;
  125. layout(set = 3, binding = 1) uniform texture2D normal_texture;
  126. layout(set = 3, binding = 2) uniform texture2D specular_texture;
  127. layout(set = 3, binding = 3) uniform sampler texture_sampler;