Material assets
Turn material and shader declarations into runtime resources.
Use material assets to turn authored material and shader declarations into runtime resources for a render model.
Declare a material
Declare a material in JSON with its material type, shader references, and variables:
{
"domain":"World",
"type": "Surface",
"shaders": {
"Fragment": "../.."
},
"variables": [
{
"name":"color",
"data_type": "vec4f",
"value":"Purple",
"type":"Static"
}
]
}Declare a material variant
A material variant can inherit from a parent material and replace values for variables that the parent declares:
{
"parent":"material",
"variables": [
{
"name": "color",
"value": "Red"
}
]
}When variants share shader code, Byte Engine can use one pipeline with different per-instance values.
Do not depend on this optimization. Byte Engine can create additional shader or pipeline variants when static replacement produces better runtime code.
Load and process materials
When you request a material, Byte Engine loads the material or variant and its shader dependencies before processing begins.
Processing produces the shader code and metadata that a render model needs at runtime.
flowchart TD
ma ---> Materials --> Shaders
subgraph Materials
Material
end
subgraph Shaders
Vertex
Fragment
...
end
shader_manager[[Shader Manager]]
Materials ---> shader_manager
Shaders ---> shader_manager
render_model_a[Visibility]
render_model_b[Forward]
shader_manager ---> render_model_a
shader_manager ---> render_model_b
subgraph Resources
subgraph resources.materials[Materials]
Material
end
subgraph resource.shaders[Shaders]
Compute
end
end
render_model_a ---> ResourcesEach generated material identifies its render model:
{
"name":"material",
"model": {
"name":"Visibility",
"pass":"MaterialEvaluation",
},
"variables": [
{
"name": "color",
"type": "Static",
"data_type": "vec4f",
"value": "Purple",
}
]
...
}Byte Engine also extracts variable definitions from shader code.
Shader generation details not available
The documentation doesn't yet explain how Byte Engine converts declarations into render-model-specific shader code and metadata.
For the supported declaration format, continue to the
.bema file guide.