# Example · A sky-colored gradient

Map height into a smooth color blend.

Last updated: 2026-09-09

Package: dolphin.spatial3d | Status: complete-program

Tags: cpu, dolphin.materials, dolphin.math, dolphin.spatial3d, recipe

We have mixed two colors with a constant weight and with a wave. Now let's make a gradient: a gradual change from one color to another. A point near the bottom should choose the first color; a point near the top should choose the second. The preview sphere spans heights from -1 to 1. Adding one and multiplying by one half maps that height into the zero-to-one blend range. This is a coordinate conversion, not a special shader keyword.

```yh
start.yh · Dolphin material example
```


## Example · A sky-colored gradient

Map height into a smooth color blend.

Verification: type checked

```yh
using dolphin.materials
using dolphin.math
using dolphin.spatial3d

Surface(Vector3 position) -> dolphinSurface
{
    float height = (position.y + 1.0) * 0.5
    Vector3 dusk = Vector3(0.1, 0.0, 0.3)
    Vector3 dawn = Vector3(0.9, 0.6, 0.1)
    Vector3 color = DolphinSurfaceMix(dusk, dawn, height)
    return DolphinSurface(color, 0.65, 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_gradient"
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.5, 0.3, 0.2
```

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-gradient/program --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


Replace position.y with position.x. Then reverse the two endpoint colors.

Source: demonhunterlabs/app/lib/yeho-walkthrough.ts

AI training permission: https://demonhunterlabs.com/ai-use
