33 return {.dir =
float2(0.0f), .dist = 0.0f, .dist_raw = 0.0f};
40 float dist_raw = data.y == 1.0f ? 0.0f : data.y;
58 float coverage(
float kernel_size,
bool do_smooth_lines)
const
60 if (do_smooth_lines) {
73 bool is_ofs_horizontal = offset.
x != 0;
75 if (!
is_valid() || is_ofs_horizontal != is_dir_horizontal) {
107 int2 texel_actual = texel + offset;
114 data.line.offset_to_neighbor(offset);
126 if (!do_background_fetch) {
131 for (
int i = 0; i < 4; i++) [[
unroll]] {
132 if (neighbors[i].depth > furthest.
depth) {
133 furthest = neighbors[i];
145 bool do_smooth_lines)
151 float coverage = target.
line.
coverage(kernel_size, do_smooth_lines);
163 bool do_smooth_lines)
169 float coverage = neighbor.
line.
coverage(kernel_size, do_smooth_lines);
170 if (coverage == 0.0f) {
178 bool target_over_neighbor = target.
depth < neighbor.
depth;
182 if (background.
color.a == 0.0) {
184 target.
color = over + under * (1.0f - over.a);
188 under.a *= (1.0f - over.a);
189 target.
color = (over * over.a + under * under.a) / (over.a + under.a);
192 if (!target_over_neighbor) {
217 if (!srt.do_smooth_lines && center.
line.
dist <= 1.0f) {
218 frag.color = center.
color;
224 srt.fetch_texel(texel,
int2(-1, 0)),
225 srt.fetch_texel(texel,
int2(0, 1)),
226 srt.fetch_texel(texel,
int2(0, -1))};
232 const bool original_center_has_alpha = center.
color.a < 1.0f;
235 const float kernel_size = uni.uniform_buf.sizes.pixel * 0.5f - 0.5f;
236 center_kernel(center, background, kernel_size, srt.do_smooth_lines);
239 neighbor_kernel(center, neighbors[0], background, kernel_size, srt.do_smooth_lines);
240 neighbor_kernel(center, neighbors[1], background, kernel_size, srt.do_smooth_lines);
241 neighbor_kernel(center, neighbors[2], background, kernel_size, srt.do_smooth_lines);
242 neighbor_kernel(center, neighbors[3], background, kernel_size, srt.do_smooth_lines);
246 if (!original_center_has_alpha && center.
line.
is_valid() && kernel_size < 0.45f) {
254 blend =
clamp(blend * 2.0f - 1.0f, 0.0f, 1.0f);
259 frag.color = center.
color;
VecBase< bool, D > notEqual(VecOp< T, D >, VecOp< T, D >) RET
T smoothstep(T, T, T) RET
bool any(VecOp< bool, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
SamplerBase< float, 2 > sampler2D
void fullscreen_vertex(int vertex_id, float4 &out_position)
TexelData furthest_texel(TexelData center, TexelData neighbors[4], bool do_background_fetch)
void frag_main(const float4 &frag_coord, Resources &srt, const Uniform &uni, FragOut &frag)
PipelineGraphic pipeline(vert_main, frag_main)
void vert_main(const int &vert_id, float4 &vert)
void neighbor_kernel(TexelData &target, TexelData neighbor, TexelData background, float kernel_size, bool do_smooth_lines)
void center_kernel(TexelData &target, const TexelData background, float kernel_size, bool do_smooth_lines)
void unpack_line_data(float2 data, float2 &perp, float &dist)
#define LINE_SMOOTH_START
static Line unpack(float2 data)
void offset_to_neighbor(int2 offset)
float coverage(float kernel_size, bool do_smooth_lines) const
const bool do_background_fetch
const sampler2DDepth depth_tx
TexelData fetch_texel(int2 texel, int2 offset)
const bool do_smooth_lines