update
This commit is contained in:
@@ -1,8 +1,55 @@
|
||||
#version 330 core
|
||||
out vec4 frag_color;
|
||||
out vec4 pixel_color;
|
||||
|
||||
in vec4 fragment_color;
|
||||
in vec4 frag_color;
|
||||
in vec2 frag_dest_position;
|
||||
in vec2 frag_dest_center;
|
||||
in vec2 frag_dest_half_size;
|
||||
in float frag_softness;
|
||||
in float frag_border_radius;
|
||||
in float frag_border_thickness;
|
||||
|
||||
float roundedRectSDF(vec2 sample_pos, vec2 rect_center, vec2 rect_half_size, float r) {
|
||||
vec2 d2 = (abs(rect_center - sample_pos) - rect_half_size + vec2(r, r));
|
||||
return min(max(d2.x, d2.y), 0.0) + length(max(d2, 0.0)) - r;
|
||||
}
|
||||
|
||||
void main() {
|
||||
frag_color = fragment_color;
|
||||
vec2 softness_padding = vec2(
|
||||
max(0, frag_softness*2-1),
|
||||
max(0, frag_softness*2-1));
|
||||
|
||||
float border_factor = 1.0f;
|
||||
if (frag_border_thickness != 0) {
|
||||
vec2 interior_half_size = frag_dest_half_size - vec2(frag_border_thickness);
|
||||
|
||||
float interior_radius_reduce_f = min(
|
||||
interior_half_size.x / frag_dest_half_size.x,
|
||||
interior_half_size.y / frag_dest_half_size.y);
|
||||
|
||||
float interior_corner_radius = frag_border_radius * interior_radius_reduce_f * interior_radius_reduce_f;
|
||||
|
||||
float inside_d = roundedRectSDF(
|
||||
frag_dest_position,
|
||||
frag_dest_center,
|
||||
interior_half_size - softness_padding,
|
||||
interior_corner_radius);
|
||||
|
||||
|
||||
float inside_f = smoothstep(0, 2*frag_softness, inside_d);
|
||||
border_factor = inside_f;
|
||||
}
|
||||
|
||||
float dist = roundedRectSDF(
|
||||
frag_dest_position,
|
||||
frag_dest_center,
|
||||
frag_dest_half_size - softness_padding,
|
||||
frag_border_radius);
|
||||
|
||||
// For texturing later
|
||||
float sample = 1;
|
||||
|
||||
float sdf_factor = 1.0f - smoothstep(0, 2*frag_softness, dist);
|
||||
|
||||
pixel_color = frag_color * sample * sdf_factor * border_factor;
|
||||
};
|
||||
|
||||
@@ -2,10 +2,19 @@
|
||||
layout (location = 0) in vec2 p0;
|
||||
layout (location = 1) in vec2 p1;
|
||||
layout (location = 2) in vec4 color;
|
||||
layout (location = 3) in float border_radius;
|
||||
layout (location = 4) in float border_thickness;
|
||||
layout (location = 6) in float edge_softness;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec4 fragment_color;
|
||||
out vec4 frag_color;
|
||||
out vec2 frag_dest_position;
|
||||
out vec2 frag_dest_center;
|
||||
out vec2 frag_dest_half_size;
|
||||
out float frag_softness;
|
||||
out float frag_border_radius;
|
||||
out float frag_border_thickness;
|
||||
|
||||
const vec2 rectangle_vertices[4] = vec2[](
|
||||
vec2(-1, -1),
|
||||
@@ -25,5 +34,11 @@ void main() {
|
||||
1
|
||||
);
|
||||
|
||||
fragment_color = color;
|
||||
frag_color = color;
|
||||
frag_dest_position = dest_position;
|
||||
frag_dest_center = dest_center;
|
||||
frag_dest_half_size = dest_half_size;
|
||||
frag_border_radius = border_radius;
|
||||
frag_border_thickness = border_thickness;
|
||||
frag_softness = edge_softness;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user