Autosave feature, spritesheet editor dashed lines, refactoring, fixes

This commit is contained in:
shweet committed 2025-10-28 15:47:54 -04:00
1 parent dd3aeae6d2
commit 729d5fb216
39 files changed
+1446 -228

No files matched your search

+84 -2
View File
@@ -112,6 +112,79 @@ namespace anm2ed::shader
}
)";
constexpr auto DASHED_VERTEX = R"(
#version 330 core
layout (location = 0) in vec2 i_position;
out vec2 v_local;
uniform mat4 u_transform;
void main()
{
v_local = i_position;
gl_Position = u_transform * vec4(i_position, 0.0, 1.0);
}
)";
constexpr auto DASHED_FRAGMENT = R"(
#version 330 core
in vec2 v_local;
uniform vec4 u_color;
uniform vec2 u_axis_x;
uniform vec2 u_axis_y;
uniform float u_dash_length;
uniform float u_dash_gap;
uniform float u_dash_offset;
out vec4 o_fragColor;
void main()
{
vec2 local = clamp(v_local, 0.0, 1.0);
float lengthX = max(length(u_axis_x), 1e-4);
float lengthY = max(length(u_axis_y), 1e-4);
float dash = max(u_dash_length, 1e-4);
float gap = max(u_dash_gap, 0.0);
float period = max(dash + gap, 1e-4);
vec2 pixel = max(fwidth(v_local), vec2(1e-5));
float bottomMask = 1.0 - smoothstep(pixel.y, pixel.y * 2.0, local.y);
float topMask = 1.0 - smoothstep(pixel.y, pixel.y * 2.0, 1.0 - local.y);
float leftMask = 1.0 - smoothstep(pixel.x, pixel.x * 2.0, local.x);
float rightMask = 1.0 - smoothstep(pixel.x, pixel.x * 2.0, 1.0 - local.x);
float perimeterOffset = u_dash_offset;
float bottomPos = mod(perimeterOffset + local.x * lengthX, period);
if (bottomPos < 0.0) bottomPos += period;
float bottomDash = bottomMask * (bottomPos <= dash ? 1.0 : 0.0);
float rightPos = mod(perimeterOffset + lengthX + local.y * lengthY, period);
if (rightPos < 0.0) rightPos += period;
float rightDash = rightMask * (rightPos <= dash ? 1.0 : 0.0);
float topPos = mod(perimeterOffset + lengthX + lengthY + (1.0 - local.x) * lengthX, period);
if (topPos < 0.0) topPos += period;
float topDash = topMask * (topPos <= dash ? 1.0 : 0.0);
float leftPos = mod(perimeterOffset + 2.0 * lengthX + lengthY + (1.0 - local.y) * lengthY, period);
if (leftPos < 0.0) leftPos += period;
float leftDash = leftMask * (leftPos <= dash ? 1.0 : 0.0);
float alpha = max(max(bottomDash, topDash), max(leftDash, rightDash));
if (alpha <= 0.0)
discard;
o_fragColor = vec4(u_color.rgb, u_color.a * alpha);
}
)";
constexpr auto UNIFORM_AXIS = "u_axis";
constexpr auto UNIFORM_COLOR = "u_color";
constexpr auto UNIFORM_TRANSFORM = "u_transform";
@@ -123,18 +196,27 @@ namespace anm2ed::shader
constexpr auto UNIFORM_MODEL = "u_model";
constexpr auto UNIFORM_RECT_SIZE = "u_rect_size";
constexpr auto UNIFORM_TEXTURE = "u_texture";
constexpr auto UNIFORM_AXIS_X = "u_axis_x";
constexpr auto UNIFORM_AXIS_Y = "u_axis_y";
constexpr auto UNIFORM_DASH_LENGTH = "u_dash_length";
constexpr auto UNIFORM_DASH_GAP = "u_dash_gap";
constexpr auto UNIFORM_DASH_OFFSET = "u_dash_offset";
enum Type
{
LINE,
DASHED,
TEXTURE,
AXIS,
GRID,
COUNT
};
const Info SHADERS[COUNT] = {
{VERTEX, FRAGMENT}, {VERTEX, TEXTURE_FRAGMENT}, {AXIS_VERTEX, FRAGMENT}, {GRID_VERTEX, GRID_FRAGMENT}};
const Info SHADERS[COUNT] = {{VERTEX, FRAGMENT},
{DASHED_VERTEX, DASHED_FRAGMENT},
{VERTEX, TEXTURE_FRAGMENT},
{AXIS_VERTEX, FRAGMENT},
{GRID_VERTEX, GRID_FRAGMENT}};
class Shader
{