All puzzles › Computer Graphics

Computer Graphics Practice Problems

28 puzzles (7 easy, 13 medium, 8 hard), 8 free, in Python, JavaScript and C++.

Rasterization, ray tracing, shading and colour: the math that turns numbers into pictures.

The puzzles, easiest first

  1. Shades From Black and White (Easy, free): A screen that can only show black or white can still fake gray, by lighting some pixels and not others.
  2. Which Eighth of the Box (Easy, free): An octree splits a box of space into eight smaller boxes around its center, and to store a point you need to know which of the eight it falls in.
  3. AABB Overlap Test (Easy): Given two boxes as [x1, y1, x2, y2], return true if they overlap.
  4. Alpha Blending (Easy): Given a new color, the color behind it, and an alpha from 0 to 1, return the blended color, rounded to 4 decimals.
  5. Colour Gradient Lerp (Easy): Given two colors a and b and a fraction t from 0 to 1, return the color t of the way from a to b, rounded to 4 decimals.
  6. Gamma Correction (Easy): Given a list of color values from 0 to 1, raise each one to the power 1 / 2.2 and return the results, rounded to 4 decimals.
  7. Relative Luminance (Easy): Given a color as [r, g, b], each from 0 to 1, return its brightness, rounded to 4 decimals: 0.2126 x r + 0.7152 x g + 0.0722 x b.
  8. Any Rectangle in Four Lookups (Medium, free): Adding up the pixels in a rectangle normally means visiting every one.
  9. Pass the Error Along (Medium, free): Turning gray into black and white always gets each pixel a little wrong.
  10. Read the Contour From the Corners (Medium, free): To draw a contour line through a grid of measurements, look at each small square formed by four neighboring values.
  11. Step by the Safe Distance (Medium, free): A ray starts at x = 0 and travels right along the x axis.
  12. Backface Culling (Medium): Given a triangle's three corners on screen, return true if it faces you.
  13. Barycentric Coordinates (Medium): Given a triangle's three corners a, b, and c and a point p, return p's barycentric weights [w0, w1, w2], rounded to 4 decimals.
  14. Bilinear Texture Filter (Medium): Given a 2 by 2 grid of texture values and a point (u, v), each from 0 to 1, return the blended value, rounded to 4 decimals.
  15. Bresenham's Line (Medium): Given two points, return every pixel on the line between them, start to end.
  16. Perlin's Fade Curve (Medium): Given t from 0 to 1, return 6t^5 - 15t^4 + 10t^3, rounded to 4 decimals.
  17. Reinhard Tone Mapping (Medium): Given a list of brightness values that can be any size, squash each one into the range 0 to 1 with c / (1 + c), rounded to 4 decimals.
  18. The Perspective Divide (Medium): Given a point in clip space as [x, y, z, w], return [x / w, y / w, z / w], rounded to 4 decimals.
  19. Viewport Transform (Medium): Given a point from -1 to 1 on each axis, plus a screen width and height, return its pixel position, rounded to 2 decimals.
  20. Z-Buffer Depth Test (Medium): Given a depth grid and a list of fragments as [x, y, z], return the grid after testing every fragment.
  21. A Curve That Never Jumps (Hard, free): A Hilbert curve visits every cell of a 2^order by 2^order grid exactly once, and each step moves to a touching cell.
  22. Which Pixels Are Inside (Hard, free): A GPU decides which pixels a triangle covers by testing each pixel's center against the three edges.
  23. De Casteljau's Algorithm (Hard): Given four control points and t from 0 to 1, return the point on the Bezier curve at t, rounded to 4 decimals.
  24. Gaussian Splat Compositing (Hard): Given each splat's alpha and color, front to back, return the final color, rounded to 4 decimals.
  25. Morton Code (Z-Order) (Hard): Given x and y, return their Morton code by interleaving their bits: x's bits go in the even positions and y's bits go in the odd ones.
  26. Ray-Box Slab Test (Hard): Given a ray's origin and direction and a box's min and max corners, return true if the ray hits the box.
  27. Ray-Sphere Intersection (Hard): Given a ray's origin o and unit direction d, and a sphere's center c and radius r, return the distance t to the nearest hit in front of the ray, rounded to 4 decimals, or -1 for a miss.
  28. Schlick's Fresnel (Hard): Given a base reflectance f0 as [r, g, b] and the cosine of the viewing angle, return the reflectance for each channel, rounded to 4 decimals: f0 + (1 - f0) x (1 - cos)^5.

Practice another pattern

Or browse by subject

Browse all 676 puzzles