Skip to content

Latest commit

 

History

History
107 lines (71 loc) · 2.95 KB

File metadata and controls

107 lines (71 loc) · 2.95 KB

Diamond Pattern Texture Tiling: Technical Analysis

Introduction

Traditional texture tiling methods produce visible artifacts at texture boundaries. The diamond pattern texture tiling algorithm presents a solution through overlapping rotated texture samples arranged in a diamond pattern, effectively minimizing these artifacts through strategic sampling and blending.

Core Algorithm Components

1. Grid System

The algorithm operates on two overlapping grids:

Primary Grid (Corner-Centered) $G_1 = {(i, j) \mid i,j \in \mathbb{Z}}$

Secondary Grid (Center-Centered) $G_2 = {(i + 0.5, j + 0.5) \mid i,j \in \mathbb{Z}}$

2. Coordinate Transformation

For any point $P(x, y)$, we compute:

Nearest Corner Position: $C(x,y) = \lfloor(x,y) + 0.5\rfloor$

Nearest Center Position: $M(x,y) = \lfloor(x,y) - (0.5,0.5) + 0.5\rfloor + (0.5,0.5)$

3. Rotation System

The rotation transformation matrix $R(\theta)$ for angle $\theta$:

$ R(\theta) = \begin{bmatrix} \cos(\theta) & -\sin(\theta) \ \sin(\theta) & \cos(\theta) \end{bmatrix} $

Applied to point $P$ around center $C$: $P_{rot} = R(\theta)(P - C) + C$

4. Random Rotation Generation

The deterministic random function for position $P(x,y)$:

$random(P) = fract(P_x \cdot 443.897 + P_y \cdot 441.423 + dot(P,P + 19.19))$

Final rotation angle: $\theta = 2\pi \cdot r \cdot random(P)$ where $r$ is the rotation scale factor.

5. Blending Mechanism

Distance calculations:

  • $d_C = |P - C|^2$ (squared distance to nearest corner)
  • $d_M = |P - M|^2$ (squared distance to nearest center)

Blend factor computation: $\beta = clamp((d_M \cdot offset - d_C) \cdot falloff, 0, 1)$

where:

  • $offset$ controls the relative influence of center points
  • $falloff$ controls the transition sharpness

Implementation Details

Coordinate Processing

  • Input UV coordinates are normalized to the texture space
  • Grid positions are computed using floor and fractional operations
  • Distances are calculated using dot products for efficiency

Sampling Process

  • Calculate rotated coordinates for both grid positions
  • Sample texture at both rotated positions
  • Blend samples using computed blend factor: $color_{final} = lerp(color_1, color_2, \beta)$

Performance Considerations

Computational Efficiency

The algorithm primarily uses:

  • Basic vector operations
  • Trigonometric functions (sin, cos)
  • Two texture samples per fragment
  • Simple distance calculations via dot products

Limitations

  • Corner Artifacts

    • Four-way intersections of diamond patterns can show subtle discontinuities
    • Severity depends on texture content and parameter selection
  • Computational Cost

    • Two texture samples per fragment versus one in simple tiling
    • Additional trigonometric operations for rotation

Practical Applications

The algorithm is particularly effective for:

  • Large-scale terrain texturing
  • Procedural texture generation
  • Architectural visualization
  • Dynamic texture mapping