From 3039593b72a9b64597276ef75b089ea7033bc3c0 Mon Sep 17 00:00:00 2001 From: cursed22bc Date: Fri, 20 Feb 2026 15:23:20 +0200 Subject: smooth pixel perfect camera example --- smoothCamera.glsl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 smoothCamera.glsl (limited to 'smoothCamera.glsl') diff --git a/smoothCamera.glsl b/smoothCamera.glsl new file mode 100644 index 0000000..074c52c --- /dev/null +++ b/smoothCamera.glsl @@ -0,0 +1,17 @@ +//[[ +// +// applies sub-pixel offset to the viewport texture for smooth camera movement +// while keeping pixel-perfect rendering. +// - game is rendered with camera snapped to integer pixels (pixel-perfect) +// - this shader samples the texture with a UV offset = (smooth_pos - snapped_pos) +// - the offset creates the illusion of smooth camera movement +// +// offset: (subPixelX, subPixelY) in UV space (0-1 range) +// texture must have 1px padding on each side to avoid black bars when sampling. +//]] + +extern vec2 offset; + +vec4 effect(vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords) { + return Texel(tex, texture_coords + offset); +} -- cgit v1.2.3