Shaders and Materials
Morph uses typed shaders. Material fields are validated by shader definitions.
Define a Shader
TexturedQuad is shader {
tint as Color;
albedo as Texture2D;
linearSampler as Sampler;
Vertex method(position as Vector3, uv as Vector2) {
pass uv;
return MVP * position;
}
Fragment method(uv as Vector2) {
return albedo.Sample(linearSampler, uv) * tint;
}
}
Create Material from Shader
material is Material<TexturedQuad>();
material.tint is Color(1.0, 1.0, 1.0, 1.0);
material.albedo is Texture2D.Load("examples/assets/checker.png");
material.linearSampler is Sampler.Create();
Built-in Shader Data
MVPis available in vertex stage for transformspasssends values from vertex stage to fragment stage
Next Steps
- Textures and Samplers - Sampling textures correctly
- Low-Level Draw Commands - Submitting shader materials