Initial font work
This commit is contained in:
@@ -73,6 +73,7 @@ Optional fields:
|
||||
- `category`: UI grouping label.
|
||||
- `entryPoint`: Slang function to call. Defaults to `shadeVideo`.
|
||||
- `textures`: texture assets to load and expose as samplers.
|
||||
- `fonts`: packaged font assets for live text parameters.
|
||||
- `temporal`: history-buffer requirements.
|
||||
|
||||
Shader-visible identifiers must be valid Slang-style identifiers:
|
||||
@@ -80,6 +81,7 @@ Shader-visible identifiers must be valid Slang-style identifiers:
|
||||
- `entryPoint`
|
||||
- parameter `id`
|
||||
- texture `id`
|
||||
- font `id`
|
||||
|
||||
Use letters, numbers, and underscores only, and start with a letter or underscore. For example, `logoTexture` is valid; `logo-texture` is not valid as a shader-visible texture ID.
|
||||
|
||||
@@ -180,6 +182,7 @@ Supported types:
|
||||
| `color` | `float4` | `[r, g, b, a]` |
|
||||
| `bool` | `bool` | `true` or `false` |
|
||||
| `enum` | `int` | selected option index |
|
||||
| `text` | generated texture/helper | string |
|
||||
|
||||
Float example:
|
||||
|
||||
@@ -278,12 +281,42 @@ else if (mode == 2)
|
||||
}
|
||||
```
|
||||
|
||||
Text example:
|
||||
|
||||
```json
|
||||
{
|
||||
"fonts": [
|
||||
{ "id": "inter", "path": "fonts/Inter-Regular.ttf" }
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"id": "titleText",
|
||||
"label": "Title",
|
||||
"type": "text",
|
||||
"default": "LIVE",
|
||||
"font": "inter",
|
||||
"maxLength": 64
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Text parameters are runtime-owned strings. They are not emitted as uniform values. Instead, the runtime renders the current string into a single-line SDF mask texture and the shader wrapper exposes helpers based on the parameter id:
|
||||
|
||||
```slang
|
||||
float mask = sampleTitleText(textUv);
|
||||
float4 premultipliedText = drawTitleText(textUv, float4(1.0, 1.0, 1.0, 1.0));
|
||||
```
|
||||
|
||||
Text is currently limited to printable ASCII. `maxLength` defaults to `64` and is clamped to `1..256`. The optional `font` field references a packaged font declared in `fonts`; if no font is specified, the runtime uses its fallback sans-serif renderer.
|
||||
|
||||
Parameter validation:
|
||||
|
||||
- Float values are clamped to `min`/`max` if provided.
|
||||
- `vec2` must have exactly 2 numbers.
|
||||
- `color` must have exactly 4 numbers.
|
||||
- Enum defaults must match one of the declared option values.
|
||||
- Text defaults must be strings. Non-printable characters are dropped and values are clamped to `maxLength`.
|
||||
- Non-finite numeric values are rejected.
|
||||
|
||||
## Texture Assets
|
||||
@@ -323,6 +356,31 @@ return float4(logo.rgb * alpha, alpha);
|
||||
|
||||
See `shaders/dvd-bounce/` for a complete texture-driven example.
|
||||
|
||||
## Font Assets
|
||||
|
||||
Declare packaged font assets in the manifest:
|
||||
|
||||
```json
|
||||
{
|
||||
"fonts": [
|
||||
{
|
||||
"id": "inter",
|
||||
"path": "fonts/Inter-Regular.ttf"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Rules:
|
||||
|
||||
- `id` must be a valid shader identifier.
|
||||
- `path` is relative to the shader package directory.
|
||||
- The file must exist when the manifest is loaded.
|
||||
- Font asset changes trigger shader reload.
|
||||
- V1 text layout is single-line; shaders position and scale the generated text texture themselves.
|
||||
|
||||
See `shaders/text-overlay/` for a complete live text example. The sample bundles Roboto Regular and includes its OFL license beside the font file.
|
||||
|
||||
## Temporal Shaders
|
||||
|
||||
Temporal shaders can request access to previous frames.
|
||||
@@ -401,6 +459,7 @@ These files are ignored by git and are useful for debugging compiler output. If
|
||||
- Do not write a `[shader("fragment")]` entry point in `shader.slang`; the runtime provides it.
|
||||
- Remember enum globals are integer indexes, not strings.
|
||||
- Declare every texture in `shader.json`; undeclared texture samplers will not be bound.
|
||||
- Declare packaged fonts in `shader.json` when text parameters should use a specific font.
|
||||
- Keep temporal history requests modest. They consume texture units and memory and are capped by runtime config.
|
||||
- If a parameter appears in the UI but not in Slang, the shader may still compile, but the control has no effect.
|
||||
- If a Slang name collides with a generated global, rename your parameter or local symbol.
|
||||
@@ -414,6 +473,7 @@ Before committing a new shader package:
|
||||
- `entryPoint`, parameter IDs, and texture IDs are valid identifiers.
|
||||
- `shader.slang` implements the configured entry point.
|
||||
- Texture files referenced by `textures` exist.
|
||||
- Font files referenced by `fonts` exist.
|
||||
- Enum defaults are present in their `options`.
|
||||
- Temporal shaders handle short or empty history gracefully.
|
||||
- The app can reload and compile the shader without errors.
|
||||
|
||||
Reference in New Issue
Block a user