Class MaterialDescriptors
The descriptors behind the toolkit's material helpers, for when a helper's material is nearly
right: take the descriptor, add or swap a feature, and compile it with
game.CreateMaterial(descriptor) or Material.New.
public static class MaterialDescriptors
- Inheritance
-
MaterialDescriptors
Remarks
A material in Stride is a bag of features: a colour or a texture in the diffuse slot, a diffuse model that says how light spreads, a glossiness and a metalness, a specular model that says what shape the reflection has, and so on. Each method here fills that bag one common way; what a helper leaves out is left out of the shader, so the flat material has no lighting code at all. The manual page on materials explains what the numbers claim and what the gallery shows.
Fields
DefaultGlossiness
The glossiness the helpers use when none is given: neither rough nor a mirror.
public const float DefaultGlossiness = 0.65
Field Value
Methods
Emissive(Color, float)
A surface that gives off its own light: the colour as diffuse under Lambert, and the same colour
as emissive at intensity. Above 1 the emissive overshoots the display range,
which is what a bloom post effect picks out of the frame. No specular: a lamp has no highlight of its own.
public static MaterialDescriptor Emissive(Color colour, float intensity = 1)
Parameters
colourColorThe colour, lit and emitted.
intensityfloatThe emissive strength; 1 is the colour as given, 5 or more blooms under post effects.
Returns
Flat(Color)
A flat colour unaffected by lighting: the colour as emissive and as diffuse, no specular. What
game.CreateFlatMaterial(colour) compiles; the material for 2D shapes and HUD elements.
public static MaterialDescriptor Flat(Color colour)
Parameters
colourColorThe colour, alpha included.
Returns
Highlight(Color, float, float)
A highlight shell: the model drawn again a little larger, glowing faintly over the original, the hover effect of the engine's TopDownRPG template transcribed. For a HighlightShell, which puts it on every material slot of the model under the mouse.
public static MaterialDescriptor Highlight(Color colour, float strength = 1, float inflate = 0.02)
Parameters
colourColorThe glow's colour.
strengthfloatHow much of the colour is added over the model; 1 is the template's, strong enough to read on a bright surface.
inflatefloatHow far the shell stands off the surface along the vertex normals, in the model's own units before its scale.
Returns
Remarks
Four features, no diffuse: a constant displacement in the vertex stage pushes every vertex out along its normal; an emissive colour is the whole of its shading, with its alpha taken from the emissive; a blend transparency with a small alpha lets the original show through; and no culling, so the glow reads from inside the shell as well. What ends up on screen is the colour added over the model, like light. The shell's shadow is its entity's business: a HighlightShell turns it off.
On a model with split normals - a cube's corners, any flat-shaded edge - the faces move apart and the shell opens at the seams; on smooth models it closes.
Microfacet()
The engine's microfacet specular model at its defaults: Schlick Fresnel, Smith-Schlick-GGX visibility,
the GGX distribution and the GGX lookup-table environment term. One method so every descriptor here
shares one choice; the lookup table needs the content manager at compile time (see Pbr(Color, float, float)).
When there is no content manager to give - a tool, a test - set
Environment = new MaterialSpecularMicrofacetEnvironmentGGXPolynomial(), a fit that needs no asset.
public static MaterialSpecularMicrofacetModelFeature Microfacet()
Returns
Pbr(Color, float, float)
The four numbers of a PBR (physically based rendering) material - the model where a surface is
described by what it is made of, a colour, a metalness and a glossiness, and light is computed
from that - under the Lambert diffuse and microfacet specular models. What game.CreateMaterial(colour, metalness, glossiness) compiles.
public static MaterialDescriptor Pbr(Color colour, float metalness = 0, float glossiness = 0.65)
Parameters
colourColorThe colour: the diffuse of a dielectric, the reflection tint of a metal.
metalnessfloat0 for a dielectric, which keeps its colour as diffuse and reflects a colourless 4 percent; 1 for a metal, which has no diffuse and reflects in its own colour.
glossinessfloat0 for rough, where the highlight is a haze; 1 for a mirror.
Returns
Remarks
The specular model is the engine's default, whose environment term is a lookup texture the engine
ships as an asset. Compile the descriptor with game.CreateMaterial(descriptor) or
Material.New(device, descriptor, game.Content) so that texture resolves; Material.New
without the content manager leaves it empty and every metal renders black.
Screen(Texture, float)
A screen showing a texture: the texture as emissive, clamped so nothing wraps at the edges, and no lighting, so the picture reads as given whichever way the surface faces. The material for a monitor showing a render-texture camera's feed.
public static MaterialDescriptor Screen(Texture texture, float intensity = 1)
Parameters
textureTextureWhat the screen shows; a render target works as well as a loaded image.
intensityfloatThe emissive strength; 1 shows the texture's own colours.
Returns
Textured(Texture, float, float, float)
A texture where the colour was, with the same numbers as Pbr(Color, float, float): the albedo tiled
tiling times across the mesh's UV range.
public static MaterialDescriptor Textured(Texture texture, float metalness = 0, float glossiness = 0.65, float tiling = 1)
Parameters
textureTextureThe albedo. Load a colour texture as sRGB; the descriptor does not decide that.
metalnessfloatAs in Pbr(Color, float, float).
glossinessfloatAs in Pbr(Color, float, float).
tilingfloatHow many times the texture repeats across the UV range; 1 maps it once.