# Example · A checker material

Turn a continuous position into alternating cells.

Last updated: 2026-09-09

Package: dolphin.spatial3d | Status: complete-program

Tags: cpu, dolphin.materials, dolphin.math, dolphin.spatial3d, recipe

A checkerboard asks which cell a point belongs to. Multiply a coordinate to choose cell density, round down to get the cell number, and alternate between two colors using whether the sum of two cell numbers is even or odd. Here we use X and Y, so the pattern is planar. On a sphere it stretches toward the edges of that projection. This is a deliberate first mapping, not an automatic solution for every mesh's texture coordinates.

```yh
start.yh · Dolphin material example
```


## Example · A checker material

Turn a continuous position into alternating cells.

Verification: type checked

```yh
using dolphin.materials
using dolphin.math
using dolphin.spatial3d

Surface(Vector3 position) -> dolphinSurface
{
    int cellX = Math.FloorToInt(position.x * 4.0)
    int cellY = Math.FloorToInt(position.y * 4.0)
    Vector3 color = Vector3(0.04, 0.06, 0.1)
    if (cellX + cellY) / 2 * 2 == cellX + cellY
    {
        color = Vector3(0.1, 0.9, 0.7)
    }
    return DolphinSurface(color, 0.7, 0.0, 0.0)
}

dolphinSurface center = Surface(Vector3(0.0, 0.0, 0.0))
Console.Log(Text.Format("{0}, {1}, {2}", center.color.x, center.color.y, center.color.z))
```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.recipe__shader_checker"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

[[dependencies]]
package = "dolphin.materials"
version = "0.1.0"
path = "../../../dolphin/packages/materials"

[[dependencies]]
package = "dolphin.math"
version = "0.1.0"
path = "../../../dolphin/packages/math"

[[dependencies]]
package = "dolphin.spatial3d"
version = "0.1.0"
path = "../../../dolphin/packages/spatial3d"

```

Expected output:

```text
0.1, 0.9, 0.7
```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/recipe--shader-checker/program --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


Change both density multipliers from 4.0 to 2.0. Then try using X and Z instead of X and Y.

Source: demonhunterlabs/app/lib/yeho-walkthrough.ts

AI training permission: https://demonhunterlabs.com/ai-use
