Merge pull request #275 from zed-industries/fix-selection-artifacts

Use 16-bit float to store path windings
This commit is contained in:
Antonio Scandurra
2021-12-05 12:58:00 +01:00
committed by GitHub
2 changed files with 4 additions and 6 deletions
+2 -2
View File
@@ -107,7 +107,7 @@ impl Renderer {
"path_atlas",
"path_atlas_vertex",
"path_atlas_fragment",
MTLPixelFormat::R8Unorm,
MTLPixelFormat::R16Float,
);
Self {
sprite_cache,
@@ -827,7 +827,7 @@ fn build_path_atlas_texture_descriptor() -> metal::TextureDescriptor {
let texture_descriptor = metal::TextureDescriptor::new();
texture_descriptor.set_width(2048);
texture_descriptor.set_height(2048);
texture_descriptor.set_pixel_format(MTLPixelFormat::R8Unorm);
texture_descriptor.set_pixel_format(MTLPixelFormat::R16Float);
texture_descriptor
.set_usage(metal::MTLTextureUsage::RenderTarget | metal::MTLTextureUsage::ShaderRead);
texture_descriptor.set_storage_mode(metal::MTLStorageMode::Private);
@@ -205,8 +205,6 @@ vertex SpriteFragmentInput sprite_vertex(
};
}
#define MAX_WINDINGS 32.
fragment float4 sprite_fragment(
SpriteFragmentInput input [[stage_in]],
texture2d<float> atlas [[ texture(GPUISpriteFragmentInputIndexAtlas) ]]
@@ -216,7 +214,7 @@ fragment float4 sprite_fragment(
float4 sample = atlas.sample(atlas_sampler, input.atlas_position);
float mask;
if (input.compute_winding) {
mask = 1. - abs(1. - fmod(sample.r * MAX_WINDINGS, 2.));
mask = 1. - abs(1. - fmod(sample.r, 2.));
} else {
mask = sample.a;
}
@@ -303,6 +301,6 @@ fragment float4 path_atlas_fragment(
);
float f = (input.st_position.x * input.st_position.x) - input.st_position.y;
float distance = f / length(gradient);
float alpha = saturate(0.5 - distance) / MAX_WINDINGS;
float alpha = saturate(0.5 - distance);
return float4(alpha, 0., 0., 1.);
}