# DolphinSurfacePreview

Evaluate a surface function with Dolphin's CPU reference renderer and return encoded BGRA pixels for a small material preview.

Last updated: 2026-09-09

Package: dolphin.materials | Status: source-declared

Tags: cpu, dolphin, dolphin.materials, function, material, materials, preview

Compose linear-color surfaces and shared shading math in ordinary Yeho code.

```yh
external DolphinSurfacePreview(function of Vector3 to dolphinSurface shader,int size) returns text
```


## Render a material preview

Sample a teal material with the compiled Dolphin CPU reference. The output is encoded BGRA pixel data, not a GPU shader export.

Verification: executed

```yh
using dolphin.math
using dolphin.spatial3d
using dolphin.materials

Surface(Vector3 point) -> dolphinSurface
{
    return DolphinSurface(Vector3(0.1, 0.7, 0.6), 0.4, 0.0, 0.0)
}
text pixels = DolphinSurfacePreview(Surface, 16)
Console.Log(Text.From(Text.Length(pixels)))

```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.dolphin_materials__dolphinsurfacepreview"
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"

```

Executed backend: cpu-oracle

Observed output:

```text
2048
```

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/dolphin.materials--DolphinSurfacePreview/complete --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


Package presence and a declaration do not establish support on every host. Host services need their platform and lifecycle setup.

Source: dolphin/packages/materials/src/surface.yh

AI training permission: https://demonhunterlabs.com/ai-use
