2021-11-16 16:25:42 +01:00
|
|
|
/* clang-format off */
|
2021-11-13 12:54:58 +01:00
|
|
|
#[modes]
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
mode_quad =
|
2021-11-16 16:25:42 +01:00
|
|
|
mode_ninepatch = #define USE_NINEPATCH
|
|
|
|
mode_primitive = #define USE_PRIMITIVE
|
|
|
|
mode_attributes = #define USE_ATTRIBUTES
|
2022-05-25 22:19:45 +02:00
|
|
|
mode_instanced = #define USE_ATTRIBUTES \n#define USE_INSTANCING
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#[specializations]
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
DISABLE_LIGHTING = false
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#[vertex]
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_ATTRIBUTES
|
2021-11-16 16:25:42 +01:00
|
|
|
layout(location = 0) in vec2 vertex_attrib;
|
2021-10-26 17:18:39 +02:00
|
|
|
layout(location = 3) in vec4 color_attrib;
|
|
|
|
layout(location = 4) in vec2 uv_attrib;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
layout(location = 10) in uvec4 bone_attrib;
|
|
|
|
layout(location = 11) in vec4 weight_attrib;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-05-25 22:19:45 +02:00
|
|
|
#ifdef USE_INSTANCING
|
|
|
|
|
2022-06-15 05:55:07 +02:00
|
|
|
layout(location = 1) in highp vec4 instance_xform0;
|
|
|
|
layout(location = 2) in highp vec4 instance_xform1;
|
|
|
|
layout(location = 5) in highp uvec4 instance_color_custom_data; // Color packed into xy, custom_data packed into zw for compatibility with 3D
|
2022-05-25 22:19:45 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-04-30 00:34:01 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// This needs to be outside clang-format so the ubo comment is in the right place
|
|
|
|
#ifdef MATERIAL_UNIFORMS_USED
|
|
|
|
layout(std140) uniform MaterialUniforms{ //ubo:4
|
|
|
|
|
|
|
|
#MATERIAL_UNIFORMS
|
|
|
|
|
|
|
|
};
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
2021-11-16 16:25:42 +01:00
|
|
|
/* clang-format on */
|
2021-11-13 12:54:58 +01:00
|
|
|
#include "canvas_uniforms_inc.glsl"
|
2021-11-16 16:25:42 +01:00
|
|
|
#include "stdlib_inc.glsl"
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
uniform sampler2D transforms_texture; //texunit:-1
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
out vec2 uv_interp;
|
|
|
|
out vec4 color_interp;
|
|
|
|
out vec2 vertex_interp;
|
2021-11-16 16:25:42 +01:00
|
|
|
flat out int draw_data_instance;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_NINEPATCH
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
out vec2 pixel_size_interp;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#GLOBALS
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
void main() {
|
|
|
|
vec4 instance_custom = vec4(0.0);
|
2021-11-16 16:25:42 +01:00
|
|
|
draw_data_instance = gl_InstanceID;
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_PRIMITIVE
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
//weird bug,
|
|
|
|
//this works
|
|
|
|
vec2 vertex;
|
|
|
|
vec2 uv;
|
|
|
|
vec4 color;
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
if (gl_VertexID == 0) {
|
|
|
|
vertex = draw_data[draw_data_instance].point_a;
|
|
|
|
uv = draw_data[draw_data_instance].uv_a;
|
|
|
|
color = vec4(unpackHalf2x16(draw_data[draw_data_instance].color_a_rg), unpackHalf2x16(draw_data[draw_data_instance].color_a_ba));
|
|
|
|
} else if (gl_VertexID == 1) {
|
|
|
|
vertex = draw_data[draw_data_instance].point_b;
|
|
|
|
uv = draw_data[draw_data_instance].uv_b;
|
|
|
|
color = vec4(unpackHalf2x16(draw_data[draw_data_instance].color_b_rg), unpackHalf2x16(draw_data[draw_data_instance].color_b_ba));
|
2021-11-13 12:54:58 +01:00
|
|
|
} else {
|
2021-11-16 16:25:42 +01:00
|
|
|
vertex = draw_data[draw_data_instance].point_c;
|
|
|
|
uv = draw_data[draw_data_instance].uv_c;
|
|
|
|
color = vec4(unpackHalf2x16(draw_data[draw_data_instance].color_c_rg), unpackHalf2x16(draw_data[draw_data_instance].color_c_ba));
|
2021-11-13 12:54:58 +01:00
|
|
|
}
|
|
|
|
uvec4 bones = uvec4(0, 0, 0, 0);
|
|
|
|
vec4 bone_weights = vec4(0.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#elif defined(USE_ATTRIBUTES)
|
2022-05-25 22:19:45 +02:00
|
|
|
#ifdef USE_INSTANCING
|
|
|
|
draw_data_instance = 0;
|
|
|
|
#endif
|
2021-11-13 12:54:58 +01:00
|
|
|
vec2 vertex = vertex_attrib;
|
2021-11-16 16:25:42 +01:00
|
|
|
vec4 color = color_attrib * draw_data[draw_data_instance].modulation;
|
2021-11-13 12:54:58 +01:00
|
|
|
vec2 uv = uv_attrib;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
uvec4 bones = bone_attrib;
|
|
|
|
vec4 bone_weights = weight_attrib;
|
2022-05-25 22:19:45 +02:00
|
|
|
|
|
|
|
#ifdef USE_INSTANCING
|
2022-06-15 05:55:07 +02:00
|
|
|
vec4 instance_color = vec4(unpackHalf2x16(instance_color_custom_data.x), unpackHalf2x16(instance_color_custom_data.y));
|
2022-05-25 22:19:45 +02:00
|
|
|
color *= instance_color;
|
2022-06-15 05:55:07 +02:00
|
|
|
instance_custom = vec4(unpackHalf2x16(instance_color_custom_data.z), unpackHalf2x16(instance_color_custom_data.w));
|
2022-05-25 22:19:45 +02:00
|
|
|
#endif
|
|
|
|
|
2020-11-18 19:11:30 +01:00
|
|
|
#else
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
vec2 vertex_base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0));
|
2021-11-16 16:25:42 +01:00
|
|
|
vec2 vertex_base = vertex_base_arr[gl_VertexID];
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
vec2 uv = draw_data[draw_data_instance].src_rect.xy + abs(draw_data[draw_data_instance].src_rect.zw) * ((draw_data[draw_data_instance].flags & FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy);
|
|
|
|
vec4 color = draw_data[draw_data_instance].modulation;
|
|
|
|
vec2 vertex = draw_data[draw_data_instance].dst_rect.xy + abs(draw_data[draw_data_instance].dst_rect.zw) * mix(vertex_base, vec2(1.0, 1.0) - vertex_base, lessThan(draw_data[draw_data_instance].src_rect.zw, vec2(0.0, 0.0)));
|
2021-11-13 12:54:58 +01:00
|
|
|
uvec4 bones = uvec4(0, 0, 0, 0);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-03-18 10:10:55 +01:00
|
|
|
mat4 model_matrix = mat4(vec4(draw_data[draw_data_instance].world_x, 0.0, 0.0), vec4(draw_data[draw_data_instance].world_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(draw_data[draw_data_instance].world_ofs, 0.0, 1.0));
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-05-25 22:19:45 +02:00
|
|
|
#ifdef USE_INSTANCING
|
|
|
|
model_matrix = model_matrix * transpose(mat4(instance_xform0, instance_xform1, vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)));
|
|
|
|
#endif // USE_INSTANCING
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#if !defined(USE_ATTRIBUTES) && !defined(USE_PRIMITIVE)
|
2021-11-16 16:25:42 +01:00
|
|
|
if (bool(draw_data[draw_data_instance].flags & FLAGS_USING_PARTICLES)) {
|
2021-11-13 12:54:58 +01:00
|
|
|
//scale by texture size
|
2021-11-16 16:25:42 +01:00
|
|
|
vertex /= draw_data[draw_data_instance].color_texture_pixel_size;
|
2021-11-13 12:54:58 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_POINT_SIZE
|
2020-11-18 19:11:30 +01:00
|
|
|
float point_size = 1.0;
|
2021-11-13 12:54:58 +01:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
{
|
2021-11-13 12:54:58 +01:00
|
|
|
#CODE : VERTEX
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_NINEPATCH
|
2021-11-16 16:25:42 +01:00
|
|
|
pixel_size_interp = abs(draw_data[draw_data_instance].dst_rect.zw) * vertex_base;
|
2021-11-13 12:54:58 +01:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#if !defined(SKIP_TRANSFORM_USED)
|
2022-03-18 10:10:55 +01:00
|
|
|
vertex = (model_matrix * vec4(vertex, 0.0, 1.0)).xy;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
color_interp = color;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
if (use_pixel_snap) {
|
2021-11-13 12:54:58 +01:00
|
|
|
vertex = floor(vertex + 0.5);
|
|
|
|
// precision issue on some hardware creates artifacts within texture
|
|
|
|
// offset uv by a small amount to avoid
|
|
|
|
uv += 1e-5;
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_ATTRIBUTES
|
|
|
|
#if 0
|
2021-11-16 16:25:42 +01:00
|
|
|
if (bool(draw_data[draw_data_instance].flags & FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone
|
2021-11-13 12:54:58 +01:00
|
|
|
//skeleton transform
|
|
|
|
ivec4 bone_indicesi = ivec4(bone_indices);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
uvec2 tex_ofs = bone_indicesi.x * 2;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
mat2x4 m;
|
|
|
|
m = mat2x4(
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 0),
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 1)) *
|
|
|
|
bone_weights.x;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
tex_ofs = bone_indicesi.y * 2;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
m += mat2x4(
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 0),
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 1)) *
|
|
|
|
bone_weights.y;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
tex_ofs = bone_indicesi.z * 2;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
m += mat2x4(
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 0),
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 1)) *
|
|
|
|
bone_weights.z;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
tex_ofs = bone_indicesi.w * 2;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
m += mat2x4(
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 0),
|
|
|
|
texelFetch(skeleton_buffer, tex_ofs + 1)) *
|
|
|
|
bone_weights.w;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
mat4 bone_matrix = skeleton_data.skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_data.skeleton_transform_inverse;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
//outvec = bone_matrix * outvec;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
vertex = (canvas_transform * vec4(vertex, 0.0, 1.0)).xy;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
vertex_interp = vertex;
|
|
|
|
uv_interp = uv;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
gl_Position = screen_transform * vec4(vertex, 0.0, 1.0);
|
2021-11-13 12:54:58 +01:00
|
|
|
|
|
|
|
#ifdef USE_POINT_SIZE
|
|
|
|
gl_PointSize = point_size;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
2021-11-13 12:54:58 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#[fragment]
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#include "canvas_uniforms_inc.glsl"
|
2021-11-16 16:25:42 +01:00
|
|
|
#include "stdlib_inc.glsl"
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-09-06 23:42:08 +02:00
|
|
|
//uniform sampler2D atlas_texture; //texunit:-2
|
|
|
|
//uniform sampler2D shadow_atlas_texture; //texunit:-3
|
2021-11-13 12:54:58 +01:00
|
|
|
uniform sampler2D screen_texture; //texunit:-4
|
|
|
|
uniform sampler2D sdf_texture; //texunit:-5
|
|
|
|
uniform sampler2D normal_texture; //texunit:-6
|
|
|
|
uniform sampler2D specular_texture; //texunit:-7
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
uniform sampler2D color_texture; //texunit:0
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
in vec2 uv_interp;
|
|
|
|
in vec4 color_interp;
|
|
|
|
in vec2 vertex_interp;
|
2021-11-16 16:25:42 +01:00
|
|
|
flat in int draw_data_instance;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_NINEPATCH
|
|
|
|
|
|
|
|
in vec2 pixel_size_interp;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
|
|
|
#ifdef MATERIAL_UNIFORMS_USED
|
2022-02-20 01:08:53 +01:00
|
|
|
layout(std140) uniform MaterialUniforms{
|
2021-11-13 12:54:58 +01:00
|
|
|
//ubo:4
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#MATERIAL_UNIFORMS
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
};
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#GLOBALS
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef USE_NINEPATCH
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, float margin_begin, float margin_end, int np_repeat, inout int draw_center) {
|
|
|
|
float tex_size = 1.0 / tex_pixel_size;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
if (pixel < margin_begin) {
|
|
|
|
return pixel * tex_pixel_size;
|
|
|
|
} else if (pixel >= draw_size - margin_end) {
|
|
|
|
return (tex_size - (draw_size - pixel)) * tex_pixel_size;
|
|
|
|
} else {
|
2021-11-16 16:25:42 +01:00
|
|
|
if (!bool(draw_data[draw_data_instance].flags & FLAGS_NINEPACH_DRAW_CENTER)) {
|
2021-11-13 12:54:58 +01:00
|
|
|
draw_center--;
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
// np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum.
|
|
|
|
if (np_repeat == 0) { // Stretch.
|
|
|
|
// Convert to ratio.
|
|
|
|
float ratio = (pixel - margin_begin) / (draw_size - margin_begin - margin_end);
|
|
|
|
// Scale to source texture.
|
|
|
|
return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size;
|
|
|
|
} else if (np_repeat == 1) { // Tile.
|
|
|
|
// Convert to offset.
|
|
|
|
float ofs = mod((pixel - margin_begin), tex_size - margin_begin - margin_end);
|
|
|
|
// Scale to source texture.
|
|
|
|
return (margin_begin + ofs) * tex_pixel_size;
|
|
|
|
} else if (np_repeat == 2) { // Tile Fit.
|
|
|
|
// Calculate scale.
|
|
|
|
float src_area = draw_size - margin_begin - margin_end;
|
|
|
|
float dst_area = tex_size - margin_begin - margin_end;
|
|
|
|
float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5));
|
|
|
|
// Convert to ratio.
|
|
|
|
float ratio = (pixel - margin_begin) / src_area;
|
|
|
|
ratio = mod(ratio * scale, 1.0);
|
|
|
|
// Scale to source texture.
|
|
|
|
return (margin_begin + ratio * dst_area) * tex_pixel_size;
|
|
|
|
} else { // Shouldn't happen, but silences compiler warning.
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
float msdf_median(float r, float g, float b, float a) {
|
|
|
|
return min(max(min(r, g), min(max(r, g), b)), a);
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
vec4 color = color_interp;
|
|
|
|
vec2 uv = uv_interp;
|
2021-11-13 12:54:58 +01:00
|
|
|
vec2 vertex = vertex_interp;
|
|
|
|
|
|
|
|
#if !defined(USE_ATTRIBUTES) && !defined(USE_PRIMITIVE)
|
|
|
|
|
|
|
|
#ifdef USE_NINEPATCH
|
|
|
|
|
|
|
|
int draw_center = 2;
|
|
|
|
uv = vec2(
|
2021-11-16 16:25:42 +01:00
|
|
|
map_ninepatch_axis(pixel_size_interp.x, abs(draw_data[draw_data_instance].dst_rect.z), draw_data[draw_data_instance].color_texture_pixel_size.x, draw_data[draw_data_instance].ninepatch_margins.x, draw_data[draw_data_instance].ninepatch_margins.z, int(draw_data[draw_data_instance].flags >> FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center),
|
|
|
|
map_ninepatch_axis(pixel_size_interp.y, abs(draw_data[draw_data_instance].dst_rect.w), draw_data[draw_data_instance].color_texture_pixel_size.y, draw_data[draw_data_instance].ninepatch_margins.y, draw_data[draw_data_instance].ninepatch_margins.w, int(draw_data[draw_data_instance].flags >> FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center));
|
2021-11-13 12:54:58 +01:00
|
|
|
|
|
|
|
if (draw_center == 0) {
|
|
|
|
color.a = 0.0;
|
|
|
|
}
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
uv = uv * draw_data[draw_data_instance].src_rect.zw + draw_data[draw_data_instance].src_rect.xy; //apply region if needed
|
2021-11-13 12:54:58 +01:00
|
|
|
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
2021-11-16 16:25:42 +01:00
|
|
|
if (bool(draw_data[draw_data_instance].flags & FLAGS_CLIP_RECT_UV)) {
|
|
|
|
uv = clamp(uv, draw_data[draw_data_instance].src_rect.xy, draw_data[draw_data_instance].src_rect.xy + abs(draw_data[draw_data_instance].src_rect.zw));
|
2021-11-13 12:54:58 +01:00
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifndef USE_PRIMITIVE
|
2021-11-16 16:25:42 +01:00
|
|
|
if (bool(draw_data[draw_data_instance].flags & FLAGS_USE_MSDF)) {
|
|
|
|
float px_range = draw_data[draw_data_instance].ninepatch_margins.x;
|
|
|
|
float outline_thickness = draw_data[draw_data_instance].ninepatch_margins.y;
|
|
|
|
//float reserved1 = draw_data[draw_data_instance].ninepatch_margins.z;
|
|
|
|
//float reserved2 = draw_data[draw_data_instance].ninepatch_margins.w;
|
|
|
|
|
|
|
|
vec4 msdf_sample = texture(color_texture, uv);
|
|
|
|
vec2 msdf_size = vec2(textureSize(color_texture, 0));
|
2021-11-13 12:54:58 +01:00
|
|
|
vec2 dest_size = vec2(1.0) / fwidth(uv);
|
|
|
|
float px_size = max(0.5 * dot((vec2(px_range) / msdf_size), dest_size), 1.0);
|
|
|
|
float d = msdf_median(msdf_sample.r, msdf_sample.g, msdf_sample.b, msdf_sample.a) - 0.5;
|
|
|
|
|
2022-05-10 19:02:44 +02:00
|
|
|
if (outline_thickness > 0.0) {
|
|
|
|
float cr = clamp(outline_thickness, 0.0, px_range / 2.0) / px_range;
|
2021-11-13 12:54:58 +01:00
|
|
|
float a = clamp((d + cr) * px_size, 0.0, 1.0);
|
|
|
|
color.a = a * color.a;
|
|
|
|
} else {
|
|
|
|
float a = clamp(d * px_size + 0.5, 0.0, 1.0);
|
|
|
|
color.a = a * color.a;
|
|
|
|
}
|
2022-08-12 13:03:28 +02:00
|
|
|
} else if (bool(draw_data[draw_data_instance].flags & FLAGS_USE_LCD)) {
|
|
|
|
vec4 lcd_sample = texture(color_texture, uv);
|
|
|
|
if (lcd_sample.a == 1.0) {
|
|
|
|
color.rgb = lcd_sample.rgb * color.a;
|
|
|
|
} else {
|
|
|
|
color = vec4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
}
|
2021-11-13 12:54:58 +01:00
|
|
|
} else {
|
|
|
|
#else
|
|
|
|
{
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
2021-11-16 16:25:42 +01:00
|
|
|
color *= texture(color_texture, uv);
|
2021-11-13 12:54:58 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 23:42:08 +02:00
|
|
|
bool using_light = false;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
vec3 normal;
|
|
|
|
|
|
|
|
#if defined(NORMAL_USED)
|
|
|
|
bool normal_used = true;
|
|
|
|
#else
|
|
|
|
bool normal_used = false;
|
|
|
|
#endif
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
if (normal_used || (using_light && bool(draw_data[draw_data_instance].flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) {
|
|
|
|
normal.xy = texture(normal_texture, uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
|
|
|
|
normal_used = true;
|
|
|
|
} else {
|
|
|
|
normal = vec3(0.0, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
vec4 specular_shininess;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#if defined(SPECULAR_SHININESS_USED)
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
bool specular_shininess_used = true;
|
2020-11-18 19:11:30 +01:00
|
|
|
#else
|
2021-11-13 12:54:58 +01:00
|
|
|
bool specular_shininess_used = false;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-16 16:25:42 +01:00
|
|
|
if (specular_shininess_used || (using_light && normal_used && bool(draw_data[draw_data_instance].flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) {
|
|
|
|
specular_shininess = texture(specular_texture, uv);
|
|
|
|
specular_shininess *= unpackUnorm4x8(draw_data[draw_data_instance].specular_shininess);
|
2021-11-13 12:54:58 +01:00
|
|
|
specular_shininess_used = true;
|
|
|
|
} else {
|
|
|
|
specular_shininess = vec4(1.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(SCREEN_UV_USED)
|
2021-11-16 16:25:42 +01:00
|
|
|
vec2 screen_uv = gl_FragCoord.xy * screen_pixel_size;
|
2021-11-13 12:54:58 +01:00
|
|
|
#else
|
|
|
|
vec2 screen_uv = vec2(0.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
vec3 light_vertex = vec3(vertex, 0.0);
|
|
|
|
vec2 shadow_vertex = vertex;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
{
|
|
|
|
float normal_map_depth = 1.0;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#if defined(NORMAL_MAP_USED)
|
|
|
|
vec3 normal_map = vec3(0.0, 0.0, 1.0);
|
|
|
|
normal_used = true;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#CODE : FRAGMENT
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#if defined(NORMAL_MAP_USED)
|
|
|
|
normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_map_depth);
|
|
|
|
#endif
|
|
|
|
}
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-11-13 12:54:58 +01:00
|
|
|
#ifdef MODE_LIGHT_ONLY
|
|
|
|
color = vec4(0.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
#else
|
2021-11-16 16:25:42 +01:00
|
|
|
color *= canvas_modulation;
|
2021-11-13 12:54:58 +01:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
frag_color = color;
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|