GAME COLOR CONVERTER

Convert color codes seamlessly between HEX, RGB (0-255), HSL, and normalized Unity C# Color(r,g,b,a) float values (0.0 to 1.0).

COLOR INPUTS

QUICK PALETTES:

CONVERTED OUTPUTS

UNITY C# COLOR (0.0 - 1.0f)
new Color(0.000f, 0.898f, 1.000f, 1.000f)
UNITY C# COLOR32 (0 - 255)
new Color32(0, 229, 255, 255)
HEX STRING
#00E5FF
CSS RGB
rgb(0, 229, 255)
CSS HSL
hsl(186, 100%, 50%)

How Unity Color Conversion Works

In Unity C#, the standard UnityEngine.Color struct stores Red, Green, Blue, and Alpha components as normalized 32-bit floating-point values ranging from 0.0f to 1.0f, rather than standard web integers (0 to 255).

C# Normalized Color Formula
float normalizedRed = 229f / 255f; // Results in ~0.898f
Color customColor = new Color(0.0f, 0.898f, 1.0f, 1.0f);

Alternatively, Unity provides Color32 which uses 8-bit unsigned bytes (byte r, byte g, byte b, byte a) from 0 to 255 for lower memory overhead in mesh vertex colors and sprite shaders.

Color Spaces in Video Games: Linear vs Gamma and Shader Performance

Understanding digital color representation is essential for graphics engineers, technical artists, and UI designers. In Unity, colors are fundamentally represented either in the Gamma Color Space (standard sRGB monitor space) or the Linear Color Space (physically accurate lighting math).

Why Unity Color(r, g, b, a) Uses Normalized Floats

In standard web development and Photoshop, colors are represented by 8-bit integers ranging from 0 to 255 (e.g. rgb(255, 128, 0)). However, modern GPU shaders and Unity's UnityEngine.Color struct operate using 32-bit floating-point numbers normalized between 0.0f and 1.0f.

  • High Dynamic Range (HDR): Normalized floating-point color channels can exceed 1.0f (e.g. new Color(3.5f, 1.2f, 0.5f)). When rendered with bloom post-processing, values above 1.0 create intense, realistic weapon muzzle flashes and laser engine glow.
  • Shader Interpolation: GPUs calculate surface lighting, vertex blending, and specular highlights through vector dot products. Floating-point math prevents ugly color banding artifacts in dark shadows and sunset atmospheres.

Color32 Memory Optimization for Mobile Games

While UnityEngine.Color consumes 16 bytes of memory per instance (4 floats x 4 bytes), UnityEngine.Color32 packs RGBA channels into 4 raw bytes (4 unsigned bytes x 1 byte). When procedurally generating mesh vertex colors for thousands of particles or procedural terrain chunks, switching from Color[] to Color32[] reduces memory bandwidth overhead by exactly 75%!

Unity C# Dynamic Material Color Manipulation

Below is the recommended, garbage-free pattern for smoothly lerping material colors (such as enemy damage flashes) using MaterialPropertyBlocks:

DamageFlashController.cs (Zero-Allocation Color Lerp)
using UnityEngine;

public class DamageFlashController : MonoBehaviour
{
    private Renderer targetRenderer;
    private MaterialPropertyBlock propBlock;
    private static readonly int BaseColorHash = Shader.PropertyToID("_BaseColor");

    [SerializeField] private Color normalColor = Color.white;
    [SerializeField] private Color hitColor = Color.red;

    private void Awake()
    {
        targetRenderer = GetComponent<Renderer>();
        propBlock = new MaterialPropertyBlock();
    }

    public void TriggerDamageFlash()
    {
        // Sets color instantly without instantiating duplicate runtime materials!
        propBlock.SetColor(BaseColorHash, hitColor);
        targetRenderer.SetPropertyBlock(propBlock);
        Invoke(nameof(ResetColor), 0.15f);
    }

    private void ResetColor()
    {
        propBlock.SetColor(BaseColorHash, normalColor);
        targetRenderer.SetPropertyBlock(propBlock);
    }
}