Past exam of the computer science course of the University of Oxford 2015 Computer graphics 3 e Solution by
Codex 0 2026-10-31
At each primary hit , send a shadow ray toward each point light. An especially clear parameterization isIf an opaque scene surface intersects this open segment, the source is hidden. The finite interval is essential: an object beyond the light must not cast a shadow at . Exclude the launch surface with a small geometrically appropriate origin offset or positive minimum parameter, so floating-point arithmetic does not create a false self-intersection.
Introduce a visibility factor equal to zero when blocked and one otherwise. The modified equation isA blocked light loses both its diffuse and specular contributions. The simple ambient approximation remains. Opaque point lights produce hard shadow boundaries. Use a consistent sidedness policy for occluders: an opaque closed solid blocks from either crossing side, so a two-sided blocker test is appropriate even when primary visibility uses back-face culling. An any-hit query can stop as soon as it finds one blocker before the light.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 3 d Solution by
Codex 0 2026-10-31
For single-shot ray tracing, construct one primary ray per pixel, normally through its centre on the image plane, with the camera centre as origin for perspective projection. Transform the ray into the scene's coordinates, or consistently transform all the scene geometry into camera coordinates.
Intersect that primary ray with the scene's triangles, using part (c), and retain the accepted hit with the smallest nonnegative parameter . This nearest-hit selection supplies visibility: farther surfaces cannot show through the first opaque surface. If there is no hit, write the background colour. At a hit , obtain its material colour and front unit normal vector and set toward the camera.
For each point light at , form , calculate the specular reflection direction, and evaluate its diffuse and specular contributions using the Phong reflection model. Sum the contributions and add ambient illumination once:The coloured surface can supply colour-dependent diffuse weights, and each source can have its own colour. Convert the result into the output image's colour encoding and range. Single-shot here means direct local shading after one primary visibility ray; no reflected or transmitted secondary viewing rays are followed. Part (e) adds secondary visibility queries for the lights.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 3 c Solution by
Codex 0 2026-10-31
Let the oriented vertices be , in an order such that points out of the front face. The given nondegeneracy guarantees . A ray with nonzero direction approaches the front face only ifReject . This combines back-face culling with rejection of parallel rays, including the coplanar case for this ordinary surface-hit test. The ray-plane intersection parameter isReject ; for rays launched from existing surfaces use a positive lower cutoff to avoid counting the launch surface. Form .
Finally determine whether lies inside the triangle. For , , , computeThese solve . The barycentric coordinates are , so the complete acceptance criterion isThe inequalities include the edges and vertices. A renderer sharing edges between triangles should use a consistent numerical edge convention; small floating-point arithmetic errors near a shared boundary should not create cracks. Normalizing is unnecessary for this intersection calculation because its scale cancels.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 3 b Solution by
Codex 0 2026-10-31
A bidirectional reflectance distribution function, or BRDF, describes how a surface scatters incident illumination into each outgoing direction. At a fixed surface point and wavelength, its inputs are two directions above the surface, toward the incident source and toward the observer; equivalently these are two pairs of angular coordinates. Its output is the ratio of differential reflected radiance to differential incident irradiance:Position and wavelength may be additional arguments when material properties vary. A colour implementation can return one value per colour channel. The BRDF is a material response, not the final outgoing light value: it must be combined with the incident illumination and the projected-angle factor.[ref]
Physically Based Rendering: From Theory to Implementation (4th edition) by Matt Pharr and others. §4.3.1, definition of the BRDF as differential outgoing radiance divided by differential incident irradiance
For incident radiance , the reflection part of the rendering equation isEmission is added separately if the surface itself emits. This integral explains how a BRDF replaces the assumed material response of a local lighting model. For Lambertian reflectance, , so the cosine factor yields the diffuse term from part (a). A directional specular lobe supplies a highlight. The empirical Phong reflection model is an approximate angular-response model of this kind; its original direct specular term is not automatically a normalized, energy-conserving BRDF. The ambient term approximates missing illumination and is not itself a third direction-independent material scattering mechanism. More general BRDFs can reproduce measured surface behaviour, while illumination from other surfaces supplies indirect light in the rendering equation.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 3 a Solution by
Codex 0 2026-10-31
At a surface point , let be the outward unit normal vector, the unit vector from toward the viewer, and the unit vector from toward the light. The incoming propagation direction is therefore . The specular reflection direction points away from the surface along the ideal reflected ray.
Resolve into its normal and tangential components:Reflection of the incoming direction preserves its tangential component and reverses its normal component. Equivalently, the outgoing direction has the same normal component as and the opposite tangential component, givingThe dot product identity shows when .
In the Phong reflection model, ambient lighting approximates unmodelled indirect illumination and is independent of these directions. The diffuse term models Lambertian reflectance and varies as . The specular term models a highlight around and varies as , where controls its sharpness. For a visible front surface, a convenient per-colour-channel equation iswhere is ambient illumination, is the source strength at the surface including any chosen attenuation, are material weights, and is one when and zero otherwise. The weights can be colour-dependent. An idealized point source's incident strength decreases as inverse distance squared; the empirical equation can also use a prescribed attenuation law.
In degenerate geometric cases the effective weights switch off. A light behind or tangent to the surface contributes neither direct diffuse nor specular illumination. If , the specular term is zero. A viewpoint on the back side is rejected by back-face culling for a one-sided surface. A material with no highlight has ; with no diffuse response, ; without ambient illumination the ambient term vanishes. These zeros do not require renormalizing the other weights, and the empirical Phong reflection model does not impose a universal condition . At coincident light/surface or eye/surface positions a direction cannot be normalized; such singular configurations require a separate convention, rather than substituting an undefined unit vector into the formula.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 1 e Solution by
Codex 0 2026-10-31
After every proposed pixel has passed part (d), insist on exactly one call in every column of the closed endpoint interval:
void final()
{
for (int x = x0; x <= x1; x++) {
if (counter[x] != 1) reject();
}
accept();
}Part (d) already rejected every out-of-range column and every incorrect ordinate. A zero counter now detects an omitted column; a counter greater than one detects a repeated call in that column. Because the residual interval in part (d) allows exactly one integer ordinate in each column, accepted calls in a repeated column must address the same pixel. Conversely, a counter of one in every column forces the complete set of nearest pixels, including both endpoints. Consecutive correct columns differ in ordinate by at most one, which proves that there are no gaps in the resulting thin line segment.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 1 d Solution by
Codex 0 2026-10-31
The verifier can check the final geometric criterion directly, independently of the incremental decision variable. Set , , and define the scaled vertical residualThe exact line ordinate is , so . Nearest-integer selection with upward ties is preciselyThe strictness matters: at a half-integer ordinate the upper pixel has and passes, whereas the lower pixel has and fails. Each column has exactly one accepted integer ordinate.
With
reject() terminating verification unsuccessfully, suitable outline code is:void checkPoint(int x, int y)
{
Wide a = Wide(x) - x0;
if (a < 0) reject(); // inequality 1
Wide b = Wide(x1) - x;
if (b < 0) reject(); // inequality 2
Wide dx = Wide(x1) - x0;
Wide dy = Wide(y1) - y0;
Wide e = 2 * dy * a - 2 * dx * (Wide(y) - y0);
Wide lower = e + dx;
if (lower < 0) reject(); // inequality 3
Wide upper = dx - e;
if (upper <= 0) reject(); // inequality 4
counter[x]++;
}Wide denotes a signed integer type large enough for the products and differences, with conversion before subtraction. These are exactly four inequalities against zero, all applied to named integer variables. The arithmetic restriction on the drawing loop in part (c) does not restrict multiplication in this verifier. The screen endpoints are assumed valid, with and valid endpoint ordinates, so indexing is safe after the first two checks. These endpoint and screen preconditions belong in initialization if they are not guaranteed by the caller.No separate -range tests are needed: for between the endpoints, lies in , and its nearest integer lies in the same interval because both bounds are integers. The counters defer detection of omissions and repetitions to part (e). As for every finite counter, use adequate capacity or a sticky failure on overflow; saturating each counter at two also suffices because only zero, one, and “more than one” matter.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 1 c Solution by
Codex 0 2026-10-31
Multiply the midpoint line decision by two to remove the fraction. At the current pixel , maintainAt the initial endpoint this is . If is chosen, the next decision midpoint is displaced by and increases by . If is chosen, its displacement is and increases by . Both increments are constant, so the per-pixel work uses only integer arithmetic:The completed code, using the tie rule of part (b), is:
void midpointLine(int x0, int y0, int x1, int y1)
{
int dx, dy, incrE, incrNE, d, x, y;
x = x0; y = y0;
dx = x1 - x0;
dy = y1 - y0;
incrE = 2 * dy;
incrNE = 2 * (dy - dx);
d = 2 * dy - dx;
drawPoint(x, y);
while (x < x1) {
if (d < 0) {
d += incrE;
} else {
d += incrNE;
y++;
}
x++;
drawPoint(x, y);
}
return;
}Thus
guard1 is x < x1, and guard2 is d < 0. Multiplication by two is the only multiplication. Signed decision variables are convenient because and incrNE can be negative; this remains an integer arithmetic algorithm. A strictly unsigned hardware representation would need an equivalent biased or separated-sign encoding. As with the printed int skeleton, assume all intermediate values fit the chosen type; integer overflow would invalidate the mathematical decisions.To verify the geometry, write . The chosen ordinate isThe midpoint line decision selects exactly this nearest integer, rounding halves upward. Its increment between successive columns is zero or one. At and , it gives exactly and , respectively, so both endpoints are included and the line segment has precisely distinct pixels.
For the illustrated endpoints and , the ordinates are . In particular the exact ordinate at is , and the chosen pixel is .
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 1 b Solution by
Codex 0 2026-10-31
By exchanging axes, reversing endpoint order and reflecting coordinate signs where necessary, reduce a general line segment to the first octant:The vertical case is handled by exchanging axes. In this octant, increasing by one requires increasing by either zero or one. Thus, from the currently plotted pixel the candidates are and .
Use the implicit equation of the lineAt a fixed , means that lies below the exact line. The midpoint line decision evaluates , halfway between the two candidate pixel centres. If , the exact line lies below , so choose ; if , choose . At equality either candidate is equally near, but a fixed tie rule is essential. We choose on a tie throughout these solutions:This chooses the closest vertical-grid pixel centre in each column, with ties rounded upward. Since , the result has one pixel per column and consecutive pixels share an edge or a corner.
Past exam of the computer science course of the University of Oxford 2015 Computer graphics 1 a Solution by
Codex 0 2026-10-31
Three advantages of integer arithmetic for raster graphics are:
- Cheap, fast operations. Historically, integer addition, subtraction and shifts needed much less hardware and execution time than floating-point arithmetic, especially on machines without a floating-point unit. An incremental Bresenham's line algorithm needs only a few additions and a decision per pixel.
- Exact decisions. Provided integer overflow is excluded, the scaled midpoint line decision is exact. There is no accumulated rounding error that can move a decision across a half-pixel boundary; equality has a reproducible tie rule.
- Simple storage and hardware. Integer coordinates already identify pixels. An implementation can keep coordinates and decision variables in ordinary registers and use a small add/compare datapath, avoiding conversion between floating-point numbers and integer screen addresses.
Past exam of the computer science course of the University of Oxford 2015 Computer architecture 3 b Solution by
Codex 0 2026-10-31
Use two different shared locations
x and y, initially zero, and two CPU cores. The following are architectural memory operations, with each result kept in its own processor register:| Core 0 | Core 1 |
|---|---|
STORE [x], 1 | STORE [y], 1 |
LOAD r0, [y] | LOAD r1, [x] |
Each CPU core can retire its write into its own store buffer. Before either write drains, Core 0's load instruction misses its own store buffer because it asks for
y, while Core 1's asks for x. Both can read the old shared values. Afterwards the buffers drain and both locations become one. ThusThere is no contradiction with cache coherence: each location still has an agreed write order. The unusual observation concerns ordering across two different locations. This is the standard store-buffering example, also permitted by total store order.[ref]On a single CPU core executing the two logical participants in an ordinary thread interleaving, the same pair of zero observations is impossible under the usual shared-buffer and own-write-forwarding behavior. To read
y=0, Core-0's logical read must precede the other participant's write of y; to read x=0, the other read must precede the write of x. Combining these requirements with each participant's program order gives the impossible cycleIf a write is still buffered across a context switch on that single CPU core, a later read of the same address sees it through store-to-load forwarding rather than returning an older value. Hence separate store buffers on different CPU cores enable the observation; the comparison assumes ordinary coherent cacheable computer memory and no device accesses or additional writes. A locally completed store need not yet be visible to another core. Past exam of the computer science course of the University of Oxford 2015 Computer architecture 3 a Solution by
Codex 0 2026-10-31
A small memory cache close to the CPU can be accessed quickly, but cannot hold the entire useful data set. Increasing its capacity usually increases lookup, wiring and energy costs. A cache hierarchy combines a small fast first level with progressively larger levels that reduce the number of accesses reaching slow main computer memory.
In a simple serial two-level timing model, let be the first-level lookup time, its cache miss rate, the additional second-level lookup time, the second level's local cache miss rate conditional on a first-level miss, and the remaining main-memory cost. ThenThis average memory access time combines the common fast path with a rarer large-capacity path. Several levels balance hit latency, capacity, cost and traffic; making one cache very large does not preserve a tiny first-level hit time. Temporal locality and spatial locality make this arrangement useful.
There are unlisted articles, also show them or only show them.
