Computer Graphics: 3D Matrix Rotation, Perlin Noise, Worley Noise

3D Matrix Rotation

3D vertex matrices represent points (x,y,z)(x, y, z) as column vectors, often expanded to 4×14 \cross 1 vectors (x,y,z,1)(x,y,z,1) using homogeneous coordinates, allowing translation, rotation, and scaling within a single 4×44 \cross 4 transformation matrix. Linear rotation transforms these vertices by multiplying them with rotation matrices (Rx,Ry,Rz)(R_x, R_y, R_z) which map old basis vectors to new orientations around axes.

The general form of a 4×44 \cross 4 homogeneous rotation matrix is:

[R11R12R130R21R22R230R31R32R3300001]\begin{bmatrix} R_{11} & R_{12} & R_{13} & 0 \\ R_{21} & R_{22} & R_{23} & 0 \\ R_{31} & R_{32} & R_{33} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

  • Top-Left 3×3 (R)3 \cross 3\ (R): This submatrix contains the pure rotation components (e.g., rotation around X, Y, or Z axes)
  • Right 3×13 \cross 1 Column: Zeros, indicating no translation is occurring.
  • Bottom Row: [0, 0, 0, 1][0,\ 0,\ 0,\ 1] to maintain the homogeneous coordinate system.

Individual Axis Rotations

Rx(θ)=[10000cos(θ)sin(θ)00sin(θ)cos(θ)00001]R_x(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos(\theta) & -\sin(\theta) & 0 \\ 0 & \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Ry(β)=[cos(β)0sin(β)00100sin(β)0cos(β)00001]R_y(\beta) = \begin{bmatrix} \cos(\beta) & 0 & \sin(\beta) & 0 \\ 0 & 1 & 0 & 0 \\ -\sin(\beta) & 0 & \cos(\beta) & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Rz(γ)=[cos(γ)sin(γ)00sin(γ)cos(γ)0000100001]R_z(\gamma) = \begin{bmatrix} \cos(\gamma) & -\sin(\gamma) & 0 & 0 \\ \sin(\gamma) & \cos(\gamma) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Homogeneous Coordinates

Homogeneous coordinates, or projective coordinates, are a system used in projective geometry and computer graphics to represent nn-dimensional points with n+1n + 1 coordinates, allowing translation, rotation, and scaling to be performed via single matrix multiplications. They add a ww-dimension (x,y,z,w)(x,y,z,w) where w=1w=1 for standard points and w=0w=0 for points at infinity.

  • Definition: A Cartesian point (x,y)(x,y) becomes (x,y,1)(x,y,1) in 2D homogeneous coordinates. Similarly, a 3D point (x,y,z)(x,y,z) becomes (x,y,z,1)(x,y,z,1).
  • Scaling Property: The same point can have multiple representations; (x,y,w)(x,y,w) is the same as (kx,ky,kw)(kx,ky,kw) for any non-zero scalar kk.
  • Conversion: To convert back to Cartesian, divide x,y,zx,y,z by ww.
  • Applications: They are essential in computer graphics for handling perspective projection, rendering, and affine transformations (like translation).
  • Points at Infinity: When w=0w=0, the coordinate represents a point at infinity (a direction), which is crucial for 3D modeling and rendering.

Why Use Homogeneous Coordinates?

  • Unified Transformations: They allow rotation, translation, and scaling to be combined into a single 4×44 \cross 4 matrix through multiplication.
  • Efficiency: They enable 3D translation via matrix multiplication rather than addition.
  • Perspective Projection: Necessary for mapping 3D scenes onto 2D screens.
  • Points at Infinity: They can represent points at infinity, which is useful in computer vision.

This video provides a visual explanation of how 3D rotation matrices work:

3D Vertex Matrices

  • Definition: Vertices are typically represented as homogenous column vectors to facilitate affine transformations. Here is a 4×14 \cross 1 homogeneous column vector containing coordinates in 3D space (x,y,z)(x,y,z):

    [xyz1]\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}
  • Transformation Matrix (M)(M): a 4×44 \cross 4  matrix is used to combine scaling, rotation, and translation, allowing complex transformations to be applied by multiplying the matrix MM by each vertex vector v: (v=Mv)v:\ (v\prime = M \cdot v)
  • Order of Operations: Transformations are not commutative; the standard order is scaling, then rotation, then translation.

Perlin Noise

Perlin noise is a type of gradient, coherent noise developed by Ken Perlin in the 1980s that generates smooth, natural-looking, pseudo-random patterns. It is widely used in computer graphics and game development for creating procedural textures, terrain heightmaps, clouds, and animations. Unlike white noise, Perlin noise generates connected values that flow, making it ideal for simulating organic, irregular, and natural, phenomena.

Key Aspects of Perlin Noise

  • How it Works: It generates random gradient vectors at lattice points in an nn-dimensional grid and interpolates between them to create a smooth, continuous field of values.
  • Properties: It produces smooth transitions, avoiding the abrupt, jagged changes of pure randomness. The output usually ranges between 0.0 and 1.0 (or -1 to 1, depending on implementation).
  • Octaves & Layers: Multiple layers (octaves) of noise with varying frequencies and amplitudes can be stacked to create detailed textures, such as combining low-frequency, large-scale features with high-frequency, small-scale details.
  • Applications:
    • Terrain Generation: Creating realistic landscapes, mountains, and maps (e.g., in Minecraft).
    • Texturing: Generating natural, patterns like marble, clouds, fire, and water.
    • Animation: Creating smooth, random, motion.
  • Advantages: It is deterministic (the same input coordinates always yield the same noise value) and provides an organic, “hand-drawn” look rather than a digital, “static” look.
  • Limitations: The original algorithm has directional artifacts and, can be computationally expensive compared to simple random, generators, though it is still efficient enough for real-time applications.

Variations & Improvements

  • Simplex Noise: A faster, higher-dimensional alternative to Perlin noise with fewer computational artifacts.
  • Improved Perlin Noise: An updated algorithm with better interpolation and smoother gradients.
  • Billow/Rigid Noise: Variations used to create specific shapes like jagged mountains.

Worley Noise

Worley noise, or cellular noise, is procedural texture technique developed by Steven Worley in 1996 that generates organic, cell-like patterns by calculating the distance from any point to the nearest randomly placed “feature points”. It is widely used in computer graphics to simulate textures like stone, water, or cells. Worley noise is an extension of the Voronoi diagram that outputs a real value at a given coordinate. The Book of Shaders provides a terrific article on implementing Worley noise complete with diagrams, code, and animations.

The following video illustrates the implementation of Worley noise:

Key Aspects of Worley Noise

  • Generation Method: The algorithm scatters random points (seeds) across a space and calculates the distance from a pixel to these points. The closest distance determines the pixel’s value (usually brightness).
  • Appearance: It produces distinctive, rounded cellular or mosaic patterns.
  • Applications: It is primarily used for procedural generation, creating textures for 3D modeling, and generating natural-looking patterns such as Voronoi diagrams, stone walls, or water caustics.
  • Distance Metrics: While Euclidean distance is common, other metrics like Manhattan distance can be used to create different patterns.
  • Variations: It can be combined with other noise functions (like Perlin noise) to create complex, organic textures.

Leave a Reply

Discover more from The words of afeique

Subscribe now to keep reading and get access to the full archive.

Continue reading