Skip to content
On this page

Checkerboard

floor() and fmod() are used here to generate a tileable checkerboard pattern by alternating colors based on the parity of tiled UV coordinates. Perfect for stylized grid overlays, procedural scanlines and/or patterned transitions.

half2 uvs = floor(uv * tiling);
half mask_board = fmod(uvs.x + uvs.y, 2.0);

Visual demo

This pattern divides UV space into a grid by flooring scaled UVs, then uses the sum of the cell coordinates modulo 2 to alternate between two colors, creating a classic checkerboard effect.

Shader Story: Patterns - Checkerboard

Node logic (engine-agnostic)

Shader Story: Patterns - Checkerboard


Shader code
Shader "DecompiledArt/Patterns/Checkerboard/Checkerboard"
{
    Properties
    {
        _Tint_01("Tint_01", Color) = (1,1,1,1)
        _Tint_02("Tint_02", Color) = (1,1,1,1)
        _BoardScale("BoardScale", float) = 2.0
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {            
            ...


            half4 frag(Varyings IN) : SV_Target
            {
                half2 uvs = floor(IN.uvs);
                half mask_board = fmod(uvs.x + uvs.y, 2.0);

                half3 col_output = lerp(_Tint_01, _Tint_02, mask_board).xyz;

                return half4(col_output, 1.0);
            }

            ENDHLSL
        }
    }
}

Floor • Fmod


❤️ Support Shader Story

If this article helped you, consider supporting the project on Patreon: you’ll get access to the related source files and reference cheat-sheets.

DecompiledArt on Patreon DecompiledArt on Buy Me a Coffee

Your support helps keep this library open and free for everyone.