Snap path sprites to pixel grid
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
parent
1903f63c45
commit
da1960c3e8
2 changed files with 8 additions and 3 deletions
|
@ -160,7 +160,7 @@ impl Renderer {
|
||||||
layer_id,
|
layer_id,
|
||||||
atlas_id,
|
atlas_id,
|
||||||
sprite: shaders::GPUISprite {
|
sprite: shaders::GPUISprite {
|
||||||
origin: origin.to_float2(),
|
origin: origin.floor().to_float2(),
|
||||||
size: size.to_float2(),
|
size: size.to_float2(),
|
||||||
atlas_origin: atlas_origin.to_float2(),
|
atlas_origin: atlas_origin.to_float2(),
|
||||||
color: path.color.to_uchar4(),
|
color: path.color.to_uchar4(),
|
||||||
|
|
|
@ -193,6 +193,8 @@ vertex SpriteFragmentInput sprite_vertex(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAX_WINDINGS 8.
|
||||||
|
|
||||||
fragment float4 sprite_fragment(
|
fragment float4 sprite_fragment(
|
||||||
SpriteFragmentInput input [[stage_in]],
|
SpriteFragmentInput input [[stage_in]],
|
||||||
texture2d<float> atlas [[ texture(GPUISpriteFragmentInputIndexAtlas) ]]
|
texture2d<float> atlas [[ texture(GPUISpriteFragmentInputIndexAtlas) ]]
|
||||||
|
@ -202,7 +204,10 @@ fragment float4 sprite_fragment(
|
||||||
float4 sample = atlas.sample(atlas_sampler, input.atlas_position);
|
float4 sample = atlas.sample(atlas_sampler, input.atlas_position);
|
||||||
float mask;
|
float mask;
|
||||||
if (input.compute_winding) {
|
if (input.compute_winding) {
|
||||||
mask = fmod(sample.r * 255., 2.);
|
mask = fmod(sample.r * MAX_WINDINGS, 2.);
|
||||||
|
if (mask > 1) {
|
||||||
|
mask = 2. - mask;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mask = sample.a;
|
mask = sample.a;
|
||||||
}
|
}
|
||||||
|
@ -239,6 +244,6 @@ fragment float4 path_winding_fragment(
|
||||||
);
|
);
|
||||||
float f = (input.st_position.x * input.st_position.x) - input.st_position.y;
|
float f = (input.st_position.x * input.st_position.x) - input.st_position.y;
|
||||||
float distance = f / length(gradient);
|
float distance = f / length(gradient);
|
||||||
float alpha = saturate(0.5 - distance) / 255.;
|
float alpha = saturate(0.5 - distance) / MAX_WINDINGS;
|
||||||
return float4(alpha, 0., 0., 1.);
|
return float4(alpha, 0., 0., 1.);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue