canvas_uniforms_inc.glsl 4.3 KB

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