Master the fundamental concepts of software rasterizer through this focused micro-challenge.
Texture mapping applies a 2D image to a 3D surface. Edwin Catmull introduced the idea in 1974; today every real-time renderer depends on it. Each vertex carries texture coordinates (u, v) in the range 0 to 1. During rasterization, UVs interpolate across the triangle (with perspective correction) and each fragment looks up a texel color.
Texture mapping decouples surface detail from geometry. A flat triangle can look like brick, wood, or skin without extra vertices.
Nearest-neighbor rounds (u, v) to the closest texel. Fast but blocky when magnified.
Bilinear filtering blends four neighboring texels:
cLoading…
For example, sampling (u=0.375, v=0.625) on a 4x4 texture blends texels at (1,2), (2,2), (1,3), and (2,3). Mipmaps (Lance Williams, 1983) add precomputed smaller versions to fix minification aliasing when distant textures shrink to a few pixels.
You will sample a 4x4 gradient texture using nearest-neighbor and bilinear filtering at test UV coordinates. This task requires you to print both results so the quality difference is visible. Understanding these two modes is essential for software renderers, image resizers, and any GLSL texture() call where you choose sampler settings.
Write a C program that samples a small texture using nearest-neighbor and bilinear filtering.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github