Computer GraphicsUnit 1014 min read
Special Topics in CG: Ray Tracing, Fractals, Animation & Advanced Rendering
Unit 10 of Computer Graphics explores cutting-edge techniques beyond core rendering: ray tracing algorithms, procedural generation (fractals), keyframe animation principles, and advanced illumination models like global illumination. It bridges theory (e.g., recursive ray casting) with practical applications (e.g., Pixa
Key points
- **Ray tracing** uses recursive reflection/refraction to simulate physically accurate lighting, but requires \(O(n^2)\) complexity for \(n\) rays.
- **Fractals** generate infinite complexity from simple rules (e.g., Mandelbrot set), enabling procedural terrain or textures without manual modeling.
- **Keyframe animation** interpolates between poses using splines (e.g., Bézier curves) to create smooth motion, while inverse kinematics solves joint hierarchies.
- **Global illumination** (e.g., photon mapping) simulates indirect light but trades realism for compute cost, unlike local models like Phong shading.
- **Hardware standards** (e.g., OpenGL, Vulkan) abstract APIs to leverage GPUs, while **software standards** (e.g., SVG, VRML) ensure cross-platform compatibility.
- **Challenges** include real-time performance (e.g., path tracing vs. rasterization) and perceptual trade-offs (e.g., aliasing in anti-aliasing methods).
- ```
1. Ray Tracing: The Physics of Light Simulation
Ray tracing simulates the path of light by tracing rays from the camera backward into a scene, calculating intersections with objects and applying reflection/refraction laws. Unlike rasterization (which paints pixels), it models global illumination by recursively bouncing rays to simulate indirect lighting.
How It Works
- Primary rays: Shot from the camera through each pixel.
- Intersection tests: For each ray, check against geometric primitives (spheres, triangles) using:
- Ray-sphere intersection: Solve quadratic equation for closest hit.
- Ray-triangle intersection: Use barycentric coordinates or Möller-Trumbore algorithm.
- Shading: At intersection points, compute:
- Local illumination: Phong/Blinn-Phong models.
- Global effects: Reflection (mirrors), refraction (glass), shadows (occlusion tests).
- Recursion: For reflective/refractive surfaces, spawn secondary rays.
Mathematical Core: Ray-Sphere Intersection
For a ray and sphere centered at with radius : Expanding yields a quadratic in : Solve for to find intersection points.
Example: Simple Scene
Setup:
- Camera at , looking at origin.
- Red sphere: center , radius , color .
- White floor: plane .
Trace a ray through pixel (normalized device coordinates):
- Convert to world space: , .
- Intersect with sphere: Plugging in values gives (hit sphere) and (hit floor).
- Color: At , normal . Compute lighting using Phong model.
Advantages/Disadvantages
| Pros | Cons |
|---|---|
| Photorealistic results (e.g., Toy Story). | Slow ( per pixel). |
| Natural soft shadows, caustics. | Memory-intensive (scene storage). |
| Supports complex materials (subsurface scattering). | Hard to optimize for real-time. |
Optimizations:
- Spatial partitioning: BVH (Bounding Volume Hierarchy) or kd-trees to cull empty space.
- Acceleration: Embree (Intel), OptiX (NVIDIA) use GPU ray tracing.
- Approximations: Path tracing (Monte Carlo) for stochastic sampling.
2. Procedural Generation: Fractals and L-Systems
Procedural content generation (PCG) creates data algorithmically. Fractals and L-systems enable infinite complexity from simple rules.
Fractals: Infinite Detail from Recursion
A fractal is a set of points with self-similarity at all scales, defined by iterative functions. Key types:
- Geometric fractals: Koch snowflake, Sierpiński triangle.
- Random fractals: Perlin noise (used in terrain generation).
- Fractional Brownian motion (fBm): Sum of octaves for natural-looking textures.
Example: Mandelbrot Set Define , where is a complex parameter. The set is all for which remains bounded.
def mandelbrot(c, max_iter):
z = 0
for n in range(max_iter):
if abs(z) > 2: return n
z = z*z + c
return max_iter
Visualization:
")
Applications:
- Terrain generation (e.g., Minecraft biomes).
- Texture synthesis (e.g., clouds, wood grain).
- Antialiasing (fractal noise for smoother edges).
L-Systems: Formal Grammars for Growth
Lindenmayer systems define growth via rewriting rules. Example: Plant growth:
- Alphabet:
F(draw forward),+(turn left),-(turn right),[(push),](pop). - Axiom:
F. - Rules:
F → F[+F]F[-F]+F.
Iteration:
- Start:
F - After 1 iteration:
F[+F]F[-F]+F - After 2 iterations:
F[+F[+F]F[-F]+F]F[-F[+F]F[-F]+F]+F
Visualization:
graph TD
A[F] --> B[F[+F]F[-F]+F]
B --> C[F[+F[+F]F[-F]+F]F[-F[+F]F[-F]+F]+F]
C --> D[Complex plant structure]
style A fill:#f9f, B fill:#bbf, C fill:#f99, D fill:#f66Applications:
- Botanical modeling (e.g., Spore creatures).
- Architectural designs (e.g., Gothic arches).
- Animation rigging (e.g., hair/fur simulation).
3. Animation Techniques: Keyframes and Inverse Kinematics
Animation brings static scenes to life via motion synthesis. Two core methods:
A. Keyframe Animation
Define keyframes (critical poses) and interpolate between them. Steps:
- Pose keyframes: Animate character at frames 1, 10, 20 (e.g., walk cycle).
- Interpolation: Use splines (e.g., Bézier, B-splines) to smooth transitions.
- Linear interpolation: .
- Cubic interpolation: .
- Hierarchical rigging: Parent-child relationships (e.g., arm → hand → fingers).
Example: 2D Bézier Curve for Arm Motion Given control points : Visualization:
flowchart TD
A["Keyframe 1\n(t=0)"] -->|Bézier Curve| B["Keyframe 2\n(t=1)"]
A --> C["Control Point 1"]
A --> D["Control Point 2"]
B --> E["Control Point 3"]
B --> F["Control Point 4"]
style A fill:#f96, B fill:#6f9, C fill:#9f6, D fill:#f96, E fill:#6f9, F fill:#9f6B. Inverse Kinematics (IK)
Solves for joint angles to achieve a goal position (e.g., hand touching an object). Steps:
- Define end effector (e.g., hand) and target.
- Use Fabrik (Forward And Backward Reaching IK) or CCD (Cyclic Coordinate Descent).
- Iteratively adjust joints to minimize distance to target.
Example: 2-Link Arm IK Given:
- Joint 1 at , length .
- Joint 2 at , length .
- End effector target .
Solution:
- Compute angle for the second joint:
- Compute angle :
Applications:
- Character animation (e.g., Final Fantasy combat).
- Robotics (e.g., industrial arms).
- Game AI (e.g., NPC interactions).
4. Advanced Illumination: Global Illumination vs. Local Models
| Model | Description | Pros | Cons |
|---|---|---|---|
| Phong (Local) | Fast ( per pixel). | No soft shadows/indirect light. | |
| Ray Tracing (Global) | Recursive ray casting for reflections/refractions. | Photorealistic. | Slow (). |
| Photon Mapping | Stores photons for global illumination. | Soft shadows, caustics. | Memory-heavy. |
| Path Tracing | Monte Carlo integration of light paths. | Statistically accurate. | Noisy without many samples. |
| Screen-Space GI | Approximates GI in screen pixels. | Real-time (e.g., Unreal Engine). | Limited to visible surfaces. |
Shadow Detection Challenges
- Hard shadows: Simple ray occlusion (Phong model).
- Soft shadows: Multiple light samples (e.g., percentage-closer filtering).
- Global shadows: Require ray recursion (e.g., shadow rays in ray tracing).
- Complex geometries: Portals or lightmaps for static scenes.
Example: Shadow Mapping
- Render scene from light’s POV to depth buffer.
- For each fragment, compare depth to stored shadow map.
- If , it’s in shadow.
5. Graphics Standards: APIs and File Formats
Standards ensure interoperability across hardware/software.
A. Hardware Standards (APIs)
| Standard | Role | Key Features |
|---|---|---|
| OpenGL | Cross-platform rendering. | Immediate mode, shaders (GLSL). |
| Vulkan | Low-level GPU access. | Explicit control, multi-threading. |
| DirectX | Microsoft ecosystem. | HDR, ray tracing (DXR). |
| WebGL | Browser-based rendering. | JavaScript API, limited to OpenGL ES 2.0. |
B. Software Standards (File Formats)
| Format | Type | Use Case |
|---|---|---|
| SVG | Vector graphics. | Scalable logos, web graphics. |
| VRML/X3D | 3D scenes. | Interactive 3D models (e.g., CAD). |
| OBJ | Mesh data. | 3D modeling (vertices, textures, materials). |
| GLTF | 3D scenes + animations. | Real-time rendering (e.g., Babylon.js). |
Why Standards Matter
- Portability: Code runs on any compliant GPU.
- Abstraction: Hide hardware details (e.g., OpenGL’s
glBegin()/glEnd()). - Optimization: Vendors implement standards efficiently (e.g., NVIDIA’s CUDA for GPU compute).
6. Special Topics in Modern CG
A. Non-Photorealistic Rendering (NPR)
Simulates artistic styles (e.g., cel-shading, watercolor). Techniques:
- Toon shading: Flat colors with outlines (e.g., The Legend of Zelda).
- Stylized lighting: Cel shading uses ramp textures for edges.
- Procedural textures: Hand-painted effects (e.g., Disney’s "The Princess and the Frog").
B. Volumetric Rendering
Models participating media (smoke, fog, clouds) via:
- Ray marching: Step along rays, accumulate color/transparency.
- Sparse voxel octrees: Compress 3D textures.
C. Machine Learning in CG
- Neural radiance fields (NeRF): 3D scenes from 2D images.
- GANs for super-resolution: Upscale low-res textures.
- Style transfer: Apply artistic styles to 3D models.
Exam Tip: How to Score Full Marks
For derivations (e.g., rotation matrix, ray-sphere intersection):
- Show all steps with clear labels (e.g., "Step 1: Expand the quadratic equation").
- Use LaTeX for equations (even if handwritten, write neatly).
- Example: For 2D rotation, start with: Then substitute , .
For comparisons (e.g., raster vs. vector, local vs. global illumination):
- Use tables with Pros/Cons/Applications.
- Highlight key differences in bold (e.g., "Vector graphics are scalable but not resolution-independent for anti-aliasing").
For algorithms (e.g., flood fill, ray tracing):
- Write pseudocode or step-by-step traces.
- Example for flood fill:
ALGORITHM FloodFill(x, y, target_color, replacement_color) 1. IF pixel(x,y) != target_color: RETURN 2. SET pixel(x,y) = replacement_color 3. FloodFill(x+1, y, target_color, replacement_color) 4. FloodFill(x-1, y, target_color, replacement_color) 5. FloodFill(x, y+1, target_color, replacement_color) 6. FloodFill(x, y-1, target_color, replacement_color) - Trace: Show how it fills a 3×3 grid starting at (1,1).
For definitions:
- Be precise. Avoid vague terms like "very detailed."
- ❌ "Ray tracing is very accurate."
- ✅ "Ray tracing models global illumination via recursive ray-object intersection, enabling physically accurate reflections, refractions, and soft shadows."
- Be precise. Avoid vague terms like "very detailed."
For applications:
- Link to real-world examples (e.g., "Photon mapping is used in Unreal Engine 5 for cinematic lighting").
- Mention trade-offs (e.g., "While ray tracing is photorealistic, it’s not suitable for real-time games without hardware acceleration").
Diagrams:
- Sketch flowcharts for pipelines (e.g., 3D viewing pipeline: World → View → Projection → Screen).
- Use Mermaid-style text in exams (e.g.,
flowchart TD: A-->Bfor transformations).
Common Pitfalls:
- Confusing raster/vector: Raster = pixels (e.g., JPEG), vector = math (e.g., SVG).
- Global vs. local illumination: Local (Phong) ignores indirect light; global (path tracing) simulates it.
- Rotation matrices: Remember clockwise vs. counter-clockwise conventions (TU exams often use math convention: positive θ is counter-clockwise).
Quick Revision Table
| Topic | Key Equation/Concept | Example Application |
|---|---|---|
| 2D Rotation | Rotating a sprite in a game. | |
| Ray-Sphere Intersection | Quadratic solution for . | Minecraft block rendering. |
| Phong Shading | Low-poly 3D models. | |
| Mandelbrot Set | , bounded . | Procedural art, fractal zooms. |
| Bézier Curve | Smooth character animations. | |
| Inverse Kinematics | Iterative joint angle solving. | Robot arm control. |
| Global Illumination | Photon mapping/path tracing. | Cycles (Blender) renders. |
Based on the TU BSc CSIT syllabus for Computer Graphics (CSC214), unit 10.
Discussion
Loading…