54 float4 rect, color_inner, color_outline;
55 float outline_thickness, outline_offset, shape, aspect;
60 rect = params_inst.parameters[offset + 0];
61 color_inner = params_inst.parameters[offset + 1];
62 color_outline = params_inst.parameters[offset + 2];
63 outline_thickness = params_inst.parameters[offset + 3].
x;
64 outline_offset = params_inst.parameters[offset + 3].y;
65 shape = params_inst.parameters[offset + 3].z;
66 aspect = params_inst.parameters[offset + 3].w;
70 rect = params.parameters[0];
71 color_inner = params.parameters[1];
72 color_outline = params.parameters[2];
73 outline_thickness = params.parameters[3].
x;
74 outline_offset = params.parameters[3].y;
75 shape = params.parameters[3].z;
76 aspect = params.parameters[3].w;
80 float2 originalRectSize = rect.yw - rect.xz;
81 float offset = 0.125f *
min(originalRectSize.
x, originalRectSize.
y) +
82 outline_offset * outline_thickness;
88 pos = rect.xz + ofs.yy;
92 pos = rect.xw + ofs.yx;
96 pos = rect.yz + ofs.xy;
100 pos = rect.yw + ofs.xx;
105 out_pos = srt.ModelViewProjectionMatrix *
float4(pos, 0.0f, 1.0f);
107 float2 rectSize = rect.yw - rect.xz + 2.0f *
float2(outline_offset, outline_offset);
108 float minSize =
min(rectSize.
x, rectSize.
y);
110 float2 centeredCoordinates = pos - ((rect.xz + rect.yw) / 2.0f);
111 v_out.uv = centeredCoordinates / minSize;
115 float ratio = rectSize.
x / rectSize.
y;
116 v_out.extrusion = (ratio > 1.0f) ?
float2((ratio - 1.0f) / 2.0f, 0.0f) :
117 float2(0.0f, ((1.0f / ratio) - 1.0f) / 2.0f);
120 v_out.final_shape = int(shape);
121 v_out.final_outline_thickness = outline_thickness / minSize;
122 v_out.final_dot_radius = outline_thickness / minSize;
123 v_out.aa_size = 1.0f * aspect / minSize;
126 v_out.final_color = color_inner;
127 v_out.final_outline_color = color_outline;
146 float2 extruded_co = absCo - half_size;
149 float exterior_distance_squared =
dot(clamped_extruded_co, clamped_extruded_co);
151 float interior_distance =
min(
max(extruded_co.
x, extruded_co.
y), 0.0f);
152 float interior_distance_squared = interior_distance * interior_distance;
154 return exterior_distance_squared - interior_distance_squared;
177 float alpha_threshold = 0.0f;
178 float dot_threshold = -1.0f;
180 constexpr float circle_radius = 0.5f;
183 constexpr float corner_rounding = 0.0f;
185 switch (v_out.final_shape) {
189 alpha_threshold = circle_radius;
194 alpha_threshold = circle_radius;
195 dot_threshold = v_out.final_dot_radius;
200 alpha_threshold = corner_rounding;
205 alpha_threshold = corner_rounding;
206 dot_threshold = v_out.final_dot_radius;
211 alpha_threshold = corner_rounding;
216 alpha_threshold = corner_rounding;
217 dot_threshold = v_out.final_dot_radius;
222 alpha_threshold = corner_rounding;
226 constexpr float rect_side_length = 0.25f;
227 const float2 oversize =
float2(0.0f, square_radius * 1.4) / 2.5f;
228 const float2 rect_corner =
max(
float2(rect_side_length), v_out.extrusion / 2.0f + oversize) +
229 v_out.final_outline_thickness / 4.0f;
230 const float2 mirrored_uv =
abs(
abs(v_out.uv) - rect_corner);
232 rect_corner + v_out.final_outline_thickness / 2.0f);
233 alpha_threshold = corner_rounding;
237 constexpr float2 rect_side_length =
float2(0.5f, 0.25f);
238 const float2 oversize =
float2(0.0f, square_radius * 1.4) / 2.5f;
239 const float2 rect_corner =
max(rect_side_length, v_out.extrusion / 2.0f + oversize) +
240 v_out.final_outline_thickness / 4.0f;
243 abs(
abs(
abs(v_out.uv.y) - rect_corner.
y / 1.5f) - rect_corner.
y / 1.5f));
245 mirrored_uv, (rect_corner + v_out.final_outline_thickness / 2.0f) /
float2(1.0f, 1.5f));
252 v_out.aa_size, alpha_threshold - v_out.final_outline_thickness);
256 float dot_mask =
smoothstep(dot_thresholds[1], dot_thresholds[0],
dot(co, co));
260 frag_out.color =
mix(v_out.final_color, v_out.final_outline_color, outline_mask);
261 frag_out.color.a *= alpha_mask;