2020-10-24 15:15:43 +00:00
|
|
|
|
|
|
|
#define MAX_LIGHTS_PER_ITEM 16
|
|
|
|
|
2019-07-05 01:54:32 +00:00
|
|
|
#define M_PI 3.14159265359
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2020-11-26 12:50:21 +00:00
|
|
|
#define SDF_MAX_LENGTH 16384.0
|
|
|
|
|
2021-05-10 16:12:44 +00:00
|
|
|
//1 means enabled, 2+ means trails in use
|
|
|
|
#define FLAGS_INSTANCING_MASK 0x7F
|
|
|
|
#define FLAGS_INSTANCING_HAS_COLORS (1 << 7)
|
|
|
|
#define FLAGS_INSTANCING_HAS_CUSTOM_DATA (1 << 8)
|
2019-06-16 02:45:24 +00:00
|
|
|
|
|
|
|
#define FLAGS_CLIP_RECT_UV (1 << 9)
|
|
|
|
#define FLAGS_TRANSPOSE_RECT (1 << 10)
|
2019-07-05 01:54:32 +00:00
|
|
|
#define FLAGS_USING_LIGHT_MASK (1 << 11)
|
2019-06-16 02:45:24 +00:00
|
|
|
#define FLAGS_NINEPACH_DRAW_CENTER (1 << 12)
|
|
|
|
#define FLAGS_USING_PARTICLES (1 << 13)
|
|
|
|
|
2019-06-19 20:03:19 +00:00
|
|
|
#define FLAGS_NINEPATCH_H_MODE_SHIFT 16
|
|
|
|
#define FLAGS_NINEPATCH_V_MODE_SHIFT 18
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2019-06-26 18:11:52 +00:00
|
|
|
#define FLAGS_LIGHT_COUNT_SHIFT 20
|
|
|
|
|
2019-07-05 01:54:32 +00:00
|
|
|
#define FLAGS_DEFAULT_NORMAL_MAP_USED (1 << 26)
|
|
|
|
#define FLAGS_DEFAULT_SPECULAR_MAP_USED (1 << 27)
|
|
|
|
|
2020-12-27 13:30:33 +00:00
|
|
|
#define FLAGS_USE_MSDF (1 << 28)
|
|
|
|
|
2020-11-26 12:50:21 +00:00
|
|
|
#define SAMPLER_NEAREST_CLAMP 0
|
|
|
|
#define SAMPLER_LINEAR_CLAMP 1
|
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP 2
|
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP 3
|
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_CLAMP 4
|
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_CLAMP 5
|
|
|
|
#define SAMPLER_NEAREST_REPEAT 6
|
|
|
|
#define SAMPLER_LINEAR_REPEAT 7
|
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_REPEAT 8
|
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT 9
|
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_REPEAT 10
|
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_REPEAT 11
|
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
// Push Constant
|
2019-07-27 13:23:24 +00:00
|
|
|
|
2019-06-24 19:13:06 +00:00
|
|
|
layout(push_constant, binding = 0, std430) uniform DrawData {
|
|
|
|
vec2 world_x;
|
|
|
|
vec2 world_y;
|
|
|
|
vec2 world_ofs;
|
|
|
|
uint flags;
|
|
|
|
uint specular_shininess;
|
|
|
|
#ifdef USE_PRIMITIVE
|
2019-06-26 18:11:52 +00:00
|
|
|
vec2 points[3];
|
|
|
|
vec2 uvs[3];
|
|
|
|
uint colors[6];
|
2019-06-24 19:13:06 +00:00
|
|
|
#else
|
2019-06-16 02:45:24 +00:00
|
|
|
vec4 modulation;
|
|
|
|
vec4 ninepatch_margins;
|
|
|
|
vec4 dst_rect; //for built-in rect and UV
|
|
|
|
vec4 src_rect;
|
2019-06-26 18:11:52 +00:00
|
|
|
vec2 pad;
|
|
|
|
|
2019-06-24 19:13:06 +00:00
|
|
|
#endif
|
2019-06-26 18:11:52 +00:00
|
|
|
vec2 color_texture_pixel_size;
|
|
|
|
uint lights[4];
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
draw_data;
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
// In vulkan, sets should always be ordered using the following logic:
|
|
|
|
// Lower Sets: Sets that change format and layout less often
|
|
|
|
// Higher sets: Sets that change format and layout very often
|
|
|
|
// This is because changing a set for another with a different layout or format,
|
|
|
|
// invalidates all the upper ones (as likely internal base offset changes)
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
/* SET0: Globals */
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
// The values passed per draw primitives are cached within it
|
2019-06-24 19:13:06 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
layout(set = 0, binding = 1, std140) uniform CanvasData {
|
2019-07-10 20:44:55 +00:00
|
|
|
mat4 canvas_transform;
|
|
|
|
mat4 screen_transform;
|
|
|
|
mat4 canvas_normal_transform;
|
|
|
|
vec4 canvas_modulation;
|
2019-07-21 14:31:30 +00:00
|
|
|
vec2 screen_pixel_size;
|
|
|
|
float time;
|
2020-10-29 21:09:16 +00:00
|
|
|
bool use_pixel_snap;
|
|
|
|
|
2020-11-26 12:50:21 +00:00
|
|
|
vec4 sdf_to_tex;
|
|
|
|
vec2 screen_to_sdf;
|
|
|
|
vec2 sdf_to_screen;
|
|
|
|
|
2020-11-03 19:51:53 +00:00
|
|
|
uint directional_light_count;
|
2020-11-26 12:50:21 +00:00
|
|
|
float tex_to_sdf;
|
2020-11-03 19:51:53 +00:00
|
|
|
uint pad1;
|
|
|
|
uint pad2;
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
canvas_data;
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2019-11-05 11:01:00 +00:00
|
|
|
#define LIGHT_FLAGS_BLEND_MASK (3 << 16)
|
|
|
|
#define LIGHT_FLAGS_BLEND_MODE_ADD (0 << 16)
|
|
|
|
#define LIGHT_FLAGS_BLEND_MODE_SUB (1 << 16)
|
|
|
|
#define LIGHT_FLAGS_BLEND_MODE_MIX (2 << 16)
|
|
|
|
#define LIGHT_FLAGS_BLEND_MODE_MASK (3 << 16)
|
|
|
|
#define LIGHT_FLAGS_HAS_SHADOW (1 << 20)
|
2019-07-07 04:49:40 +00:00
|
|
|
#define LIGHT_FLAGS_FILTER_SHIFT 22
|
2019-11-05 11:01:00 +00:00
|
|
|
#define LIGHT_FLAGS_FILTER_MASK (3 << 22)
|
|
|
|
#define LIGHT_FLAGS_SHADOW_NEAREST (0 << 22)
|
|
|
|
#define LIGHT_FLAGS_SHADOW_PCF5 (1 << 22)
|
|
|
|
#define LIGHT_FLAGS_SHADOW_PCF13 (2 << 22)
|
2019-07-05 01:54:32 +00:00
|
|
|
|
2019-06-16 02:45:24 +00:00
|
|
|
struct Light {
|
2019-11-14 23:32:54 +00:00
|
|
|
mat2x4 texture_matrix; //light to texture coordinate matrix (transposed)
|
2019-07-07 04:49:40 +00:00
|
|
|
mat2x4 shadow_matrix; //light to shadow coordinate matrix (transposed)
|
2019-07-05 01:54:32 +00:00
|
|
|
vec4 color;
|
2020-10-24 15:15:43 +00:00
|
|
|
|
|
|
|
uint shadow_color; // packed
|
2019-07-05 01:54:32 +00:00
|
|
|
uint flags; //index to light texture
|
|
|
|
float shadow_pixel_size;
|
2020-10-24 15:15:43 +00:00
|
|
|
float height;
|
|
|
|
|
|
|
|
vec2 position;
|
|
|
|
float shadow_zfar_inv;
|
|
|
|
float shadow_y_ofs;
|
|
|
|
|
|
|
|
vec4 atlas_rect;
|
2019-06-16 02:45:24 +00:00
|
|
|
};
|
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
layout(set = 0, binding = 2, std140) uniform LightData {
|
2019-07-10 20:44:55 +00:00
|
|
|
Light data[MAX_LIGHTS];
|
2020-02-11 13:01:43 +00:00
|
|
|
}
|
|
|
|
light_array;
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
layout(set = 0, binding = 3) uniform texture2D atlas_texture;
|
|
|
|
layout(set = 0, binding = 4) uniform texture2D shadow_atlas_texture;
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
layout(set = 0, binding = 5) uniform sampler shadow_sampler;
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
layout(set = 0, binding = 6) uniform texture2D screen_texture;
|
2020-11-26 12:50:21 +00:00
|
|
|
layout(set = 0, binding = 7) uniform texture2D sdf_texture;
|
2020-10-24 15:15:43 +00:00
|
|
|
|
2020-11-26 12:50:21 +00:00
|
|
|
layout(set = 0, binding = 8) uniform sampler material_samplers[12];
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-11-26 12:50:21 +00:00
|
|
|
layout(set = 0, binding = 9, std430) restrict readonly buffer GlobalVariableData {
|
2020-04-17 02:52:00 +00:00
|
|
|
vec4 data[];
|
|
|
|
}
|
|
|
|
global_variables;
|
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
/* SET1: Is reserved for the material */
|
2019-07-21 14:31:30 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
//
|
2019-07-08 12:53:40 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
/* SET2: Instancing and Skeleton */
|
2019-07-10 20:44:55 +00:00
|
|
|
|
2020-10-24 15:15:43 +00:00
|
|
|
layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
|
|
|
|
vec4 data[];
|
|
|
|
}
|
|
|
|
transforms;
|
|
|
|
|
|
|
|
/* SET3: Texture */
|
|
|
|
|
|
|
|
layout(set = 3, binding = 0) uniform texture2D color_texture;
|
|
|
|
layout(set = 3, binding = 1) uniform texture2D normal_texture;
|
|
|
|
layout(set = 3, binding = 2) uniform texture2D specular_texture;
|
|
|
|
layout(set = 3, binding = 3) uniform sampler texture_sampler;
|