Skip to content
Tutorials Center
My learning

Topics

Lesson 49 of 50 · Projects, Practice and Review

Computer Graphics Interview Questions

36 common computer graphics interview questions with concise answers on algorithms, transforms, projection, depth, shading, the pipeline and ray tracing, plus live checks.

Graphics interviews come in two flavors. Some test whether you can explain the ideas (what a homogeneous coordinate is for, why perspective needs a divide). Others test whether you can write a small piece of code on a whiteboard (a line algorithm, a ray-sphere test, a triangle inside test). This page collects 36 questions that come up again and again, grouped by topic, with short answers you can expand in your own voice.

Try to answer each question out loud before you open it. If you hesitate, follow the link and review the lesson. A few questions are best remembered by running a tiny program; those editors are small stand-ins that run in your browser, not a real GPU.

Answer in three beats: a one-sentence definition, the reason it exists, and one trade-off or example. Interviewers are usually listening for the "why", not the formula.

Rasterization basics

These questions come from Pixels and the Framebuffer, The DDA Line Algorithm, Bresenham's Line Algorithm, The Midpoint Circle Algorithm and Aliasing and Antialiasing.

1. What is a framebuffer?

A block of memory that holds one color value per pixel of the image. The renderer writes into it and the display hardware reads it out. Double buffering uses two of them, so you draw into a hidden one while the other is shown, then swap, which avoids flicker and tearing.

2. How does the DDA line algorithm work, and what is its weakness?

It takes the larger of |dx| and |dy| as the number of steps, divides both differences by that count to get a per-step increment, and adds the increments repeatedly, rounding at each plot. It is simple, but it uses floating-point additions and a rounding per pixel, and rounding errors can accumulate on long lines.

3. Why is Bresenham's algorithm preferred over DDA?

It uses only integer addition, subtraction and shifts. A decision variable tracks which of the two candidate pixels is closer to the true line, and it is updated incrementally. It never accumulates error, and it was faster on hardware where floating-point work was expensive.

4. How do you extend Bresenham to all slopes and directions?

Handle the eight octants. Either swap the roles of x and y when the line is steep (|dy| greater than |dx|), or use the general error-term form that steps in x, in y or in both depending on the error. The direction of each step is just the sign of dx and dy.

5. Why can a circle be drawn from only one octant?

A circle is symmetric about both axes and both diagonals. If you compute the points of one 45-degree arc, every point (x, y) produces seven mirror points: (y, x), (-x, y), and so on. That cuts the work to one eighth and keeps the shape evenly rounded.

6. What does the midpoint circle algorithm decide at each step?

Having plotted a pixel, it chooses between the next pixel to the right and the one diagonally down-right, by evaluating the circle function x² + y² - r² at the midpoint between them. A negative value means the midpoint is inside the circle, so the upper pixel stays; otherwise it moves down. Updating the decision value incrementally uses integers only.

7. What is aliasing, and how do you reduce it?

Aliasing is the jagged "staircase" look (and shimmering in motion) that appears because a continuous scene is sampled at a finite pixel grid. Antialiasing reduces it by sampling more than once per pixel (supersampling or MSAA), by computing partial pixel coverage (Wu's algorithm), or by filtering the result. All of them trade extra computation for smoother edges.

8. What is the difference between supersampling and multisampling?

Supersampling runs the whole shading computation several times per pixel, so it smooths everything, including textures and shader edges, at full cost. Multisampling (MSAA) tests coverage and depth at several sample positions but runs the shader once per pixel, which is much cheaper and fixes mainly geometry edges.

Here is a quick check you can run. Bresenham and the DDA agree on this line, but only one of them needs floating point.

JS DDA versus Bresenham

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Polygons, filling and clipping

These questions come from Polygons, Scanline Polygon Filling, Flood Fill, Triangle Rasterization, Cohen-Sutherland, Liang-Barsky and Polygon Clipping.

9. How do you test whether a point is inside a polygon?

Cast a ray from the point in any direction and count crossings with the polygon's edges. With the even-odd rule, an odd count means inside. The nonzero winding rule instead adds up edge directions and says inside when the total is not zero. They differ for self-intersecting shapes such as a five-pointed star drawn in one stroke.

10. How does scanline polygon filling work?

For each horizontal scanline, find where it crosses the polygon's edges, sort the crossings by x and fill between pairs. An edge table and an active edge list avoid rechecking every edge on every line, and each edge's x intersection is updated incrementally using its inverse slope. Horizontal edges are skipped and shared vertices need a consistent rule so they are not counted twice.

11. What is the difference between flood fill and boundary fill?

Flood fill replaces a region of one existing color with a new color, starting from a seed. Boundary fill paints outward from a seed until it reaches pixels of a specified boundary color. Flood fill suits "paint bucket" tools; boundary fill suits shapes outlined in a single color.

12. Why is a recursive flood fill dangerous?

Each pixel adds a stack frame, so a large region can overflow the call stack. Use an explicit stack or queue, or a scanline variant that fills a whole horizontal run at once and pushes only the runs above and below it. The scanline version is faster and uses far less memory.

13. What are barycentric coordinates, and what are they used for?

For a point inside a triangle, the three weights (w0, w1, w2) that sum to 1 and express the point as w0·A + w1·B + w2·C. A point is inside exactly when all three are non-negative. The same weights interpolate any per-vertex attribute: color, depth, normals and texture coordinates.

14. What are edge functions?

For an edge from P to Q, the function E(x, y) = (x - Px)(Qy - Py) - (y - Py)(Qx - Px) is positive on one side of the edge, negative on the other and zero on it. A pixel is inside a triangle when all three edge functions have the same sign. The normalized values are the barycentric weights, and the functions can be updated incrementally across a row.

15. What is the top-left rule?

A tie-breaking rule for pixels that lie exactly on an edge shared by two triangles. Without it the pixel would be drawn twice (and blend twice) or not at all. With it, a pixel on a top or left edge belongs to the triangle, and one on a bottom or right edge does not, so every pixel is covered exactly once.

16. How does Cohen-Sutherland clip a line?

It gives each endpoint a four-bit outcode (left, right, below, above the window). If both codes are 0000, accept the line. If the bitwise AND of the codes is not zero, both points lie beyond the same edge, so reject. Otherwise it clips the line against one violated edge, replaces the outside endpoint with the intersection and repeats.

17. How is Liang-Barsky different?

It writes the line as P(t) = P0 + t·(P1 - P0) and, for each of the four window edges, computes a p and q value that bound t. The visible part is the t interval [t0, t1] left after taking the maximum of the entering values and the minimum of the leaving values. It needs no repeated intersection calculations, so it is generally faster than Cohen-Sutherland.

18. How does Sutherland-Hodgman clip a polygon, and where does it fail?

It clips the polygon against one window edge at a time, passing the output list of vertices to the next edge. Each polygon edge falls into one of four cases (inside to inside, inside to outside, outside to outside, outside to inside), which decide what to output. It is correct for convex polygons; for concave ones it can leave extra "bridge" edges along the window boundary where the result should be several separate pieces.

Transformations and projection

These questions come from Homogeneous Coordinates, 3D Transformations, 3D Rotation, The Camera and Projection.

19. Why do we use homogeneous coordinates?

Translation is an addition, not a matrix multiplication, in ordinary coordinates. Adding one extra coordinate (w = 1) lets translation, rotation and scaling all be written as a single matrix, so a chain of transforms collapses into one matrix. Perspective projection needs the same extra coordinate for the divide by w.

20. Does the order of transformations matter?

Yes, matrix multiplication is not commutative. Rotating and then translating is different from translating and then rotating. With column vectors the matrix nearest the point is applied first, so T · R · p rotates first and translates second. To rotate about a pivot, translate the pivot to the origin, rotate, then translate back.

21. Which transformations are affine, and what do they preserve?

Translation, rotation, scaling, reflection and shear. Affine maps keep straight lines straight and parallel lines parallel, and they preserve ratios of distances along a line. Perspective projection is not affine: parallel lines can converge.

22. How do you transform a normal vector?

Not with the model matrix itself when it contains non-uniform scale or shear. Use the inverse transpose of its upper-left 3x3 part, then re-normalize. That keeps the normal perpendicular to the transformed surface. For rotation plus uniform scale, the ordinary matrix works after normalizing.

23. What is gimbal lock, and how do quaternions avoid it?

With Euler angles (three rotations applied in a fixed order), a certain middle angle, such as 90 degrees of pitch, makes two of the rotation axes line up, so one degree of freedom is lost. Quaternions represent a rotation as an axis and angle in four numbers, have no such singularity, compose cheaply and interpolate smoothly with slerp.

24. Explain model, view and projection matrices.

The model matrix places an object from its own space into the world. The view matrix moves the world so the camera sits at the origin looking down an axis. The projection matrix maps the visible volume (a frustum or a box) to clip space. A vertex goes through them in that order: clip = P · V · M · p.

25. How is a look-at matrix built?

From the eye position, a target and an up vector. Compute the forward axis f = normalize(target - eye), the right axis r = normalize(f × up) and a corrected up u = r × f. These three orthonormal vectors form the rotation (as rows in the view matrix) and the translation moves the eye to the origin. The result is the inverse of the camera's own placement.

26. What is the difference between orthographic and perspective projection?

Orthographic projection drops one coordinate along parallel rays, so size does not depend on distance, which suits CAD and 2D games. Perspective projection makes distant objects smaller by dividing x and y by depth, which matches how we see. It is controlled by the field of view, the aspect ratio and the near and far planes.

27. What is the perspective divide?

After the projection matrix, a vertex is in clip space as (x, y, z, w). Dividing by w gives normalized device coordinates (x/w, y/w, z/w). The division is what makes far things shrink; for a standard perspective matrix, w equals the distance in front of the camera.

Order matters for transforms, and the divide makes depth non-linear. Both are easy to see in numbers.

JS Transform order and depth precision

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The second half of the output is the answer to a favorite follow-up question: half of the depth range is used up by the first fraction of a unit, so distant surfaces share very few distinct values.

Visibility, lighting and texturing

These questions come from Back-Face Culling, The Z-Buffer, Light and Reflection, Shading and Texture Mapping.

28. How does back-face culling work, and what does it save?

A closed solid's triangles that face away from the camera can never be seen. With a consistent winding order, the sign of the face normal dotted with the vector to the eye (or the signed screen-space area) tells whether the triangle faces away; if so it is skipped. For a closed convex object that removes about half the triangles before rasterization. It is not enough alone for concave objects.

29. How does the z-buffer work, and what are its weaknesses?

It stores the nearest depth seen so far for each pixel; a fragment is written only if it is nearer. Triangles can come in any order and intersecting surfaces work. Weaknesses are memory, overdraw (hidden fragments may still be shaded), finite precision (z-fighting between nearly coplanar surfaces) and that it cannot handle transparency without sorting.

30. What is z-fighting and how do you fix it?

Two surfaces at almost the same depth get nearly identical stored values, so rounding makes the winner flip pixel by pixel. Fix it by moving the near plane farther out (the biggest gain), reducing the far/near ratio, using a higher-precision or reversed-z buffer, or offsetting one surface slightly (a depth bias).

31. Describe the Phong reflection model.

Light at a surface point is the sum of three terms. Ambient is a constant. Diffuse is kd · max(0, N·L), the Lambert term, which depends on the angle between the normal and the light direction. Specular is ks · max(0, R·V)^n, a highlight that depends on how closely the mirror direction lines up with the viewer; n controls how tight the highlight is. Blinn-Phong uses N·H with the half vector instead of R·V.

32. Compare flat, Gouraud and Phong shading.

Flat shading computes one color per triangle: cheap, faceted. Gouraud shading computes lighting at the vertices and interpolates colors across the triangle: smooth, but can miss highlights that fall between vertices. Phong shading interpolates the normal and computes lighting at every pixel: the best quality and the cost of per-pixel lighting, which is what fragment shaders do today. (Do not confuse Phong shading with the Phong reflection model.)

33. Why does texture mapping need perspective-correct interpolation?

Screen-space linear interpolation of u and v is wrong after perspective, because equal steps on screen are not equal steps on the surface; textures appear to swim and bend on slanted triangles. The fix is to interpolate u/w, v/w and 1/w linearly, then divide per pixel to recover u and v.

34. What are mipmaps?

A chain of pre-filtered copies of a texture, each half the size of the previous one. When a textured surface is far away, many texels fall under one pixel; sampling the right smaller level avoids shimmering and is cache-friendly. Trilinear filtering blends two adjacent levels, and anisotropic filtering handles surfaces seen at a grazing angle.

The pipeline and ray tracing

These questions come from Ray Tracing Basics, Shadows, Reflections and Refraction and The Rasterization Pipeline.

flowchart LR
  A["Vertices"] --> B["Vertex stage<br/>(model, view, projection)"]
  B --> C["Clipping and<br/>perspective divide"]
  C --> D["Viewport<br/>transform"]
  D --> E["Rasterization"]
  E --> F["Fragment stage<br/>(shading, textures)"]
  F --> G["Depth test and<br/>blending"]
  G --> H["Framebuffer"]

The classic rasterization pipeline, which questions 35 and 36 build on.

35. Walk through the stages of the rasterization pipeline.

Vertex processing transforms each vertex to clip space and computes per-vertex data. Primitives are assembled and clipped, then the perspective divide gives normalized device coordinates and the viewport transform maps them to pixels. Rasterization finds the pixels (fragments) each triangle covers and interpolates attributes. The fragment stage shades each fragment, and the output stage runs the depth test, blending and writes to the framebuffer.

36. How does ray tracing differ from rasterization, and how does a ray-sphere test work?

Rasterization loops over triangles and finds the pixels they cover; ray tracing loops over pixels, shoots a ray through each, and finds what it hits. Ray tracing makes shadows, reflections and refraction natural (shoot more rays) but costs more per pixel, so real-time engines combine both. For a sphere with center C and radius r, substitute the ray O + t·D into |P - C|² = r². The result is a quadratic in t whose discriminant says whether the ray misses (negative), grazes (zero) or crosses (positive); the smaller positive root is the nearest hit.

Run the sphere test yourself. The first ray hits the sphere head on, the second passes above it and the third hits near the top edge.

JS Ray-sphere intersection

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. Why does Bresenham's line algorithm avoid the accumulated rounding error of the DDA?

    The decision variable is an integer that is updated exactly at every step, so no rounding error can build up.
  2. 2. With column vectors, what does the matrix product T * R * p do?

    The matrix next to the vector is applied first, so R acts on p and T moves the result. Swapping the order gives a different point.
  3. 3. Which change reduces z-fighting the most?

    Depth precision is concentrated near the near plane; pushing it out spreads usable values over the visible range. Culling and sorting do not change depth precision.
  4. 4. What does a negative discriminant mean in the ray-sphere quadratic?

    A negative discriminant means the quadratic has no real roots, so the ray never reaches the sphere's surface.
  5. 5. Which shading method interpolates normals and lights each pixel?

    Phong shading interpolates the normal across the triangle and evaluates the lighting at every pixel; Gouraud interpolates colors computed at the vertices.

Summary

  • Know the rasterization algorithms by their idea: DDA steps by the larger delta, Bresenham keeps an integer error, the midpoint circle uses eight-way symmetry.
  • Fill and test with the even-odd or nonzero rules, edge functions and barycentric weights; clip with outcodes, parametric t values or one edge at a time.
  • Homogeneous coordinates turn every transform, and the camera and projection, into matrices whose order matters.
  • The z-buffer resolves visibility per pixel; its limits are memory, overdraw, precision and transparency.
  • Lighting is ambient plus diffuse plus specular; the shading mode decides where it is computed.
  • Rasterization loops over triangles, ray tracing over pixels; modern engines mix them.

Finish the track with the Computer Graphics Cheat Sheet.