Skip to content

Instantly share code, notes, and snippets.

@d7samurai
d7samurai / .readme.md
Last active June 9, 2024 01:22
Minimal D3D11 bonus material: pixel art antialiasing

Minimal D3D11 bonus material: pixel art antialiasing

A minimal Direct3D 11 implementation of "antialiased point sampling", useful for smooth fractional movement and non-integer scaling of pixel art AKA "fat pixel" aesthetics.

Also view below side-by-side point sampling comparison on YouTube (video is zoomed in to counter implicit downsampling & compression artifacts and make aa effect more apparent) or check out the Shadertoy.

skull

The actual sampler is set to bilinear filtering (the default D3D11 sampler state) in order to utilize single texture-read hardware interpolation, then emulating point sampling in the shader and applying AA at the fat pixel boundaries. Use with premultiplied alpha textures* and keep a one pixel transparent border around each sprite/tile.

@caged
caged / scale.rb
Created November 22, 2012 04:04
Linear scale interpolation in Ruby based on d3.js's implementation
# Returns a lambda used to determine what number is at t in the range of a and b
#
# interpolate_number(0, 500).call(0.5) # 250
# interpolate_number(0, 500).call(1) # 500
#
def interpolate_number(a, b)
a = a.to_f
b = b.to_f
b -= a
lambda { |t| a + b * t }