mostly correct padding rendering
This commit is contained in:
parent
c1c1247af4
commit
b35bb427a7
@ -14,6 +14,7 @@ enum CmdType {
|
||||
// command to draw a rect
|
||||
struct CmdRect {
|
||||
Rect rect;
|
||||
ushort thickness;
|
||||
ushort radius;
|
||||
Color color;
|
||||
}
|
||||
@ -104,6 +105,7 @@ fn void? Ctx.push_rect(&ctx, Rect rect, int z_index, Style* style)
|
||||
.rect.rect = rect,
|
||||
.rect.color = border_color,
|
||||
.rect.radius = radius,
|
||||
.rect.thickness = border.x,
|
||||
};
|
||||
ctx.push_cmd(&cmd, z_index)!;
|
||||
}
|
||||
@ -118,6 +120,7 @@ fn void? Ctx.push_rect(&ctx, Rect rect, int z_index, Style* style)
|
||||
},
|
||||
.rect.color = bg,
|
||||
.rect.radius = radius,
|
||||
.rect.thickness = max(rect.w, rect.h),
|
||||
};
|
||||
if (cull_rect(cmd.rect.rect, ctx.div_scissor)) return;
|
||||
ctx.push_cmd(&cmd, z_index)!;
|
||||
|
@ -7,6 +7,7 @@ layout(set = 3, binding = 0) uniform Viewport {
|
||||
layout(location = 0) in vec4 in_color;
|
||||
layout(location = 1) in vec4 in_quad_size; // x,y, w,h
|
||||
layout(location = 2) in float in_radius;
|
||||
layout(location = 3) in float thickness;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
@ -16,12 +17,16 @@ float sdf_rr(vec2 p, vec2 half_size, float radius) {
|
||||
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;
|
||||
}
|
||||
|
||||
const float smoothness = 1.5;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 centerpoint = in_quad_size.xy + in_quad_size.zw * 0.5;
|
||||
vec2 half_size = in_quad_size.zw * 0.5;
|
||||
float distance = sdf_rr(vec2(gl_FragCoord) - centerpoint, half_size, in_radius);
|
||||
float alpha = 1.0 - smoothstep(0.0, 1.5, distance);
|
||||
float distance = -sdf_rr(vec2(gl_FragCoord) - centerpoint, half_size, in_radius);
|
||||
|
||||
fragColor = vec4(in_color.rgb, in_color.a * alpha);
|
||||
float alpha_out = smoothstep(0.0, smoothness, distance);
|
||||
float alpha_in = 1.0 - smoothstep(thickness, thickness+smoothness, distance);
|
||||
|
||||
fragColor = vec4(in_color.rgb, in_color.a * alpha_out * alpha_in);
|
||||
}
|
@ -12,6 +12,7 @@ layout(location = 3) in uvec4 color;
|
||||
layout(location = 0) out vec4 out_color;
|
||||
layout(location = 1) out vec4 out_quad_size;
|
||||
layout(location = 2) out float out_radius;
|
||||
layout(location = 3) out float out_thickness;
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -26,4 +27,5 @@ void main()
|
||||
out_color = vec4(color) / 255.0;
|
||||
out_quad_size = vec4(attr);
|
||||
out_radius = float(abs(uv.x));
|
||||
out_thickness = float(uv.y - uv.x);
|
||||
}
|
||||
|
@ -651,11 +651,11 @@ fn bool Renderer.push_sprite(&self, short x, short y, short w, short h, short u,
|
||||
return self.map_quad(qa);
|
||||
}
|
||||
|
||||
fn bool Renderer.push_quad(&self, short x, short y, short w, short h, uint color, ushort radius = 0)
|
||||
fn bool Renderer.push_quad(&self, short x, short y, short w, short h, uint color, ushort radius = 0, ushort thickness = 0)
|
||||
{
|
||||
QuadAttributes qa = {
|
||||
.pos = {.x = x, .y = y, .w = w, .h = h},
|
||||
.uv = {.u = radius, .v = radius},
|
||||
.uv = {.u = radius, .v = radius+thickness},
|
||||
.color = color
|
||||
};
|
||||
|
||||
@ -866,7 +866,7 @@ fn void Renderer.render_ugui(&self, CmdQueue* queue)
|
||||
foreach (&c : queue) {
|
||||
if (c.type == CMD_RECT) {
|
||||
CmdRect r = c.rect;
|
||||
self.push_quad(r.rect.x, r.rect.y, r.rect.w, r.rect.h, r.color.to_uint(), r.radius);
|
||||
self.push_quad(r.rect.x, r.rect.y, r.rect.w, r.rect.h, r.color.to_uint(), r.radius, r.thickness);
|
||||
} else if (c.type == CMD_SPRITE) {
|
||||
CmdSprite s = c.sprite;
|
||||
self.push_sprite(s.rect.x, s.rect.y, s.texture_rect.w, s.texture_rect.h, s.texture_rect.x, s.texture_rect.y, s.hue.to_uint());
|
||||
|
Loading…
Reference in New Issue
Block a user