Table of Contents

Class NormalMapGenerator

Namespace
Map.Rendering
Assembly
MapAssembly.dll

Generates normal map from heightmap using GPU compute shader. Based on EU5's approach - calculates gradients on GPU for maximum performance.

Algorithm:

  1. Sample heightmap at each pixel and 4 neighbors (LRUD)
  2. Calculate gradients using central difference
  3. Construct normal vector from gradients
  4. Pack normal into RG8 texture (XZ components, reconstruct Y in fragment shader)

Result: High-quality lighting with depth perception at any zoom level

public class NormalMapGenerator
Inheritance
object
NormalMapGenerator

Constructors

NormalMapGenerator()

public NormalMapGenerator()

Methods

GenerateNormalMap(Texture2D, Texture2D, float, bool)

Generates normal map from heightmap texture using GPU compute shader. CRITICAL: Follows GPU coordination patterns from unity-compute-shader-coordination.md

public void GenerateNormalMap(Texture2D heightmapTexture, Texture2D normalMapTexture, float heightScale = 10, bool logProgress = false)

Parameters

heightmapTexture Texture2D

Input heightmap (R8 or R16 format)

normalMapTexture Texture2D

Output normal map (RG8 format)

heightScale float

Height scale multiplier for normal calculation (default: 10.0)

logProgress bool

Enable performance logging