โ† All examples

godot shaders

Palette swap by colour keys

Recolour sprites at run time: up to three source colours are matched within a tolerance and replaced by target colours, optionally keeping the original shading, for team colours, skins and enemy variants.

Recorded render of Palette swap by colour keys

What this component contains

  • ATTRIBUTION.md
  • LICENSE
  • README.md
  • component.json
  • demo.tscn
  • inspect_shader.py
  • material.tres
  • preview.png
  • sprite_color_key_swap.gdshader
  • test_package.py
  • verification/native.json

How it works

Shader type
canvas_item
Parameters
key_1 (vec4 = 0.95, 0.6, 0.25, 1), target_1 (vec4 = 0.25, 0.8, 0.75, 1), key_2 (vec4 = 0.85, 0.35, 0.3, 1), target_2 (vec4 = 0.2, 0.45, 0.9, 1), key_3 (vec4 = 0.55, 0.2, 0.35, 1), target_3 (vec4 = 0.15, 0.15, 0.45, 1), tolerance (float = 0.16), softness (float = 0.1) and 1 more
Use it on
A Sprite2D (or other textured CanvasItem) with transparent space around its shape, assigned to the node as usual.
Result
The orange, red and purple sprite recoloured to teal, blue and navy.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/sprite_color_key_swap/

Recorded checks

godot 4.7.2.stable.official.ed1daf0bf

  • contract_static
  • engine_run
  • engine_log_clean
  • shader_in_scene
  • capture_written
  • render_not_uniform
  • shader_changes_pixels

Limits to consider

Matching is by RGB distance, so similar colours elsewhere in the sprite can be caught; author sprites with distinct key colours. Three pairs per material.