canvas_uniforms_inc.glsl 3.8 KB

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