Computer Science Computer Science major 100% Free Open Access
Chapter 4 • Theory & Derivations

Lighting and appearance

Five original substantive sections, three fully worked problems, two bounded interactive numerical simulations; editorial review outstanding.

§4.1 Light transport and reflection models

What a surface model must explain

A renderer computes the light arriving at a virtual sensor, not an intrinsic color stored inside an object. An orange ceramic cup appears bright in one scene and nearly black in another because illumination, surface response, geometry, exposure, and display transformation all intervene. A useful appearance model must separate these causes. The illumination describes the distribution of incoming radiance over direction and wavelength. The surface model describes how much of that radiance leaves in a chosen viewing direction. Geometry establishes the angle between the light, the normal, and the camera. The camera and display then transform the resulting signal into encoded image values. Treating all these stages as a single RGB multiplication is tempting, but it prevents controlled diagnosis when an image is unexpectedly dark or glossy.

Radiance L is directional power per projected area per solid angle, commonly measured in watts per square metre per steradian. Irradiance E is incident power per unit area, integrated over the incoming hemisphere. These quantities are related, but they are not interchangeable: irradiance has no viewing direction, whereas radiance does. A Lambertian reflector has outgoing radiance that is constant with viewing direction under fixed illumination. Its reflected radiance is L_o = (rho/pi) E for diffuse reflectance rho between zero and one. The factor pi is not decorative. It ensures that integrating constant outgoing radiance against the projected solid angle of the upper hemisphere yields reflected exitance rho E. Omitting pi can create a nonphysical reflector whose output exceeds the incoming energy.

The rendering equation expresses the local energy balance at a surface point x: L_o(x,w_o) = L_e(x,w_o) + integral over the incident hemisphere of f_r(x,w_i,w_o) L_i(x,w_i) max(0,n dot w_i) d omega_i. Here L_e is emitted radiance, f_r is the bidirectional reflectance distribution function or BRDF, and the cosine accounts for the projected surface area seen from an incident direction. For an opaque nonemissive surface, a physically admissible BRDF is nonnegative and must not reflect more energy than arrives. For reciprocal materials, the BRDF is symmetric under exchange of incident and outgoing directions. Real material behavior can be wavelength-dependent, polarized, fluorescent, or nonlocal; the usual RGB BRDF is a practical approximation rather than a universal law.

The common local lighting formula combining an ambient constant, a Lambertian cosine, and a specular power term is useful pedagogically but should not be confused with a general light-transport solution. An ambient constant cannot represent a colored shadow cast by a window. A Phong highlight based on the angle between the reflected light vector and the view vector is a tunable visual effect, not a guaranteed energy-conserving microphysical model. A Blinn–Phong highlight uses a halfway vector, which can be cheaper or more convenient but likewise requires careful normalization if physical claims are made. Such models remain appropriate for illustrative diagrams, simple games, and controlled teaching examples where speed and clarity outweigh strict material realism.

A numerical renderer needs conventions for all direction vectors. Decide whether w_i points from the surface toward the light or describes the propagation direction toward the surface; the two differ by a sign. Normalize n and w_i before taking their dot product. Clamp the cosine to zero for light behind an opaque surface. If a normal map perturbs the shading normal, distinguish it from the geometric normal used for sidedness, visibility, and ray-origin offsets. A shading normal can make a surface appear tilted without actually moving its geometry, so it cannot legitimately repair a silhouette or a cast-shadow boundary. A test scene with a single white diffuse plane and one directional light is a valuable calibration target: rotating the plane from facing the light to grazing incidence should change its response predictably.

Spectral response, RGB approximations, and exposure

Physical light is distributed over wavelengths, while a typical real-time renderer stores three channels. The three channels are not literal samples at three uniquely defined wavelengths. They are coordinates in a color representation derived from assumptions about human vision and primaries. When a spectral green light strikes a red pigment, the response may be small even if both objects have high numeric values in different RGB channels. Spectral rendering can model wavelength-selective effects, dispersion, and some complex materials more faithfully, but it costs more memory and computation. For many graphics tasks, a carefully managed linear RGB pipeline is an acceptable engineering compromise.

Linear-light arithmetic matters. If two pixels encode display values 0.2 and 0.8 in a nonlinear transfer function, their arithmetic mean 0.5 is generally not the encoded value of the mean physical light. Convert to linear light, combine or filter, then encode for display. Likewise, exposure multiplies scene-linear radiance before tone mapping; it should not be applied by blindly scaling an already tone-mapped image if the intention is to model a camera exposure change. Tone mapping compresses high dynamic range into a limited display range, often sacrificing one-to-one luminance relationships to preserve visible detail. Two renderers can therefore compute the same radiance and produce different screenshots if their tone maps, white balance, and output transfer functions differ.

The distinction is important in quantitative visualization. If color is used to encode measured temperature, a cinematic tone map can destroy the meaning of equal increments unless the mapping is documented. In a scientific plot, the color bar is part of the measurement specification. In a cinematic scene, a perceptually pleasing response may be the primary objective. Neither choice is universally superior; the failure occurs when one is used while claiming the properties of the other. Record the working color space, transfer function, exposure, and any display-referred transformations whenever appearance comparisons are intended to be reproducible.

§4.2 Materials and microfacet reasoning

From ideal diffuse surfaces to rough conductors

A material is not simply a base-color triplet. It is a model of how the surface interacts with incident light, often parameterized by roughness, metallic character, absorption, and normal structure. Dielectrics such as plastic or uncoated glass have a specular reflection at their interface and may also transmit or scatter light beneath the surface. Metals have wavelength-dependent complex refractive indices and typically show colored specular reflection. An artist-friendly metallic-roughness workflow approximates these differences with a compact parameter set. It is valuable because the same parameters can respond plausibly under many lighting environments, not because every value corresponds to a directly measured laboratory quantity.

A microfacet model treats a rough surface as an ensemble of tiny facets with a statistical distribution of orientations. The distribution function D specifies the prevalence of facet normals; a Fresnel term F describes angular reflectance at an interface; and a geometry term G accounts for masking and shadowing between facets. A common conceptual structure is f_spec = D F G / [4 (n dot w_i)(n dot w_o)], with safeguards at grazing angles and model-specific definitions for the terms. Roughness broadens the distribution of orientations and usually broadens highlights. It does not simply reduce brightness by a fixed factor: a wider highlight can cover more pixels while maintaining an energy budget. A metallic workflow typically reduces the separate diffuse contribution as metallic behavior increases, but its exact interpolation is a design choice in the material system.

At a smooth dielectric interface, Fresnel reflectance generally increases toward grazing incidence. This explains why water viewed near the horizon can strongly reflect the sky while water viewed steeply downward reveals more of what is below. The normal-incidence reflectance of a nonabsorbing interface with refractive indices n1 and n2 is R0 = ((n1-n2)/(n1+n2)) squared. For air with n1 approximately 1 and a dielectric with n2=1.5, R0 is 0.04, or four percent. That figure is not the total apparent brightness of a glass pane; it describes a particular interface at normal incidence, and additional surfaces, absorption, and transmission affect the complete observation.

Surface roughness is scale-dependent. A polished table can appear smooth from across a room and scratched in a close-up. A roughness texture sampled without proper filtering can flicker as the camera moves because fine normal variations alias into high-frequency specular highlights. Some rendering systems compensate with normal-map filtering or roughness adjustment based on unresolved normal variance. These are not merely artistic hacks: they attempt to preserve the aggregate appearance of subpixel surface structure. The practical validation is temporal as well as spatial. A single attractive frame may conceal sparkling highlights that become objectionable in animation.

A physically plausible material system is still a model. Anisotropic brushed metal, layered automotive paint, cloth fibers, translucent wax, and subsurface skin scattering require additional assumptions or specialized closures. Do not label a generic rough metallic shader as a measurement-grade reconstruction of all these phenomena. Choose a model by the questions it must answer. For an interactive product configurator, consistency under a few representative environments may matter more than spectral precision. For inverse rendering of a measured material, calibration against known lights and reference samples may be essential.

§4.3 Textures, filtering, and coordinate meaning

Why a texture lookup is not just an array access

Texture coordinates map a geometric surface to a parameter domain, often a square with coordinates u and v. The mapping can stretch, rotate, overlap, or split at seams. A photograph projected onto a mesh does not automatically have uniform spatial resolution: one texel can cover a large surface patch in one region and a tiny patch elsewhere. UV distortion is therefore relevant both to visual quality and to any claim that a texture represents a measured physical field. An artist may deliberately reuse UV islands to save memory, whereas a scientific atlas may require a one-to-one mapping to avoid ambiguity.

At rendering time, a screen pixel often covers an area in texture space rather than a single point. Sampling one texel at the pixel center ignores the rest of the footprint and can produce shimmering or moiré patterns. Mipmapping stores successively downsampled versions of the texture. A renderer estimates the texture footprint from derivatives of texture coordinates across neighboring fragments and chooses a level of detail. Bilinear filtering combines four nearby texels within a level; trilinear filtering blends between two mip levels. Neither technique fully solves anisotropic footprints, such as a road texture viewed toward the horizon. Anisotropic filtering takes multiple samples or uses an elongated footprint approximation to better preserve directional detail.

Texture filtering must respect the meaning of stored data. Albedo or emission values intended as light should be filtered in an appropriate linear representation. Surface normals stored in a normal map are directions, not colors: decode them to vectors, combine appropriately, and renormalize when needed. A height map is a scalar geometric field, so its interpretation differs from a roughness parameter that influences a nonlinear reflectance model. A normal map that looks visually blue should not be treated as a blue material. The fact that several kinds of data fit in three image channels does not make their operations interchangeable.

Normal mapping typically transforms a texture-space normal through a tangent, bitangent, and normal basis into the space used by lighting calculations. Tangent handedness and UV mirroring must be handled consistently. Otherwise a raised groove can appear inverted on mirrored islands. A normal map modifies local shading but not the actual outline; displacement mapping changes geometry and can affect silhouettes and shadows. Parallax techniques approximate the view-dependent offset of texture features without necessarily creating real geometry. Choose based on viewing distance and the evidence the final image must preserve.

Texture memory is a systems concern. An uncompressed 4096-by-4096 RGBA image with four bytes per texel requires about 67 megabytes before mip levels; a full mip pyramid adds approximately one third for large power-of-two textures. Compressed formats reduce storage and bandwidth but may introduce block artifacts, especially in smooth gradients or normal data. Streaming higher-resolution mip levels only when needed reduces peak memory but creates a risk of visible resolution changes. Texture atlases reduce binding overhead in some pipelines but can bleed neighboring colors across mip levels unless sufficient padding is maintained.

Texture coordinate validation in a reproducible scene

A reliable UV test object contains labeled axes, a checkerboard, and a few asymmetric symbols. A plain repeating checkerboard can conceal mirrored orientation because it looks similar after a flip. Inspect the mesh from several angles, including UV seams. Apply known transformations to u and v independently to verify which axis points in which direction. At high minification, move the camera gradually and inspect for temporal aliasing. Compare the result with a mipmapped version, keeping exposure and tone mapping fixed. This isolates filtering behavior from unrelated appearance changes.

A procedural texture is a function rather than a stored photograph. A checker pattern can be computed from the parity of integer grid coordinates; a noise function can produce varied scales of detail. The key challenge is still sampling. A mathematically sharp checkerboard contains arbitrarily high spatial frequencies at its boundaries. Rendering it by a point sample aliases even if no texture image exists. Analytic filtering or derivative-aware approximations can integrate over the pixel footprint. Procedural generation does not exempt an image from the sampling theorem.

§4.4 Shading and normal interpolation

The location of computation changes the image

Flat shading evaluates one representative normal for a polygon, often producing a faceted appearance. Gouraud shading evaluates lighting at vertices and interpolates the resulting colors. Phong shading, in its interpolation sense, interpolates normals across the surface and evaluates lighting per fragment. These terms describe where normals or lighting are interpolated; they should not be confused with the separate Phong specular reflectance formula. A highlight narrower than a triangle can disappear under vertex lighting because no vertex samples the peak. Per-fragment lighting can capture it, although a coarse geometric mesh still limits silhouette accuracy and correct visibility.

Interpolated normals should generally be renormalized before use. Linear interpolation of two unit vectors does not preserve unit length except in special cases. For example, averaging perpendicular unit vectors produces a vector of length sqrt(1/2). If a shader uses this vector directly in a cosine lighting term, the apparent brightness is reduced for a reason unrelated to the actual surface orientation. Renormalization removes this artifact but does not turn a low-resolution mesh into a geometrically accurate surface. The normal is a shading assumption that can differ from the face's geometric orientation.

Under perspective projection, attributes attached to vertices generally require perspective-correct interpolation. Simple screen-space barycentric interpolation of UV coordinates can distort a textured plane. If a projected vertex has clip-space w, interpolate the attribute divided by w and interpolate reciprocal w, then divide the two results. This correction follows from the projective relationship between screen position and geometry. For attributes that are already defined in screen space, linear screen interpolation may be correct. A graphics programmer must know which space an attribute inhabits before selecting its interpolation rule.

Shadows introduce a separate visibility question. A surface may face a light yet receive none of its direct contribution because another object blocks the path. A shadow map stores a depth image from the light's point of view and compares receiver depth against the stored value. Bias is needed to avoid false self-shadowing due to finite precision, but excessive bias detaches shadows from contact points. Percentage-closer filtering can soften jagged shadow boundaries by combining multiple depth comparisons; it does not automatically simulate a physically correct area light. For physically motivated soft shadows, light-source extent and visibility integration must be considered.

A controlled diagnostic workflow

When a material looks wrong, change one subsystem at a time. First render the surface normal as an RGB visualization and check that normals are normalized and oriented consistently. Next render a grayscale cosine term under a single known directional light. Then add a constant diffuse reflectance, followed by the specular term. Test the texture in isolation with unlit output. Finally restore shadows, indirect light, exposure, and tone mapping. This order prevents a broken tangent frame from being hidden by an attractive environment map. It also produces intermediate images that a reviewer can compare numerically.

Unit tests can verify mathematical properties even when a final render is subjective. The cosine term must be zero for a light behind an opaque plane. The Fresnel normal-incidence formula must remain between zero and one for positive refractive indices. A normalized interpolated normal must have length approximately one unless the input vectors cancel exactly. A mipmap level estimate should increase as a texture footprint expands. Pixel comparisons require tolerances and a defined rendering environment; a single exact screenshot hash is fragile across GPU vendors and drivers. For deterministic educational demonstrations, pure mathematical kernels are preferable to screenshots as the primary correctness oracle.

§4.5 Integrated investigation: an outdoor product visualization

Separate the appearance errors instead of retouching them

Imagine a product team rendering a painted metal bicycle frame for an online configurator. Under a studio environment the frame looks convincing, but in an outdoor scene the highlights appear too sharp, the paint looks unnaturally dark, and the decals shimmer while the camera moves. The team could compensate by manually brightening the base color, blurring the reflection map, and increasing decal resolution. Those edits may improve one screenshot while making the material inconsistent across other views. A more reliable investigation treats each symptom as a hypothesis about the rendering pipeline.

Begin with a neutral calibrated light and a diffuse reference sphere. Verify that the scene uses linear-light operations before tone mapping and that output encoding occurs once. Compare the painted frame under a known environment with the same frame rendered using an untextured constant albedo. If both appear too dark, investigate exposure, light intensity, and color management rather than the decal file. If only the textured version is dark, check whether a nonlinear image was incorrectly interpreted as linear or encoded twice. Document the input color profile and texture import flags so the result can be reproduced on another workstation.

For the highlight width, inspect the roughness map and the normal-map frequency. A low roughness value produces concentrated microfacet highlights; unresolved normal variations can add sparkle when the object is distant. Increase roughness only if the actual material is too smooth, not merely to suppress aliasing. If the close-up looks correct but the distant image flickers, evaluate filtered normal maps, prefiltered environment reflections, and temporal sampling. Compare sequences of frames, not just a still. A temporal variance metric over a stationary patch can expose instability that an art review misses.

For decal shimmer, display UV derivatives or estimated mip levels and verify that mipmapping is active. A 4K source image does not solve minification aliasing when the visible decal occupies only ten pixels. Inspect anisotropic filtering at grazing angles, check atlas padding, and confirm that transparent edges are handled in an appropriate alpha representation. Premultiplied-alpha textures can avoid dark fringes under interpolation if the compositing and filtering pipeline consistently uses that convention. The team should record the selected settings and compare a fixed camera path before and after changes.

Finally evaluate the visual claim. If the configurator is for color choice, the lighting and display pipeline should be stable enough that customers can compare finishes meaningfully, while still acknowledging that consumer displays are not calibrated. If the rendering is for engineering surface inspection, artistic tone mapping and aggressive normal mapping may obscure defects and should be disabled or clearly separated from measurement views. The same scene can support both purposes through different documented render modes. The investigation succeeds when its decisions are traceable to the underlying light, material, texture, and shading mechanisms rather than arbitrary retouching.

THREE WORKED QUESTIONS

Step-by-Step Programming Fundamentals Solutions

Three original questions connect calculations, definitions and interpretation. Open each solution to follow the reasoning.

Worked original editorial example Example 4.1: Lambertian reflection and angular response

A nonemissive diffuse patch has reflectance rho=0.6. A collimated source produces irradiance E=100 W/m² on a patch facing the beam. Find the outgoing radiance for the facing patch. Then rotate the patch so the incident direction makes an angle of 60 degrees with the normal while the beam strength per area perpendicular to the beam remains unchanged. Assume no shadows or other light sources.

Use the diffuse BRDF.

For an ideal Lambertian material, fr=rho/pi sr^-1. At normal incidence, E=100 W/m² and Lo=fr E=60/pi, approximately 19.099 W/(m² sr). This result is independent of the observer direction over the outgoing hemisphere; the apparent projected area of the patch changes with viewing direction, but radiance itself remains constant for this model.

Apply projected-area geometry.

Tilting the patch changes irradiance from the same beam to Etheta=100 cos(60 degrees)=50 W/m². The new outgoing radiance is 0.6 times 50 divided by pi, approximately 9.549 W/(m² sr). The factor of one half comes from geometry, not from changing the material's reflectance.

Check energy.

Reflected exitance at normal incidence is 60 W/m², less than incident 100 W/m². After tilt it is 30 W/m², less than incident 50 W/m². If an implementation produces reflected exitance greater than incoming irradiance under these assumptions, it violates the stated diffuse energy budget.

Final Answer & Physical Insight

About 19.099 W/(m² sr) facing the beam and 9.549 W/(m² sr) after a 60-degree tilt.

Worked original editorial example Example 4.2: Fresnel reflectance at normal incidence

A light ray encounters a flat interface between air of refractive index 1.0 and a nonabsorbing dielectric of refractive index 1.5. Calculate the unpolarized power reflectance at normal incidence and the fraction entering the material at that interface, ignoring absorption and multiple reflections.

Choose the appropriate relation.

At normal incidence the Fresnel reflectance for nonabsorbing media is R0=[(n1-n2)/(n1+n2)]². The simplified expression applies at the interface; it is not a model of an entire glass sheet with front and back surfaces.

Substitute.

The ratio is (1-1.5)/(1+1.5)=-0.5/2.5=-0.2. Squaring gives R0=0.04. Thus four percent of incident power is reflected at this interface. Conservation of energy for this lossless interface gives transmitted power fraction 1-R0=0.96.

Interpret limitations.

The 96 percent transmission fraction is an energy-flow statement at the interface. It does not mean a camera sees exactly 96 percent of a background through a thick pane; attenuation, angle, polarization, and a second interface matter. For a conductor, the refractive index is complex and this simplified dielectric formula is insufficient.

Final Answer & Physical Insight

Normal-incidence reflectance 0.04; transmitted fraction 0.96 for the stated idealized single interface.

Worked original editorial example Example 4.3: Mipmap memory and texture filtering

An uncompressed RGBA8 texture is 1024 by 1024 texels. Calculate its base-level memory in bytes and the memory of a complete mip pyramid down to 1 by 1. Explain why the additional memory is useful and why it does not remove all aliasing.

Count the base level.

RGBA8 stores four 8-bit channels, or four bytes per texel. The base level contains 1024²=1,048,576 texels and uses 4,194,304 bytes, exactly 4 MiB.

Sum all levels.

The dimensions halve each level, so the texel counts form 1024²+512²+...+1². This is a finite geometric sum with ratio 1/4: total texels=(4×1024²-1)/3=1,398,101. Multiply by four bytes to obtain 5,592,404 bytes, approximately 5.333 MiB. The additional 1,398,100 bytes are about one third of the base-level storage.

Explain filtering scope.

A mip pyramid provides prefiltered approximations for roughly isotropic minification. Choosing levels using screen-space derivatives reduces high-frequency flicker. A highly elongated texture footprint still requires anisotropic filtering or a better footprint integral, and alpha edges or nonlinear color values require careful preprocessing. The pyramid also does not prevent aliasing caused by undersampled geometric edges.

Final Answer & Physical Insight

Base level 4,194,304 bytes; full pyramid 5,592,404 bytes. Mipmaps reduce texture minification aliasing but do not solve every sampling problem.