07 · Stable content and materials
Distinguish stone and sand using stable content IDs and read tint, response and tags through the public material ABI. Prerequisites: chapter 06, flat uint varyings and SSBOs. Retain a neutral fallback and distinguish geometry identifiers from stable content identity.
Changes and complete download
Add materials.abiVersion=1 and a persistent materialTable buffer. Only the opaque Terrain command gains a readOnly storageBuffer at binding 4, with the table also declared in inputs. The fragment shader includes the host’s virtual /dawnlight/materials-v1.glsl; no helper file is copied.
Previous chapter download · This complete ZIP, source inventory and receipt
Resource flow
The course:stones group selects survivalcraft:GraniteBlock and BasaltBlock; another mapping selects SandBlock. Both use priority=10 and onMissing=skip. course:neutral must have shaderId 0, while stone=1 and sand=2. White tint and response=0 preserve unmatched blocks. Logical ID, effective ID/owner, RenderIdentifier, material record index and shaderId are separate domains. Never infer a species or BlockIndex from an arbitrary number.
The vertex stage carries identifiers as flat out highp uint into flat in highp uint. Explicit highp is required even when default integer precision is high. LookupMaterial returns a record; AmberTint/AmberResponse read declared properties, MaterialHasTag tests mineral, and MaterialShaderId selects the author’s branch. response controls color mixing, rather than claiming PBR roughness.
The final world layout determines byteSize; never hardcode it. A 16 B header precedes lookup and records. Each record has 16 B of identity/tag data plus 16 B per property, so these two properties give 48 B per record. Total size remains world-dependent. Without the same world’s WorldFinal snapshot, materials explain must keep mappingStatus=deferred. Valid definitions/layout do not establish world mapping or actual GPU reads.
Active branch matrix
Source and freshly extracted ZIP agree for every row. Counts include only active nodes; resources include the material buffer where present.
| Variant | Overrides | Resources | Commands |
|---|---|---|---|
default | {} | 4 | 6 |
grade-off | {"course:grade":false} | 3 | 5 |
strength-max | {"course:strength":1,"course:gain":1.2} | 4 | 6 |
Exact active closure
default
resource:course:materials, resource:course:post/color, resource:course:scene/color, resource:course:scene/depth
command:course:grade:0, command:course:present-grade:0, command:course:terrain_alpha_tested:0, command:course:terrain_opaque:0, command:course:terrain_sorted_translucent:0, command:course:terrain_transparent:0
program:course:post/grade, program:course:post/present, program:course:scene/terrain, program:dawnlight:scene_fallback/terrain_alpha_tested, program:dawnlight:scene_fallback/terrain_sorted_translucent, program:dawnlight:scene_fallback/terrain_transparent
Active services: 0
grade-off
resource:course:materials, resource:course:scene/color, resource:course:scene/depth
command:course:present-raw:0, command:course:terrain_alpha_tested:0, command:course:terrain_opaque:0, command:course:terrain_sorted_translucent:0, command:course:terrain_transparent:0
program:course:post/present, program:course:scene/terrain, program:dawnlight:scene_fallback/terrain_alpha_tested, program:dawnlight:scene_fallback/terrain_sorted_translucent, program:dawnlight:scene_fallback/terrain_transparent
Active services: 0
strength-max
resource:course:materials, resource:course:post/color, resource:course:scene/color, resource:course:scene/depth
command:course:grade:0, command:course:present-grade:0, command:course:terrain_alpha_tested:0, command:course:terrain_opaque:0, command:course:terrain_sorted_translucent:0, command:course:terrain_transparent:0
program:course:post/grade, program:course:post/present, program:course:scene/terrain, program:dawnlight:scene_fallback/terrain_alpha_tested, program:dawnlight:scene_fallback/terrain_sorted_translucent, program:dawnlight:scene_fallback/terrain_transparent
Active services: 0
Complete shader sources
shaders/fullscreen.vsh
#version 320 es
precision highp float;
out vec2 v_uv;
void main() {
const vec2 corners[4] = vec2[4](vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0), vec2(1.0, 1.0));
vec2 position = corners[gl_VertexID & 3];
v_uv = position * 0.5 + 0.5;
gl_Position = vec4(position, 0.0, 1.0);
}shaders/grade.psh
#version 320 es
precision highp float;
uniform sampler2D u_sceneColor;
uniform float u_gain;
uniform float u_day;
uniform float u_rain;
in vec2 v_uv;
layout(location = 0) out vec4 o_color;
void main() {
vec3 source = texture(u_sceneColor, v_uv).rgb;
vec3 amber = (source - 0.5) * 1.06 + 0.5;
amber *= vec3(1.06, 1.0, 0.93);
float daylight = 0.5 + 0.5 * sin(6.2831853 * (u_day - 0.25));
amber *= mix(vec3(0.91, 0.96, 1.04), vec3(1.03, 1.01, 0.97), daylight);
amber = mix(amber, amber * vec3(0.91, 0.95, 1.0), u_rain * 0.45) * u_gain;
o_color = vec4(clamp(mix(source, amber, float(GRADE_STRENGTH)), 0.0, 1.0), 1.0);
}shaders/present.psh
#version 320 es
precision highp float;
uniform sampler2D u_postColor;
in vec2 v_uv;
layout(location = 0) out vec4 o_color;
void main() {
o_color = texture(u_postColor, v_uv);
}shaders/terrain.psh
#version 320 es
// <Sampler Name='u_samplerState' Texture='u_texture' />
precision highp float;
precision highp int;
#include "/dawnlight/materials-v1.glsl"
uniform sampler2D u_texture;
in vec2 v_texcoord;
in vec4 v_color;
flat in highp uint v_identifier;
layout(location = 0) out vec4 o_sceneColor;
void main() {
vec4 albedo = texture(u_texture, v_texcoord) * v_color;
highp uint record = LookupMaterial(v_identifier);
vec3 tint = AmberTint(record).rgb;
float response = AmberResponse(record);
if (MaterialHasTag(record, AMBER_MINERAL) && MaterialShaderId(record) == 1u)
response *= 0.75;
o_sceneColor = vec4(albedo.rgb * mix(vec3(1.0), tint, response), albedo.a);
}shaders/terrain.vsh
#version 320 es
// <Semantic Name='TEXCOORD' Attribute='a_texcoord' />
// <Semantic Name='POSITION' Attribute='a_position' />
// <Semantic Name='COLOR' Attribute='a_color' />
// <Semantic Name='IDENTIFIER' Attribute='a_identifier' />
// <Semantic Name='NORMAL' Attribute='a_normal' />
// <Semantic Name='LIGHTLEVEL' Attribute='a_lightLevel' />
// <Semantic Name='PURELIGHT' Attribute='a_pureLight' />
// <Semantic Name='HEIGHTDATA' Attribute='a_heightData' />
uniform mat4 u_viewProjectionMatrix;
uniform vec2 u_origin;
uniform float u_lightTable[96];
layout(location = 0) in vec2 a_texcoord;
layout(location = 1) in vec3 a_position;
layout(location = 2) in vec4 a_color;
layout(location = 3) in uint a_identifier;
layout(location = 4) in vec3 a_normal;
layout(location = 5) in float a_lightLevel;
layout(location = 6) in float a_pureLight;
layout(location = 7) in float a_heightData;
out vec2 v_texcoord;
out vec4 v_color;
out vec3 v_normalEncoded;
flat out highp uint v_identifier;
void main() {
int lightIndex = clamp(int(a_lightLevel) - 1, 0, 95);
float light = clamp(u_lightTable[lightIndex], 0.0, 1.0);
v_texcoord = a_texcoord;
v_color = vec4(a_color.rgb * light, a_color.a);
v_normalEncoded = clamp(a_normal / 255.0, 0.0, 1.0);
v_identifier = a_identifier;
vec3 relativePosition = vec3(a_position.x - u_origin.x, a_position.y, a_position.z - u_origin.y);
gl_Position = u_viewProjectionMatrix * vec4(relativePosition, 1.0);
OPENGL_POSITION_FIX;
}Complete Manifest and settings
settings.json
{
"schemaVersion": 1,
"defaultLocale": "en-US",
"translations": {
"zh-CN": {
"page.amber": "琥珀课程",
"course:grade": "调色",
"course:strength": "调色强度(重新编译)",
"course:gain": "曝光增益"
},
"en-US": {
"page.amber": "Amber course",
"course:grade": "Color grade",
"course:strength": "Grade strength (recompile)",
"course:gain": "Exposure gain"
}
},
"pages": [
{
"id": "amber",
"title": "page.amber",
"groups": [
{
"id": "look",
"controls": [
{
"id": "grade",
"option": "course:grade",
"widget": "toggle",
"label": "course:grade"
},
{
"id": "strength",
"option": "course:strength",
"widget": "slider",
"label": "course:strength",
"min": 0,
"max": 1,
"step": 0.05,
"format": "0.00",
"enabledWhen": [
{
"option": "course:grade",
"equals": true
}
]
},
{
"id": "gain",
"option": "course:gain",
"widget": "slider",
"label": "course:gain",
"min": 0.5,
"max": 1.5,
"step": 0.05,
"format": "0.00",
"enabledWhen": [
{
"option": "course:grade",
"equals": true
}
]
}
]
}
]
}
]
}shaderpack.json
{
"manifestVersion": 5,
"sceneAbiVersion": 2,
"expectedCatalogSha256": "4bc28c17beffea2311a422fff9f633d2e4f03784460d0254adda8af2e766d84c",
"id": "course:07-materials",
"name": "Dawnlight Course · Amber 07-materials",
"version": "1.0.0",
"author": "EltanceX",
"description": "Website-authored Amber course snapshot; see README for tested scope.",
"shaderRoot": "shaders",
"options": [
{
"id": "course:grade",
"type": "boolean",
"default": true,
"impact": [
"pipeline",
"resources"
]
},
{
"id": "course:strength",
"type": "number",
"default": 0.65,
"min": 0,
"max": 1,
"impact": [
"program"
]
},
{
"id": "course:gain",
"type": "number",
"default": 1,
"min": 0.5,
"max": 1.5,
"impact": [
"uniform"
]
}
],
"resources": [
{
"id": "course:scene/color",
"kind": "texture2D",
"lifetime": "persistent",
"size": {
"mode": "viewport"
},
"format": "rgba8"
},
{
"id": "course:scene/depth",
"kind": "texture2D",
"lifetime": "persistent",
"size": {
"mode": "viewport"
},
"format": "depth24"
},
{
"id": "course:post/color",
"kind": "texture2D",
"lifetime": "persistent",
"size": {
"mode": "viewport"
},
"format": "rgba8"
},
{
"id": "course:materials",
"kind": "buffer",
"lifetime": "persistent",
"usage": "staticDraw",
"content": {
"type": "materialTable",
"version": 1
}
}
],
"programs": [
{
"id": "course:scene/terrain",
"kind": "graphics",
"vertex": "terrain.vsh",
"fragment": "terrain.psh",
"compileMode": "officialCompatible"
},
{
"id": "course:post/grade",
"kind": "graphics",
"vertex": "fullscreen.vsh",
"fragment": "grade.psh",
"compileMode": "manifestDriven",
"defines": {
"GRADE_STRENGTH": {
"option": "course:strength"
}
}
},
{
"id": "course:post/present",
"kind": "graphics",
"vertex": "fullscreen.vsh",
"fragment": "present.psh",
"compileMode": "manifestDriven"
}
],
"frameTarget": {
"targets": {
"colors": [
{
"location": 0,
"resource": "course:scene/color",
"loadOp": "clear",
"storeOp": "store",
"clearValue": [
0,
0,
0,
1
]
}
],
"depth": {
"resource": "course:scene/depth",
"loadOp": "clear",
"storeOp": "store",
"clearValue": 1
}
}
},
"passes": [
{
"id": "course:terrain_opaque",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "world",
"phase": "opaque"
},
"services": [],
"programs": [
"course:scene/terrain"
],
"commands": [
{
"type": "engineDraw",
"sceneProvider": {
"id": "dawnlight:scene_draw/terrain_opaque",
"version": 2
},
"targets": {
"colors": [
{
"location": 0,
"resource": "course:scene/color",
"loadOp": "load",
"storeOp": "store"
}
],
"depth": {
"resource": "course:scene/depth",
"loadOp": "clear",
"storeOp": "store",
"clearValue": 1
}
},
"state": {
"blend": "opaque",
"depth": "default",
"rasterizer": "cullCounterClockwiseScissor"
},
"viewport": {
"source": "target",
"restore": "frame",
"synchronizeScissor": true
},
"program": "course:scene/terrain",
"sceneBindings": [
{
"symbol": "u_viewProjectionMatrix",
"contract": "dawnlight:scene_binding/view_projection",
"version": 1,
"frequency": "view"
},
{
"symbol": "u_origin",
"contract": "dawnlight:scene_binding/terrain_origin",
"version": 1,
"frequency": "view"
},
{
"symbol": "u_lightTable",
"contract": "dawnlight:scene_binding/light_table",
"version": 1,
"frequency": "batch"
},
{
"symbol": "u_texture",
"contract": "dawnlight:scene_binding/block_texture",
"version": 1,
"frequency": "draw",
"binding": 0
}
],
"bindings": [
{
"kind": "storageBuffer",
"symbol": "MaterialTable",
"binding": 4,
"resource": "course:materials",
"access": "readOnly"
}
]
}
],
"inputs": [
"course:scene/color",
"course:scene/depth",
"course:materials"
],
"outputs": [
"course:scene/color",
"course:scene/depth"
]
},
{
"id": "course:terrain_alpha_tested",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "world",
"phase": "opaque",
"ordering": {
"after": [
"course:terrain_opaque"
]
}
},
"services": [],
"programs": [],
"commands": [
{
"type": "engineDraw",
"sceneProvider": {
"id": "dawnlight:scene_draw/terrain_alpha_tested",
"version": 2
},
"targets": {
"colors": [
{
"location": 0,
"resource": "course:scene/color",
"loadOp": "load",
"storeOp": "store"
}
],
"depth": {
"resource": "course:scene/depth",
"loadOp": "load",
"storeOp": "store"
}
},
"state": {
"blend": "opaque",
"depth": "default",
"rasterizer": "cullCounterClockwiseScissor"
},
"viewport": {
"source": "target",
"restore": "frame",
"synchronizeScissor": true
}
}
],
"inputs": [
"course:scene/color",
"course:scene/depth"
],
"outputs": [
"course:scene/color",
"course:scene/depth"
]
},
{
"id": "course:terrain_transparent",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "world",
"phase": "transparent"
},
"services": [],
"programs": [],
"commands": [
{
"type": "engineDraw",
"sceneProvider": {
"id": "dawnlight:scene_draw/terrain_transparent",
"version": 2
},
"targets": {
"colors": [
{
"location": 0,
"resource": "course:scene/color",
"loadOp": "load",
"storeOp": "store"
}
],
"depth": {
"resource": "course:scene/depth",
"loadOp": "load",
"storeOp": "store"
}
},
"state": {
"blend": "alphaBlend",
"depth": "default",
"rasterizer": "cullCounterClockwiseScissor"
},
"viewport": {
"source": "target",
"restore": "frame",
"synchronizeScissor": true
}
}
],
"inputs": [
"course:scene/color",
"course:scene/depth"
],
"outputs": [
"course:scene/color",
"course:scene/depth"
]
},
{
"id": "course:terrain_sorted_translucent",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "world",
"phase": "transparent",
"ordering": {
"after": [
"course:terrain_transparent"
]
}
},
"services": [],
"programs": [],
"commands": [
{
"type": "engineDraw",
"sceneProvider": {
"id": "dawnlight:scene_draw/terrain_sorted_translucent",
"version": 2
},
"targets": {
"colors": [
{
"location": 0,
"resource": "course:scene/color",
"loadOp": "load",
"storeOp": "store"
}
],
"depth": {
"resource": "course:scene/depth",
"loadOp": "load",
"storeOp": "store"
}
},
"state": {
"blend": "alphaBlend",
"depth": "default",
"rasterizer": "cullCounterClockwiseScissor"
},
"viewport": {
"source": "target",
"restore": "frame",
"synchronizeScissor": true
}
}
],
"inputs": [
"course:scene/color",
"course:scene/depth"
],
"outputs": [
"course:scene/color",
"course:scene/depth"
]
},
{
"id": "course:grade",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "afterDraw",
"phase": "afterDraw"
},
"services": [],
"programs": [
"course:post/grade"
],
"commands": [
{
"type": "fullscreen",
"program": "course:post/grade",
"bindings": [
{
"kind": "sampler2D",
"symbol": "u_sceneColor",
"binding": 0,
"resource": "course:scene/color"
}
],
"state": {
"blend": "opaque",
"depth": "disabled",
"rasterizer": "cullNoneScissor"
},
"viewport": {
"source": "target",
"restore": "frame",
"synchronizeScissor": true
},
"targets": {
"colors": [
{
"location": 0,
"resource": "course:post/color",
"loadOp": "dontCare",
"storeOp": "store"
}
]
},
"customBindings": [
{
"symbol": "u_gain",
"variable": "course:gain"
},
{
"symbol": "u_day",
"variable": "course:day"
},
{
"symbol": "u_rain",
"variable": "course:rain"
}
]
}
],
"inputs": [
"course:scene/color"
],
"outputs": [
"course:post/color"
],
"enabledWhen": [
{
"option": "course:grade",
"equals": true
}
]
},
{
"id": "course:present-grade",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "afterDraw",
"phase": "screenOutput",
"ordering": {
"after": [
"course:grade"
]
}
},
"services": [],
"programs": [
"course:post/present"
],
"commands": [
{
"type": "present",
"program": "course:post/present",
"bindings": [
{
"kind": "sampler2D",
"symbol": "u_postColor",
"binding": 0,
"resource": "course:post/color"
}
],
"state": {
"blend": "opaque",
"depth": "disabled",
"rasterizer": "cullNoneScissor"
},
"viewport": {
"source": "frame",
"restore": "none",
"synchronizeScissor": true
}
}
],
"inputs": [
"course:post/color"
],
"outputs": [],
"enabledWhen": [
{
"option": "course:grade",
"equals": true
}
]
},
{
"id": "course:present-raw",
"enabled": true,
"stage": {
"template": "dawnlight:command_list",
"version": 1,
"target": "afterDraw",
"phase": "screenOutput"
},
"services": [],
"programs": [
"course:post/present"
],
"commands": [
{
"type": "present",
"program": "course:post/present",
"bindings": [
{
"kind": "sampler2D",
"symbol": "u_postColor",
"binding": 0,
"resource": "course:scene/color"
}
],
"state": {
"blend": "opaque",
"depth": "disabled",
"rasterizer": "cullNoneScissor"
},
"viewport": {
"source": "frame",
"restore": "none",
"synchronizeScissor": true
}
}
],
"inputs": [
"course:scene/color"
],
"outputs": [],
"enabledWhen": [
{
"option": "course:grade",
"equals": false
}
]
}
],
"sceneCategories": [
{
"id": "dawnlight:scene/terrain_opaque",
"version": 1,
"mode": "override",
"stage": "course:terrain_opaque"
},
{
"id": "dawnlight:scene/terrain_alpha_tested",
"version": 1,
"mode": "builtin"
},
{
"id": "dawnlight:scene/terrain_transparent",
"version": 1,
"mode": "builtin"
},
{
"id": "dawnlight:scene/terrain_sorted_translucent",
"version": 1,
"mode": "builtin"
}
],
"settings": "settings.json",
"customData": {
"abiVersion": 1,
"variables": [
{
"id": "course:gain",
"type": "float",
"frequency": "generation",
"default": 1,
"onError": "useDefault",
"expression": {
"option": "course:gain",
"as": "float"
}
},
{
"id": "course:day",
"type": "float",
"frequency": "frame",
"unit": "day_fraction",
"default": 0.5,
"onError": "useDefault",
"expression": {
"input": "dawnlight:data/day_time",
"version": 1
}
},
{
"id": "course:rain",
"type": "float",
"frequency": "frame",
"unit": "dimensionless",
"default": 0,
"onError": "useDefault",
"expression": {
"call": "clamp",
"args": [
{
"input": "dawnlight:data/weather_precipitation",
"version": 1
},
{
"literal": 0,
"type": "float"
},
{
"literal": 1,
"type": "float"
}
]
}
}
]
},
"materials": {
"abiVersion": 1,
"fallback": "course:neutral",
"properties": [
{
"id": "course:tint",
"type": "vec4",
"default": [
1,
1,
1,
1
],
"glsl": "AmberTint"
},
{
"id": "course:response",
"type": "float",
"default": 0,
"range": [
0,
1
],
"glsl": "AmberResponse"
}
],
"tags": [
{
"id": "course:mineral",
"glsl": "AMBER_MINERAL"
}
],
"definitions": [
{
"id": "course:neutral",
"shaderId": 0
},
{
"id": "course:stone",
"shaderId": 1,
"tags": [
"course:mineral"
],
"values": {
"course:tint": [
1.08,
1.01,
0.92,
1
],
"course:response": 0.25
}
},
{
"id": "course:sand",
"shaderId": 2,
"values": {
"course:tint": [
1.06,
1.02,
0.94,
1
],
"course:response": 0.4
}
}
],
"contentGroups": [
{
"id": "course:stones",
"ids": [
"survivalcraft:GraniteBlock",
"survivalcraft:BasaltBlock"
]
}
],
"mappings": [
{
"id": "course:stone-map",
"match": {
"groups": [
"course:stones"
]
},
"material": "course:stone",
"priority": 10,
"onMissing": "skip"
},
{
"id": "course:sand-map",
"match": {
"ids": [
"survivalcraft:SandBlock"
]
},
"material": "course:sand",
"priority": 10,
"onMissing": "skip"
}
]
}
}Validation and game observations
Extract into a new direct child of shaderpacks. From that pack root, use the pinned Analyzer installed in environment setup. Zero diagnostics and exit code 0 are expected. With materials but no world snapshot, deferred mapping is expected. Apply the settings inside a creative world, reload, resize and restore BuiltIn.
$analyzer = "C:\Tools\Dawnlight\shaderpack-analyzer.exe"
& $analyzer pack validate . --format json
& $analyzer scene explain . --include-inactive --format json
& $analyzer graph dump . --contract 2 --include-inactive
& $analyzer program interface . --program course:scene/terrain --contract 2
& $analyzer program interface . --program course:post/grade --contract 2
& $analyzer program interface . --program course:post/present --contract 2
& $analyzer data explain . --format json
& $analyzer materials explain . --format jsonThese graph CLI commands check defaults. The committed branch receipt uses JSON-RPC with explicit inputs.options; see the branch table and maintenance procedure.
For actual mapping, load the world, run /switchshader content-export, and pass that file as --content-snapshot world-final.json to materials explain. Export /switchshader export-data-driver-report for Data interface comparison. Keep the world snapshot private.
Actual game observations · W6
Observed 3 option branches, loading/switching, same-pack reload, actual window resizing and return to BuiltIn in the isolated creative world. Programs linked and framebuffers were complete. Data interfaces matched; no numeric readback was performed.
8c37adf9fd9eaa14e45f8a4e1cd8a81a525798813551d0dcc856dab4c250a04a
Branch and lifecycle evidence summary

Troubleshooting
DLMAT1005 calls for checking flat highp uint on both varying declarations. DLMAT1002 means the table must be consumed as a readOnly storageBuffer, never a UBO. Deferred mappings require content-export after world loading and that same snapshot passed to materials explain. Do not borrow another world’s slot table. Alpha-tested and transparent routes remain BuiltIn and are outside this opaque material shader.
Exercise
Give SandBlock a subtle cool tint in a copy, leaving neutral white. Compare sand and an unmatched block. Add a second conflicting mapping at the same priority, confirm rejection during validation or snapshot resolution and restore it. Explain why chapter 04’s low-16-bit RT2 teaching bytes are unsuitable as stable material IDs.