shader_type canvas_item; // "Sharp bilinear" upscaling for pixel art, used by PixelScreen. // Each game pixel is drawn as a solid block, and only the single screen pixel // where two game pixels meet is blended. So the game can be scaled by any // amount (2.25x, 3.7x...) with every pixel looking the same size, instead of // some being drawn a screen pixel wider than others. // Needs the texture to be sampled with linear filtering. void fragment() { vec2 textureSize = 1.0 / TEXTURE_PIXEL_SIZE; vec2 texel = UV * textureSize; // How many screen pixels one game pixel covers. vec2 scale = 1.0 / max(fwidth(texel), vec2(1e-5)); // Inside this distance of a game pixel's centre, show its colour as is. vec2 solid = max(0.5 - 0.5 / scale, vec2(0.0)); vec2 fromCentre = fract(texel) - 0.5; vec2 blend = (fromCentre - clamp(fromCentre, -solid, solid)) * scale + 0.5; COLOR = texture(TEXTURE, (floor(texel) + blend) / textureSize); }