diff options
| -rw-r--r-- | shaders/ui.frag.glsl | 3 | ||||
| -rw-r--r-- | src/gui/gui.zig | 17 |
2 files changed, 15 insertions, 5 deletions
diff --git a/shaders/ui.frag.glsl b/shaders/ui.frag.glsl index 2284fa0b..d0967309 100644 --- a/shaders/ui.frag.glsl +++ b/shaders/ui.frag.glsl @@ -13,6 +13,9 @@ layout(location = 0) out vec4 o_col; void main() { float a = texture(u_atlas, v_uv).r; + // stb_truetype is unhinted. A small coverage lift counters its grey edge + // halo without turning the atlas into hard-edged bitmap text. + a = pow(a, 0.8); vec3 col = mix(v_bg, v_fg, a); o_col = vec4(col, 1.0); } diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 983be262..b496058e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -925,6 +925,7 @@ const Gui = struct { crt_pipeline: *c.SDL_GPUGraphicsPipeline, atlas_tex: *c.SDL_GPUTexture, atlas_sampler: *c.SDL_GPUSampler, + linear_sampler: *c.SDL_GPUSampler, atlas_xfer: *c.SDL_GPUTransferBuffer, vbuf: ?*c.SDL_GPUBuffer = null, vxfer: ?*c.SDL_GPUTransferBuffer = null, @@ -1153,13 +1154,17 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options) !void { const atlas_tex = c.SDL_CreateGPUTexture(device, &tex_info) orelse return error.GpuCreate; var samp_info = std.mem.zeroes(c.SDL_GPUSamplerCreateInfo); - samp_info.min_filter = c.SDL_GPU_FILTER_LINEAR; - samp_info.mag_filter = c.SDL_GPU_FILTER_LINEAR; - samp_info.mipmap_mode = c.SDL_GPU_FILTER_LINEAR; + samp_info.min_filter = c.SDL_GPU_FILTER_NEAREST; + samp_info.mag_filter = c.SDL_GPU_FILTER_NEAREST; + samp_info.mipmap_mode = c.SDL_GPU_FILTER_NEAREST; samp_info.address_mode_u = c.SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE; samp_info.address_mode_v = c.SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE; samp_info.address_mode_w = c.SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE; const atlas_sampler = c.SDL_CreateGPUSampler(device, &samp_info) orelse return error.GpuCreate; + samp_info.min_filter = c.SDL_GPU_FILTER_LINEAR; + samp_info.mag_filter = c.SDL_GPU_FILTER_LINEAR; + samp_info.mipmap_mode = c.SDL_GPU_FILTER_LINEAR; + const linear_sampler = c.SDL_CreateGPUSampler(device, &samp_info) orelse return error.GpuCreate; var ax_info = c.SDL_GPUTransferBufferCreateInfo{ .usage = c.SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD, .size = atlas_w * atlas_h, .props = 0 }; const atlas_xfer = c.SDL_CreateGPUTransferBuffer(device, &ax_info) orelse return error.GpuCreate; @@ -1197,6 +1202,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options) !void { .crt_pipeline = crt_pipeline, .atlas_tex = atlas_tex, .atlas_sampler = atlas_sampler, + .linear_sampler = linear_sampler, .atlas_xfer = atlas_xfer, .overlay_vbuf = overlay_vbuf, .overlay_vxfer = overlay_vxfer, @@ -1643,6 +1649,7 @@ fn runWeb(opts_in: pardes.Options) !void { .crt_pipeline = undefined, .atlas_tex = undefined, .atlas_sampler = undefined, + .linear_sampler = undefined, .atlas_xfer = undefined, .overlay_vbuf = undefined, .overlay_vxfer = undefined, @@ -3209,7 +3216,7 @@ fn drawNativeImagesGpu(g: *Gui, rp: ?*c.SDL_GPURenderPass, surface: *pardes.Surf .h = @intCast(@as(u32, place.h) * g.cell_h), }; c.SDL_SetGPUScissor(pass, &clip); - const sampler = c.SDL_GPUTextureSamplerBinding{ .texture = texture, .sampler = g.atlas_sampler }; + const sampler = c.SDL_GPUTextureSamplerBinding{ .texture = texture, .sampler = g.linear_sampler }; c.SDL_BindGPUFragmentSamplers(pass, 0, &sampler, 1); const binding = c.SDL_GPUBufferBinding{ .buffer = g.image_vbuf, .offset = idx * @sizeOf(ImageInstance) }; c.SDL_BindGPUVertexBuffers(pass, 0, &binding, 1); @@ -3357,7 +3364,7 @@ fn renderFrame(g: *Gui, gpa: std.mem.Allocator, surface: *pardes.Surface, crt_on crt_target.store_op = c.SDL_GPU_STOREOP_STORE; const rp = c.SDL_BeginGPURenderPass(cmd, &crt_target, 1, null); c.SDL_BindGPUGraphicsPipeline(rp, g.crt_pipeline); - const samp_binding = c.SDL_GPUTextureSamplerBinding{ .texture = g.scene_tex.?, .sampler = g.atlas_sampler }; + const samp_binding = c.SDL_GPUTextureSamplerBinding{ .texture = g.scene_tex.?, .sampler = g.linear_sampler }; c.SDL_BindGPUFragmentSamplers(rp, 0, &samp_binding, 1); c.SDL_DrawGPUPrimitives(rp, 3, 1, 0, 0); c.SDL_EndGPURenderPass(rp); |
