new workspace

This commit is contained in:
galister
2025-06-18 01:14:04 +09:00
parent 95f2ae4296
commit f05d3a8251
252 changed files with 24618 additions and 184 deletions

View File

@@ -0,0 +1,5 @@
layout(std140, set = MODEL_BUFFER_SET,
binding = 0) readonly buffer ModelBuffer {
mat4 models[];
}
model_buffer;

View File

@@ -0,0 +1,54 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
precision highp float;
layout(location = 0) in vec4 in_color;
layout(location = 1) in vec4 in_color2;
layout(location = 2) in vec2 in_uv;
layout(location = 3) in vec4 in_border_color;
layout(location = 4) in float in_border_size; // in units
layout(location = 5) in float in_radius; // in units
layout(location = 6) in vec2 in_rect_size;
layout(location = 0) out vec4 out_color;
#define UNIFORM_PARAMS_SET 0
#include "uniform.glsl"
void main() {
float rect_aspect = in_rect_size.x / in_rect_size.y;
vec2 center = in_rect_size / 2.0;
vec2 coords = in_uv * in_rect_size;
float radius = in_radius;
vec2 sdf_rect_dim = center - vec2(radius);
float sdf = length(max(abs(coords - center), sdf_rect_dim) - sdf_rect_dim) -
in_radius;
vec4 color =
mix(in_color, in_color2, min(length((in_uv - vec2(0.5)) * 2.0), 1.0));
float pixel_size = 1.0 / uniforms.pixel_scale;
if (in_border_size < in_radius) {
// rounded border
float f = in_border_size > 0.0 ? smoothstep(in_border_size + pixel_size,
in_border_size, -sdf) *
in_border_color.a
: 0.0;
out_color = mix(color, in_border_color, f);
} else {
// square border
vec2 a = abs(coords - center);
float aa = center.x - in_border_size;
float bb = center.y - in_border_size;
out_color = (a.x > aa || a.y > bb) ? in_border_color : color;
}
if (in_radius > 0.0) {
// rounding cutout alpha
out_color.a *= 1.0 - smoothstep(-pixel_size, 0.0, sdf);
}
}

View File

@@ -0,0 +1,93 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
precision highp float;
layout(location = 0) in uint in_model_idx;
layout(location = 1) in uint in_rect_dim;
layout(location = 2) in uint in_color;
layout(location = 3) in uint in_color2;
layout(location = 4) in uint in_border_color;
layout(location = 5) in uint round_border_gradient;
layout(location = 6) in float depth;
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_color2;
layout(location = 2) out vec2 out_uv;
layout(location = 3) out vec4 out_border_color;
layout(location = 4) out float out_border_size;
layout(location = 5) out float out_radius;
layout(location = 6) out vec2 out_rect_size;
#define UNIFORM_PARAMS_SET 0
#define MODEL_BUFFER_SET 1
#include "model_buffer.glsl"
#include "uniform.glsl"
void main() {
uint v = uint(gl_VertexIndex); // 0-3
uint rect_width = in_rect_dim & 0xffffu;
uint rect_height = (in_rect_dim & 0xffff0000u) >> 16u;
vec2 rect_size = vec2(float(rect_width), float(rect_height));
float rect_aspect = rect_size.x / rect_size.y;
// 0.0 - 1.0 normalized
uvec2 corner_pos_u = uvec2(v & 1u, (v >> 1u) & 1u);
vec2 corner_pos = vec2(corner_pos_u);
out_uv = corner_pos;
mat4 model_matrix = model_buffer.models[in_model_idx];
out_rect_size = rect_size;
gl_Position =
uniforms.projection * model_matrix * vec4(corner_pos, depth, 1.0);
out_border_color =
vec4(float((in_border_color & 0x00ff0000u) >> 16u) / 255.0,
float((in_border_color & 0x0000ff00u) >> 8u) / 255.0,
float(in_border_color & 0x000000ffu) / 255.0,
float((in_border_color & 0xff000000u) >> 24u) / 255.0);
float radius = float(round_border_gradient & 0xffu);
out_radius = radius;
float border_size = float((round_border_gradient & 0xff00u) >> 8);
out_border_size = border_size;
uint gradient_mode = (round_border_gradient & 0x00ff0000u) >> 16;
uint color;
uint color2;
switch (gradient_mode) {
case 1:
// horizontal
color = corner_pos_u.x > 0u ? in_color2 : in_color;
color2 = color;
break;
case 2:
// vertical
color = corner_pos_u.y > 0u ? in_color2 : in_color;
color2 = color;
break;
case 3:
// radial
color = in_color;
color2 = in_color2;
break;
default: // none
color = in_color;
color2 = in_color;
break;
}
out_color = vec4(float((color & 0x00ff0000u) >> 16u) / 255.0,
float((color & 0x0000ff00u) >> 8u) / 255.0,
float(color & 0x000000ffu) / 255.0,
float((color & 0xff000000u) >> 24u) / 255.0);
out_color2 = vec4(float((color2 & 0x00ff0000u) >> 16u) / 255.0,
float((color2 & 0x0000ff00u) >> 8u) / 255.0,
float(color2 & 0x000000ffu) / 255.0,
float((color2 & 0xff000000u) >> 24u) / 255.0);
}

View File

@@ -0,0 +1,22 @@
struct StylesData {
float radius;
vec4 color0;
vec4 color1;
uint gradient_style;
vec2 gradient_curve;
vec4 border_size_tlbr;
vec4 border_color0;
vec4 border_color1;
vec4 border_color2;
vec4 border_color3;
uint border_gradient_style;
vec2 border_gradient_curve;
}
layout(std140, set = STYLES_BUFFER_SET,
binding = 0) readonly buffer StylesBuffer {
StylesData styles[];
}
styles_buffer;

View File

@@ -0,0 +1,22 @@
#version 310 es
#extension GL_GOOGLE_include_directive : enable
precision highp float;
layout(location = 0) in vec4 in_color;
layout(location = 1) in vec2 in_uv;
layout(location = 2) flat in uint in_content_type;
layout(location = 0) out vec4 out_color;
layout(set = 0, binding = 0) uniform sampler2D color_atlas;
layout(set = 1, binding = 0) uniform sampler2D mask_atlas;
void main() {
if (in_content_type == 0u) {
out_color = texture(color_atlas, in_uv);
} else {
out_color.rgb = in_color.rgb;
out_color.a = in_color.a * texture(mask_atlas, in_uv).r;
}
}

View File

@@ -0,0 +1,61 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
precision highp float;
layout(location = 0) in uint in_model_idx;
layout(location = 1) in uint in_rect_dim;
layout(location = 2) in uint in_uv;
layout(location = 3) in uint in_color;
layout(location = 4) in uint in_content_type;
layout(location = 5) in float depth;
layout(location = 7) in float scale;
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec2 out_uv;
layout(location = 2) flat out uint out_content_type;
layout(set = 0, binding = 0) uniform sampler2D color_atlas;
layout(set = 1, binding = 0) uniform sampler2D mask_atlas;
#define UNIFORM_PARAMS_SET 2
#define MODEL_BUFFER_SET 3
#include "model_buffer.glsl"
#include "uniform.glsl"
void main() {
uint v = uint(gl_VertexIndex); // 0-3
uint rect_width = in_rect_dim & 0xffffu;
uint rect_height = (in_rect_dim & 0xffff0000u) >> 16u;
vec2 rect_size = vec2(float(rect_width), float(rect_height));
float rect_aspect = rect_size.x / rect_size.y;
uvec2 uv = uvec2(in_uv & 0xffffu, (in_uv & 0xffff0000u) >> 16u);
uvec2 corner_pos_u = uvec2(v & 1u, (v >> 1u) & 1u);
vec2 corner_pos = vec2(corner_pos_u);
uvec2 corner_offset = uvec2(rect_width, rect_height) * corner_pos_u;
uv = uv + corner_offset;
mat4 model_matrix = model_buffer.models[in_model_idx];
gl_Position =
uniforms.projection * model_matrix * vec4(corner_pos * scale, depth, 1.0);
out_content_type = in_content_type & 0xffffu;
out_color = vec4(float((in_color & 0x00ff0000u) >> 16u) / 255.0,
float((in_color & 0x0000ff00u) >> 8u) / 255.0,
float(in_color & 0x000000ffu) / 255.0,
float((in_color & 0xff000000u) >> 24u) / 255.0);
uvec2 dim = uvec2(0, 0);
if (in_content_type == 0u) {
dim = uvec2(textureSize(color_atlas, 0));
} else {
dim = uvec2(textureSize(mask_atlas, 0));
}
out_uv = vec2(uv) / vec2(dim);
}

View File

@@ -0,0 +1,8 @@
// Viewport
layout(std140, set = UNIFORM_PARAMS_SET, binding = 0) uniform UniformParams {
uniform uvec2 screen_resolution;
uniform float pixel_scale;
uniform mat4 projection;
}
uniforms;