Table of Contents

Class MapModeColorizerBase

Namespace
Map.MapModes.Colorization
Assembly
MapAssembly.dll

ENGINE: Abstract base class for map mode colorizers. Provides common utilities for GPU compute shader-based colorization.

Subclasses implement:

  • ColorizerId, DisplayName - identification
  • InitializeColorizer() - load compute shader, create buffers
  • DoColorize() - dispatch compute shader
  • DisposeResources() - release GPU resources
public abstract class MapModeColorizerBase : IMapModeColorizer
Inheritance
object
MapModeColorizerBase
Implements
Derived

Fields

THREAD_GROUP_SIZE

protected const int THREAD_GROUP_SIZE = 8

Field Value

int

context

protected MapModeColorizerContext context

Field Value

MapModeColorizerContext

isInitialized

protected bool isInitialized

Field Value

bool

Properties

ColorizerId

Unique identifier for this colorizer (e.g., "Gradient", "DiscreteBands", "MultiColor")

public abstract string ColorizerId { get; }

Property Value

string

DisplayName

Human-readable name for UI/debugging

public abstract string DisplayName { get; }

Property Value

string

RequiresPerFrameUpdate

Whether this colorizer needs per-frame updates (e.g., animated effects)

public virtual bool RequiresPerFrameUpdate { get; }

Property Value

bool

Methods

CalculateThreadGroups(int, int)

Calculate thread groups for compute shader dispatch.

protected (int x, int y) CalculateThreadGroups(int width, int height)

Parameters

width int
height int

Returns

(int x, int y)

ColorToVector4(Color)

Convert Color to Vector4 for shader.

protected Vector4 ColorToVector4(Color color)

Parameters

color Color

Returns

Vector4

Colorize(RenderTexture, RenderTexture, float[], ColorizationStyleParams)

Apply colorization to generate output texture. Core operation: province values + style params → colored texture

public void Colorize(RenderTexture provinceIDTexture, RenderTexture outputTexture, float[] provinceValues, ColorizationStyleParams styleParams)

Parameters

provinceIDTexture RenderTexture

Input: Province ID texture (RG16 encoded)

outputTexture RenderTexture

Output: Colorized RGBA texture

provinceValues float[]

Per-province normalized values (0-1), negative = skip

styleParams ColorizationStyleParams

Colorization style parameters

Dispose()

Release GPU resources.

public void Dispose()

DisposeResources()

Subclass resource cleanup. Release compute buffers, etc.

protected abstract void DisposeResources()

DoColorize(RenderTexture, RenderTexture, float[], ColorizationStyleParams)

Subclass colorization implementation. Dispatch compute shader with appropriate parameters.

protected abstract void DoColorize(RenderTexture provinceIDTexture, RenderTexture outputTexture, float[] provinceValues, ColorizationStyleParams styleParams)

Parameters

provinceIDTexture RenderTexture
outputTexture RenderTexture
provinceValues float[]
styleParams ColorizationStyleParams

EnsureGradientBuffer(ComputeBuffer, int)

Create or resize a compute buffer for gradient colors.

protected ComputeBuffer EnsureGradientBuffer(ComputeBuffer existing, int colorCount)

Parameters

existing ComputeBuffer
colorCount int

Returns

ComputeBuffer

EnsureProvinceValueBuffer(ComputeBuffer, int)

Create or resize a compute buffer for province values.

protected ComputeBuffer EnsureProvinceValueBuffer(ComputeBuffer existing, int minSize)

Parameters

existing ComputeBuffer
minSize int

Returns

ComputeBuffer

Initialize(MapModeColorizerContext)

Initialize the colorizer with required resources. Called once when colorizer is first activated.

public void Initialize(MapModeColorizerContext ctx)

Parameters

ctx MapModeColorizerContext

InitializeColorizer()

Subclass initialization hook. Load compute shaders, create buffers, etc.

protected abstract void InitializeColorizer()

OnRenderFrame()

Called each frame if RequiresPerFrameUpdate is true. Use for animated effects, pulsing, etc.

public virtual void OnRenderFrame()

UploadGradientColors(ComputeBuffer, ColorGradient, int)

Sample gradient at specified points and upload to buffer.

protected void UploadGradientColors(ComputeBuffer buffer, ColorGradient gradient, int sampleCount)

Parameters

buffer ComputeBuffer
gradient ColorGradient
sampleCount int