Skip to content

Commit 9004057

Browse files
committed
fix: fix incorrect rendering of dots when crossing cell boundaries
1 parent f11e60c commit 9004057

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

script/ColorHalftone.hlsl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ float4 halftone(in float2 p, in int channel, in float dot_size, in float2 center
143143

144144
float min_d = 1e20;
145145
float size = 0.0;
146-
for(int y = -1; y <= 1; y++)
147-
for(int x = -1; x <= 1; x++)
146+
float shape_size = 0.0;
147+
int search_range = (int)ceil(dot_size * 1.5 + fusion * 0.5);
148+
search_range = clamp(search_range, 1, 3);
149+
for(int y = -search_range; y <= search_range; y++)
150+
for(int x = -search_range; x <= search_range; x++)
148151
{
149152
float2 rid = id + float2(x, y);
150153
float2 pos_in_st = rid * s;
@@ -284,18 +287,21 @@ float4 halftone(in float2 p, in int channel, in float dot_size, in float2 center
284287
}
285288
}
286289

290+
if (d < min_d) {
291+
shape_size = size;
292+
}
287293
min_d = smin(min_d, d, fusion);
288294
}
289295

290296
// アンチエイリアス
291297
float aa_width = length(float2(ddx(st.x), ddy(st.x)));
292298
float blend = 0.0;
293299
if (shape == 7) {
294-
blend = smoothThreshold(size, 0.5 * s, aa_width, min_d);
300+
blend = smoothThreshold(shape_size * dot_size, 0.5 * s, aa_width, min_d);
295301
} else {
296302
static const float AA_WIDTH_FACTOR = 1.2;
297303
blend = smoothstep(-aa_width, aa_width, min_d);
298-
float opacity = smoothstep(0.0, aa_width * AA_WIDTH_FACTOR, size);
304+
float opacity = smoothstep(0.0, aa_width * AA_WIDTH_FACTOR, shape_size * dot_size);
299305
blend = 1.0 - (1.0 - blend) * opacity;
300306
}
301307
return lerp(dot_col, bg_col, blend);

0 commit comments

Comments
 (0)