2020-10-24 17:15:43 +02:00
|
|
|
|
|
|
|
#define MAX_LIGHTS_PER_ITEM 16
|
|
|
|
|
2019-07-05 03:54:32 +02:00
|
|
|
#define M_PI 3.14159265359
|
2019-06-16 04:45:24 +02:00
|
|
|
|
2020-11-26 13:50:21 +01:00
|
|
|
#define SDF_MAX_LENGTH 16384.0
|
|
|
|
|
2021-05-10 18:12:44 +02:00
|
|
|
//1 means enabled, 2+ means trails in use
|
|
|
|
#define FLAGS_INSTANCING_MASK 0x7F
|
2024-07-29 23:23:03 +02:00
|
|
|
#define FLAGS_INSTANCING_HAS_COLORS_SHIFT 7
|
|
|
|
#define FLAGS_INSTANCING_HAS_COLORS (1 << FLAGS_INSTANCING_HAS_COLORS_SHIFT)
|
|
|
|
#define FLAGS_INSTANCING_HAS_CUSTOM_DATA_SHIFT 8
|
|
|
|
#define FLAGS_INSTANCING_HAS_CUSTOM_DATA (1 << FLAGS_INSTANCING_HAS_CUSTOM_DATA_SHIFT)
|
2019-06-16 04:45:24 +02:00
|
|
|
|
|
|
|
#define FLAGS_CLIP_RECT_UV (1 << 9)
|
|
|
|
#define FLAGS_TRANSPOSE_RECT (1 << 10)
|
2023-08-03 14:10:01 +02:00
|
|
|
#define FLAGS_CONVERT_ATTRIBUTES_TO_LINEAR (1 << 11)
|
2024-07-29 23:23:03 +02:00
|
|
|
#define FLAGS_NINEPACH_DRAW_CENTER_SHIFT 12
|
|
|
|
#define FLAGS_NINEPACH_DRAW_CENTER (1 << FLAGS_NINEPACH_DRAW_CENTER_SHIFT)
|
2019-06-16 04:45:24 +02:00
|
|
|
|
2019-06-19 22:03:19 +02:00
|
|
|
#define FLAGS_NINEPATCH_H_MODE_SHIFT 16
|
|
|
|
#define FLAGS_NINEPATCH_V_MODE_SHIFT 18
|
2019-06-16 04:45:24 +02:00
|
|
|
|
2019-06-26 20:11:52 +02:00
|
|
|
#define FLAGS_LIGHT_COUNT_SHIFT 20
|
|
|
|
|
2019-07-05 03:54:32 +02:00
|
|
|
#define FLAGS_DEFAULT_NORMAL_MAP_USED (1 << 26)
|
|
|
|
#define FLAGS_DEFAULT_SPECULAR_MAP_USED (1 << 27)
|
|
|
|
|
2020-12-27 14:30:33 +01:00
|
|
|
#define FLAGS_USE_MSDF (1 << 28)
|
2022-08-12 13:03:28 +02:00
|
|
|
#define FLAGS_USE_LCD (1 << 29)
|
2020-12-27 14:30:33 +01:00
|
|
|
|
2023-01-14 07:20:42 +01:00
|
|
|
#define FLAGS_FLIP_H (1 << 30)
|
|
|
|
#define FLAGS_FLIP_V (1 << 31)
|
|
|
|
|
2024-07-29 23:23:03 +02:00
|
|
|
struct InstanceData {
|
2019-06-24 21:13:06 +02:00
|
|
|
vec2 world_x;
|
|
|
|
vec2 world_y;
|
|
|
|
vec2 world_ofs;
|
|
|
|
uint flags;
|
|
|
|
uint specular_shininess;
|
|
|
|
#ifdef USE_PRIMITIVE
|
2019-06-26 20:11:52 +02:00
|
|
|
vec2 points[3];
|
|
|
|
vec2 uvs[3];
|
|
|
|
uint colors[6];
|
2019-06-24 21:13:06 +02:00
|
|
|
#else
|
2019-06-16 04:45:24 +02:00
|
|
|
vec4 modulation;
|
|
|
|
vec4 ninepatch_margins;
|
|
|
|
vec4 dst_rect; //for built-in rect and UV
|
|
|
|
vec4 src_rect;
|
2019-06-26 20:11:52 +02:00
|
|
|
vec2 pad;
|
|
|
|
|
2019-06-24 21:13:06 +02:00
|
|
|
#endif
|
2019-06-26 20:11:52 +02:00
|
|
|
vec2 color_texture_pixel_size;
|
|
|
|
uint lights[4];
|
2024-07-29 23:23:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
layout(push_constant, std430) uniform Params {
|
|
|
|
uint base_instance_index; // base index to instance data
|
|
|
|
uint pad1;
|
|
|
|
uint pad2;
|
|
|
|
uint pad3;
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
2024-07-29 23:23:03 +02:00
|
|
|
params;
|
2019-06-16 04:45:24 +02:00
|
|
|
|
2020-10-24 17:15:43 +02: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 16:31:30 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
/* SET0: Globals */
|
2019-07-21 16:31:30 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
// The values passed per draw primitives are cached within it
|
2019-06-24 21:13:06 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
layout(set = 0, binding = 1, std140) uniform CanvasData {
|
2019-07-10 22:44:55 +02:00
|
|
|
mat4 canvas_transform;
|
|
|
|
mat4 screen_transform;
|
|
|
|
mat4 canvas_normal_transform;
|
|
|
|
vec4 canvas_modulation;
|
2019-07-21 16:31:30 +02:00
|
|
|
vec2 screen_pixel_size;
|
|
|
|
float time;
|
2020-10-29 22:09:16 +01:00
|
|
|
bool use_pixel_snap;
|
|
|
|
|
2020-11-26 13:50:21 +01:00
|
|
|
vec4 sdf_to_tex;
|
|
|
|
vec2 screen_to_sdf;
|
|
|
|
vec2 sdf_to_screen;
|
|
|
|
|
2020-11-03 20:51:53 +01:00
|
|
|
uint directional_light_count;
|
2020-11-26 13:50:21 +01:00
|
|
|
float tex_to_sdf;
|
2020-11-03 20:51:53 +01:00
|
|
|
uint pad1;
|
|
|
|
uint pad2;
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
|
|
|
canvas_data;
|
2019-06-16 04:45:24 +02:00
|
|
|
|
2019-11-05 12:01:00 +01: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 06:49:40 +02:00
|
|
|
#define LIGHT_FLAGS_FILTER_SHIFT 22
|
2019-11-05 12:01:00 +01: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 03:54:32 +02:00
|
|
|
|
2019-06-16 04:45:24 +02:00
|
|
|
struct Light {
|
2019-11-15 00:32:54 +01:00
|
|
|
mat2x4 texture_matrix; //light to texture coordinate matrix (transposed)
|
2019-07-07 06:49:40 +02:00
|
|
|
mat2x4 shadow_matrix; //light to shadow coordinate matrix (transposed)
|
2019-07-05 03:54:32 +02:00
|
|
|
vec4 color;
|
2020-10-24 17:15:43 +02:00
|
|
|
|
|
|
|
uint shadow_color; // packed
|
2019-07-05 03:54:32 +02:00
|
|
|
uint flags; //index to light texture
|
|
|
|
float shadow_pixel_size;
|
2020-10-24 17:15:43 +02:00
|
|
|
float height;
|
|
|
|
|
|
|
|
vec2 position;
|
|
|
|
float shadow_zfar_inv;
|
|
|
|
float shadow_y_ofs;
|
|
|
|
|
|
|
|
vec4 atlas_rect;
|
2019-06-16 04:45:24 +02:00
|
|
|
};
|
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
layout(set = 0, binding = 2, std140) uniform LightData {
|
2019-07-10 22:44:55 +02:00
|
|
|
Light data[MAX_LIGHTS];
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
|
|
|
light_array;
|
2019-06-16 04:45:24 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
layout(set = 0, binding = 3) uniform texture2D atlas_texture;
|
|
|
|
layout(set = 0, binding = 4) uniform texture2D shadow_atlas_texture;
|
2019-07-21 16:31:30 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
layout(set = 0, binding = 5) uniform sampler shadow_sampler;
|
2019-07-21 16:31:30 +02:00
|
|
|
|
2023-01-05 20:55:59 +01:00
|
|
|
layout(set = 0, binding = 6) uniform texture2D color_buffer;
|
2020-11-26 13:50:21 +01:00
|
|
|
layout(set = 0, binding = 7) uniform texture2D sdf_texture;
|
2020-10-24 17:15:43 +02:00
|
|
|
|
2023-05-26 23:35:16 +02:00
|
|
|
#include "samplers_inc.glsl"
|
2019-07-21 16:31:30 +02:00
|
|
|
|
2022-04-03 18:56:43 +02:00
|
|
|
layout(set = 0, binding = 9, std430) restrict readonly buffer GlobalShaderUniformData {
|
2020-04-17 04:52:00 +02:00
|
|
|
vec4 data[];
|
|
|
|
}
|
2022-04-03 18:56:43 +02:00
|
|
|
global_shader_uniforms;
|
2020-04-17 04:52:00 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
/* SET1: Is reserved for the material */
|
2019-07-21 16:31:30 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
//
|
2019-07-08 14:53:40 +02:00
|
|
|
|
2020-10-24 17:15:43 +02:00
|
|
|
/* SET2: Instancing and Skeleton */
|
2019-07-10 22:44:55 +02:00
|
|
|
|
2020-10-24 17:15:43 +02: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;
|
2024-09-27 20:05:46 +02:00
|
|
|
|
|
|
|
layout(set = 3, binding = 4, std430) restrict readonly buffer DrawData {
|
|
|
|
InstanceData data[];
|
|
|
|
}
|
|
|
|
instances;
|