Skip to content

Writing a material shader

A material shader is a program in the Slang shading language that decides the color of every pixel of the parts that wear a material. Use one when the built-in material settings cannot give the look you want: cel shading, ink outlines, an unlit glow, a pulsing color, a see-through force field. A shader changes how a part looks and can draw a line around it, without changing the part's shape: the part still blocks the camera, collides, and casts shadows unless it draws see-through. A script can change a shader's parameters while the game runs.

A cel-shaded material with an ink outline

A shader is a .slang file in the project's shaders/ folder. The place keeps a copy of every file in that folder and of the project's materials, so every player draws the same look as Play in Studio. This shader paints parts in flat steps of light and draws a bold, slightly rough line around every part, mesh and character that wears it:

shaders/ink.slang

#language slang 2026
import luduvo;

// Flat cel shading with a bold ink outline that follows the shape of every
// part, mesh and character wearing the material.
struct Ink : IMaterial, IOutline
{
    [Color] [Group("Cel")] float3 shadeColor = float3(0.62, 0.60, 0.80);   // multiplies the part color in shade
    [Group("Cel")] [Range(1, 8)] float bands = 3;                          // light steps between shade and full
    [Color] [Group("Outline")] float3 inkColor = float3(0.10, 0.08, 0.14); // color of the outline
    [Group("Outline")] [Range(0, 12)] float inkWeight = 3;                 // outline width in UI points
    [Group("Outline")] [Range(0, 1)] float sketch = 0;                     // 0 draws a clean line, 1 a rough hand-drawn one

    Surface surface(SurfaceInput i)
    {
        float light = saturate(dot(i.normal, i.sun.direction)) * i.sun.visibility;
        float level = ceil(light * bands) / bands;
        Surface s = Surface(i);
        s.baseColor *= lerp(shadeColor, float3(1.0), level);
        s.lit = false;
        return s;
    }

    Outline outline(OutlineInput i)
    {
        // A random width at each corner, the same wherever corners meet.
        float wobble = frac(sin(dot(i.objectPosition, float3(12.9898, 78.233, 37.719))) * 43758.5453);
        Outline o = Outline(i);
        o.color = inkColor;
        o.width = inkWeight * (1.0 + sketch * (2.0 * wobble - 1.0));
        return o;
    }
};

export struct Material : IMaterial = Ink;
-- Server script under scripts/autorun/: parts tagged Ink and every
-- character wear a material drawn with shaders/ink.slang.
local ink = Materials.DefineMaterial({
    Name = "Ink",
    Shader = "ink",
    Params = {
        inkColor = Color.fromRGB(40, 24, 60),
        sketch = 0.5,
    },
})

local Ink = World.DefineComponent("Ink")
for part in World.Query(Ink) do
    part.Material = ink
end

Component.Character.Added:Connect(function(character: Entity)
    character.Material = ink
end)
-- Client script under scripts/autorun/: the line swells and thins on this
-- player's screen only.
local clock = 0

function Update(dt: number)
    clock += dt
    Materials.Override("Ink", "inkWeight", 4 + 2 * math.sin(clock * 2))
end

What a shader file has

  • #language slang 2026 on the first line keeps the meaning of the file fixed when Luduvo updates its Slang compiler. A file without it is read as Slang 2026, and slang 2025 is accepted too.
  • import luduvo; brings in the types below. A shader imports only luduvo and other .slang files in the project's shaders/ folder.
  • One struct conforms to IMaterial. Its surface function returns the look of one pixel of a part. It may also conform to IOutline, whose outline function draws a line around the part; see Outlines.
  • The last line, export struct Material : IMaterial = Ink;, names that struct. It names IMaterial alone, even when the struct also conforms to IOutline.

The engine runs surface for each pixel of the parts, then lights, fogs and exposes the result like every other surface.

SurfaceInput: what a pixel knows

Field Type Meaning
position float3 Position in the world, in units.
normal float3 Direction the surface faces, length 1.
toCamera float3 Direction from the surface to the camera, length 1.
uv float2 Texture coordinate of the mesh.
objectPosition float3 Position in the part's own frame, in units, with its Size applied: a Box, Sphere, Cylinder, Cone or Wedge part spans -objectSize / 2 to objectSize / 2, and a Mesh has its own coordinates times Size.
objectNormal float3 Direction the surface faces in the part's own frame, length 1.
objectSize float3 The part's Size.
color float4 The part's Color in rgb and its opacity, 1 - Transparency, in a.
baseColor float4 The part's color at this pixel with its own textures: a mesh's texture times Color, or a character's clothing over its skin. Equals color where the part has no texture of its own.
sun.direction float3 Direction from the surface toward the sun, length 1.
sun.color float3 Color of the sunlight: Lighting.Sun.Tint times its Intensity, redder near the horizon. A white sun at intensity 1 high in the sky is about 1; black while the sun is down or switched off.
sun.visibility float 0 where the surface is in the sun's shadow, under thick cloud or while the sun is down, 1 in full sun.
sampler SamplerState The sampler for textures, as in texture.Sample(i.sampler, uv): linear between texels and mipmap levels, with the player's anisotropic filtering, and a coordinate past 0 or 1 wraps around.
time float Seconds on this player's clock; see Time.
frontFacing bool false where the camera sees the back of the surface; see Faces.
pixelDepth float Distance of this pixel in front of the camera, in units, along the direction the camera looks.
sceneDepth float Distance of the nearest opaque surface behind this pixel, measured the same way as pixelDepth; see Soft edges with scene depth.
object ObjectMaps The part's shape and its own textures; see The part's own textures.

SurfaceInput also has functions for normal maps:

  • i.normalMap(texture, uv) reads a normal map field. Until a script sets the field, and while its texture downloads, it returns (0, 0, 1), which perturbNormal turns into i.normal itself; x and y tilt it along the texture.
  • i.perturbNormal(n, uv) turns n from normalMap into a world direction, length 1, for Surface.normal. Pass the uv that read the map: the frame comes from how uv and position change between neighboring pixels.
  • SurfaceInput.cotangentFrame(normal, position, uv) returns that frame as a float3x3, for a normal other than i.normal or for several maps at one uv. perturbNormal returns normalize(mul(n, frame)).
  • SurfaceInput.unpackNormal(texel, dxt5n) turns a texel already read from a normal map into the direction normalMap returns. Pass true for a map stored as DXT5n, which keeps x in alpha and y in green; a texture field's handle says so in ((uint2)texture).y & 1, which normalMap reads for you.

Surface: what a pixel looks like

Surface(i) starts from the part: its color with its own textures, its opacity and its normal. Change the fields you need and return it.

Field Type Default Meaning
baseColor float3 the part's color with its textures, SurfaceInput.baseColor Color of the surface.
alpha float the part's opacity, 1 - Transparency, times its texture's How much of the surface covers what is behind it, 0 to 1, where the part draws see-through: 0 is clear, 1 hides everything behind. A part drawn opaque ignores it, unless its material is "Cutout". Multiply it, as in s.alpha *= rim;, so the part's Transparency still counts. See Transparent materials and Cutout materials.
normal float3 the direction the part faces Direction lighting uses, length 1.
roughness float 0.5 0 is a mirror-like shine, 1 is matte.
metallic float 0 1 reflects like metal.
occlusion float 1 Darkens light that reaches into creases, 0 to 1.
emission float3 black Glow that shows at the same brightness in any light.
lit bool true false skips lighting: the pixel shows baseColor + emission at the brightness emission shows, then takes fog and the camera's exposure.

Outlines

A material struct that also conforms to IOutline draws a line around every part that wears the material, following the part's shape: a box, a wedge, a sphere, a mesh or a character. The engine grows a copy of the part outward by the line's width and draws the inside of that copy behind the part, so the line shows around the part's edges and wherever one part passes in front of another.

outline runs once for each corner of the part's mesh, so a width that changes along the line changes from corner to corner. Corners that meet share their objectPosition; compute the width from it, as ink.slang does, and the line stays closed.

OutlineInput: what a corner knows

Field Type Meaning
position float3 Position in the world, in units.
normal float3 Direction the surface faces, length 1.
toCamera float3 Direction from the corner to the camera, length 1.
uv float2 Texture coordinate of the mesh.
objectPosition float3 Position in the part's own frame, as in SurfaceInput.
objectNormal float3 Direction the surface faces in the part's own frame, length 1.
objectSize float3 The part's Size.
color float4 The part's Color in rgb and its opacity in a.
time float Seconds on this player's clock, wrapping every 3600, as in SurfaceInput.

Outline: what the line looks like

Outline(i) starts with a black line one UI point wide. Change the fields you need and return it.

Field Type Default Meaning
color float3 black Color of the line. It skips lighting like Surface.lit = false, then takes fog and the camera's exposure.
width float 1 How far the line reaches past the edge of the part, in UI points (1 point is 1 pixel at UI scale 1), at any distance. 0 or less draws no line at that corner.

Transparent materials

A material with a Shader and Pipeline = "Transparent" draws see-through: its parts draw after every opaque part, and Surface.alpha sets how much of each pixel covers what is behind it. Glass, water, holograms, smoke and force fields are transparent materials.

The material's Blend sets how a pixel combines with the color behind it. In the formulas, color is the pixel's color after lighting, or its baseColor when lit is false, and behind is what the screen already shows there:

Blend What the screen shows Use it for
"Alpha", the default color * alpha + emission + behind * (1 - alpha) glass, water, a shield: a surface that hides what is behind it by alpha
"Additive" behind + color * alpha + emission fire, sparks, beams, a hologram: light that only brightens what is behind it

With "Alpha", emission adds at full strength whatever alpha is, so a pixel at alpha 0 with emission is pure glow over a clear surface, and a pixel at alpha 1 looks like the same surface drawn opaque. "Additive" never darkens, and the order in which additive parts draw does not change the result. Fog and water between the camera and the part dim the pixel with distance as they dim an opaque surface; a clear pixel adds no fog of its own, and additive light fades into the fog instead of taking its color.

A part with Transparency above 0 that wears a material with a Shader and Pipeline = "Opaque" also draws see-through, with the material's Blend and Faces. Surface(i) starts alpha at the part's opacity, so a shader that multiplies alpha fades out as Transparency rises. At Transparency 0 the part draws opaque.

See-through parts with a shader share these limits:

  • The engine sorts them by the distance to their centers and draws them far to near, one part after another. Where two cross each other, or one is inside another, the wrong one can show in front.
  • They draw over built-in see-through parts, such as a "Transparent" material without a shader or a plain part with Transparency above 0, where the two overlap, even where the built-in part is nearer.
  • They draw no outline: IOutline draws only around parts drawn opaque.
  • They cast no shadow in sunlight, like every see-through part.

Cutout materials

A material with a Shader and Pipeline = "Cutout" draws opaque with holes. A pixel is cut out where s.alpha is below AlphaCutoff times the part's opacity, 1 - Transparency. AlphaCutoff is set in the material's Surface table and is 0.5 unless that table sets it. What is behind the part shows through a hole, and a part fading out through Transparency keeps the same holes. Leaves, fences, grates and lace are cutout materials. The edge of a hole is sharp, and the order in which parts draw does not matter.

A cut-out pixel hides nothing behind it from the camera, and the light of a point or spot light passes through it, so their shadows have the same holes. In sunlight the part still casts the shadow of its whole shape. A point or spot light redraws its shadow only when something in its range moves, so a hole that changes with time or a new AlphaCutoff shows in that shadow at the light's next redraw.

Compute alpha only from the part's geometry, its textures, its Params and time. The engine also runs Surface(i) for the depth and shadow passes, where i.sun and i.toCamera do not describe the camera's view, so an alpha that reads them cuts holes that differ from pass to pass.

A cutout part draws no outline: an IOutline line would fill its holes.

Faces

A material's Faces sets which side of its parts' surfaces draws:

  • "Front", the default, draws the front of every surface, the outside of a closed part.
  • "Back" draws only the back: seen from outside, a box shows the inside of its far walls.
  • "Both" draws both sides, for leaves and cloth made of single sheets, a mesh with holes, or a shield seen from inside.

Where the camera sees the back, SurfaceInput.frontFacing is false, and normal and objectNormal point toward the camera, so lighting works the same on both sides. Test frontFacing to color the inside differently, as in s.baseColor = i.frontFacing ? outsideColor : insideColor;.

A see-through part with "Both" draws its back and then its front, so a closed shape such as a sphere shows its far side behind its near side, from outside and from within.

Time

SurfaceInput.time is seconds on this player's clock, the same for every part in one frame. It runs in Studio's edit mode and in play, and wraps back to 0 every 3600 seconds. It animates a surface without a script: a scrolling texture, a pulsing glow, bands that sweep across a shield. A glow that pulses once a second:

s.emission = glowColor * (0.5 + 0.5 * sin(i.time * 6.2831853));

A pattern that repeats a whole number of times in 3600 seconds, as this pulse does, wraps without a jump. Outline shaders receive the same clock in OutlineInput.time. Use Materials.SetParam instead for changes the game decides, such as a key press or a hit.

Soft edges with scene depth

A see-through part shows a hard line where it cuts into the ground or a wall. SurfaceInput.sceneDepth minus pixelDepth is how far behind the pixel the nearest opaque surface is, so a fade over fadeDistance units, above 0, is one line:

float contact = 1 - saturate((i.sceneDepth - i.pixelDepth) / fadeDistance);

contact is 1 where the part touches the surface behind it and 0 where that surface is fadeDistance units or more behind. Multiply s.alpha by 1 - contact to fade water or fog out at its edges, or add contact to a glow to light a shield up where it meets the ground.

sceneDepth sees only opaque surfaces. It reads 1e30 where only sky is behind the pixel and on every part drawn opaque, so contact is 0 there.

A force field

This shader draws a shield the player sees through: nearly clear where it faces the camera, bright at its rim, crossed by bands of light that climb over time, and glowing where it touches the ground or a wall:

shaders/forcefield.slang

#language slang 2026
import luduvo;

// A see-through energy shield: nearly clear where it faces the camera,
// bright at its rim, crossed by bands of light that climb on the clock, and
// glowing where it touches the ground or a wall.
struct ForceField : IMaterial
{
    [Color] float3 glowColor = float3(0.20, 0.60, 1.00); // color of the rim, the bands and the contact glow
    [Range(0, 8)] float glowStrength = 2;                // brightness of the glow
    [Range(0, 1)] float faceAlpha = 0.05;                // how much the shield covers where it faces the camera
    [Range(0.5, 8)] float rimSharpness = 3;              // higher draws a thinner rim
    [Range(0.25, 16)] float bandSpacing = 2;             // units between two bands
    [Range(0, 8)] float bandSpeed = 0.5;                 // units the bands climb each second
    [Range(0.05, 4)] float fadeDistance = 0.5;           // units over which the contact glow fades out

    Surface surface(SurfaceInput i)
    {
        // 0 where the shield faces the camera, 1 where it turns edge on. On
        // the inside the normal already points at the camera, so both sides
        // get a rim.
        float rim = pow(1.0 - saturate(dot(i.normal, i.toCamera)), rimSharpness);

        // Thin bands of light that climb up the part on the clock.
        float wave = sin((i.objectPosition.y - i.time * bandSpeed) * 3.14159265 / bandSpacing);
        float band = pow(abs(wave), 24.0);

        // 1 where the shield touches the scene behind it, 0 fadeDistance away.
        float contact = 1.0 - saturate((i.sceneDepth - i.pixelDepth) / fadeDistance);

        float glow = saturate(rim + 0.5 * band + contact);
        Surface s = Surface(i);
        s.baseColor = glowColor;
        s.lit = false;
        s.alpha *= lerp(faceAlpha, 1.0, glow);
        s.emission = glowColor * glowStrength * glow;
        return s;
    }
};

export struct Material : IMaterial = ForceField;

dot(i.normal, i.toCamera) is 1 where the surface faces the camera and 0 where it turns edge on, so the rim is bright where the dot is small.

-- Server script under scripts/autorun/: parts tagged Shield wear a material
-- drawn with shaders/forcefield.slang. On a Sphere part it makes a bubble.
local shield = Materials.DefineMaterial({
    Name = "Shield",
    Pipeline = "Transparent",
    Shader = "forcefield",
    Blend = "Alpha",
    Faces = "Both",
    Params = {
        glowColor = Color.fromRGB(70, 160, 255),
        bandSpeed = 1,
    },
})

local Shield = World.DefineComponent("Shield")
for part in World.Query(Shield) do
    part.Material = shield
end

Faces = "Both" draws the far inside of the bubble behind its near side, so the bubble looks round, and a camera inside it still sees it.

Parameters

Every field of the material struct is a parameter, and its initializer, written as numbers such as 0.5 or float3(1.0, 0.5, 0.0), is its default. A material's Params set starting values by field name, and Materials.SetParam changes a value on one player's screen from the next frame. A material sets 16 parameters at most. Fields are float, int, uint or bool, alone or as vectors of 2 to 4, or textures; matrices, arrays and structs are not parameters.

Field type Script value
float, int, uint a number; int and uint round it
bool a boolean, or a number where 0 is false
float2, float3, float4 a vector from Vector3.new or a Color; a float4 gets 1 in w
Texture2D.Handle a texture asset id string, as in a material's Surface.BaseColor

Mark a color field with [Color], as in [Color] float3 inkColor = float3(0.10, 0.08, 0.14);. Its default, Params value and SetParam values use the same color space as Color for a part's Color. The shader receives linear light, like SurfaceInput.color, and the w of a float4 stays as given. Other fields reach the shader exactly as given. A parameter the shader does not declare, or a value of the wrong type, keeps the field's default and prints a warning that names the field.

Four more marks change how Studio shows a field in a material's Properties. The shader and scripts see the field the same as without them:

Mark Goes on Studio shows
[Range(0, 12)] a float, int or uint a slider from the first number to the second; a script may still set any value
[Group("Outline")] any field the field under that heading, with the other fields of the group, in the order the struct declares them
[Enum("Flat,Bands,Hatch")] an int or uint a dropdown of the names, the first being 0, the next 1, and so on
[Hidden] any field nothing; Params and SetParam still set it by name

Write a field's marks one after another, as in [Group("Outline")] [Range(0, 12)] float inkWeight = 3;.

In Studio, unfold an entity's material in its Material card and pick the shader in the Shader row. The row lists the project's shaders by name, plus ink and untiled, which copy their template into shaders/ first. With a shader picked, the Pipeline Class row lists Opaque, Cutout and Transparent, and the Blend and Faces rows set how the material draws. The rows below are the shader's fields; the arrow beside a field you set puts it back to the shader's default, and Open shows the file in the script editor. Studio's material.define command sets the same three choices, as in material.define Shield pipeline=transparent blend=alpha faces=both.

Textures

A field written Texture2D.Handle is a texture. Read it with SurfaceInput.sampler, as in texture.Sample(i.sampler, uv); other Texture2D methods work the same way. Until a script sets the field, and while its texture downloads, it reads white. A texture keeps the color space it was uploaded in, so a picture reads as linear light, like SurfaceInput.color, and a normal or roughness map reads as stored.

This shader lays a texture across a large floor without the repeat that a plain tiled texture shows: each tile of the grid takes the texture at its own random offset, and neighboring tiles fade into each other:

shaders/untiled.slang

#language slang 2026
import luduvo;

// A tiled texture without the repeat that shows across a large floor:
// every tile takes the texture at its own random offset, and neighboring
// tiles fade into each other near their edges.
struct Untiled : IMaterial
{
    Texture2D.Handle texture;             // the picture to tile
    [Range(0.5, 32)] float tileSize = 4;  // units across one tile
    [Range(0, 1)] float randomness = 1;   // 0 tiles the texture plainly, 1 moves every tile

    // The texture in one tile, moved by that tile's own random offset.
    float4 tile(SurfaceInput i, float2 uv, float2 cell, float2 dx, float2 dy)
    {
        float2 h = frac(sin(float2(dot(cell, float2(127.1, 311.7)), dot(cell, float2(269.5, 183.3)))) * 43758.5453);
        return texture.SampleGrad(i.sampler, uv + h * randomness, dx, dy);
    }

    Surface surface(SurfaceInput i)
    {
        // Lay the texture flat on the face the pixel lies on, in units.
        float3 n = abs(i.objectNormal);
        float2 p = n.y > max(n.x, n.z) ? i.objectPosition.xz
                 : n.x > n.z           ? i.objectPosition.zy
                                       : i.objectPosition.xy;
        float2 uv = p / tileSize;
        float2 dx = ddx(uv);
        float2 dy = ddy(uv);

        // Blend the four tiles around the pixel by how close it is to each.
        float2 cell = floor(uv - 0.5);
        float2 b = smoothstep(0.25, 0.75, frac(uv - 0.5));
        float4 color = lerp(lerp(tile(i, uv, cell, dx, dy), tile(i, uv, cell + float2(1, 0), dx, dy), b.x),
                            lerp(tile(i, uv, cell + float2(0, 1), dx, dy), tile(i, uv, cell + float2(1, 1), dx, dy), b.x),
                            b.y);

        Surface s = Surface(i);
        s.baseColor *= color.rgb;
        return s;
    }
};

export struct Material : IMaterial = Untiled;

Each tile moves the texture by its own amount, so the texture coordinate jumps at every seam. SampleGrad takes the change of uv across one pixel, which has no jump, so the seams stay as sharp as the rest of the floor; a plain Sample would blur them.

-- Server script under scripts/autorun/: floors tagged Untiled show the
-- Cobblestone texture without its repeat.
local spec = Materials.GetMaterial("Cobblestone")
local cobblestone = spec and spec.Surface
if cobblestone and cobblestone.BaseColor and cobblestone.TileSize then
    local untiled = Materials.DefineMaterial({
        Name = "Untiled",
        Shader = "untiled",
        Params = {
            texture = cobblestone.BaseColor,
            tileSize = cobblestone.TileSize,
        },
    })

    local Untiled = World.DefineComponent("Untiled")
    for part in World.Query(Untiled) do
        part.Material = untiled
    end
end
-- Client script under scripts/autorun/: R turns the random tiling off and on;
-- T lays a different stone texture.
local untiled = true
local stones = { "Cobblestone", "Slate", "Pebble" }
local stone = 1

function Update(dt: number)
    if Input.WasPressed("R") then
        untiled = not untiled
        Materials.Override("Untiled", "randomness", if untiled then 1 else 0)
    end
    if Input.WasPressed("T") then
        stone = stone % #stones + 1
        local mat = Materials.GetMaterial(stones[stone])
        local base = mat and mat.Surface and mat.Surface.BaseColor
        if base then
            Materials.Override("Untiled", "texture", base)
        end
    end
end

The part's own textures

SurfaceInput.object describes the part itself: its shape, and the textures of its mesh or of a character's clothing. The built-in materials draw a part's own textures in place of the material's; a shader does the same by testing hasAlbedo, hasNormal and hasOrm.

Member Type Meaning
primitive uint The part's shape, one of the ObjectMaps constants kPrimitiveMesh, kPrimitiveBox, kPrimitiveSphere, kPrimitiveCylinder, kPrimitiveCone and kPrimitiveWedge, as in i.object.primitive == ObjectMaps.kPrimitiveBox.
tinted bool false for a mesh with a non-clothing color texture (hasAlbedo && !clothing), which the built-in materials draw without the part's Color; true for every other part.
hasAlbedo bool The part has a color texture of its own.
hasNormal bool The part has a normal map of its own.
hasOrm bool The part has a metallic and roughness map, an occlusion map, or both.
uv(uv) float2 uv with the part's UvTransform applied (Offset, Tiling, Angle); uv unchanged when the part has none.
albedo(uv, under) float4 The part's color texture over under. For a mesh, the texture times under. For a clothing layer, the layer over under, read at the mesh's own i.uv whatever uv is, keeping under.a. Returns under when the part has no color texture.
normal(uv) float3 The part's normal map, as normalMap returns it; (0, 0, 1) without one.
orm(uv) float4 Occlusion in x, roughness in y, metallic in z and 1 in w, from the part's maps. Each is 1 where its map is missing, so multiply Surface.occlusion, roughness and metallic by them.
emissive(uv) float3 The part's glow texture; black without one.

The functions above read these fields, which a shader may also read itself:

Field Type Meaning
albedoMap, normalMap, metallicRoughnessMap, occlusionMap, emissiveMap Texture2D.Handle The part's own textures; each reads white where the part has none.
underlayMap Texture2D.Handle A clothing layer's second texture, drawn under albedoMap where it is clear: PbrMaterial.Underlay, or the pants under a character's shirt.
clothing bool albedoMap is a clothing layer (a character's shirt or pants, or a PbrMaterial on a part that has its own Color), read at meshUv.
frame, frameOffset float4, float2 The UvTransform as a 2x2 matrix, row by row, and an offset; uv() applies them.
meshUv float2 The mesh's own texture coordinate, the same as i.uv.
sampler SamplerState The same sampler as i.sampler.

This shader draws the part's own color texture and normal map when the part has them, and the shader's texture and bumps fields when it doesn't. It multiplies the color by tint:

shaders/painted.slang

#language slang 2026
import luduvo;

struct Painted : IMaterial
{
    Texture2D.Handle texture;
    Texture2D.Handle bumps;
    [Color] float3 tint = float3(1.0, 0.8, 0.6);

    Surface surface(SurfaceInput i)
    {
        Surface s = Surface(i);
        float2 uv = i.object.uv(i.uv);
        float4 under = i.object.tinted ? i.color : float4(1.0, 1.0, 1.0, i.color.a);
        float4 color = i.object.hasAlbedo ? i.object.albedo(uv, under) : under * texture.Sample(i.sampler, uv);
        s.baseColor = color.rgb * tint;
        s.alpha = color.a;
        float3 n = i.object.hasNormal ? i.object.normal(uv) : i.normalMap(bumps, uv);
        s.normal = i.perturbNormal(n, uv);
        return s;
    }
};

export struct Material : IMaterial = Painted;

When the shader cannot draw

Compiling a shader takes a moment after the place loads. Until it finishes, and on devices that cannot run material shaders, the parts draw with the Surface table of the material's MaterialSpec, or as plain parts when the material has none. The Vulkan and Direct3D 12 renderers run material shaders; the Direct3D 11 and Metal renderers use that table. Drawn from that table, a "Transparent" material and a part with Transparency above 0 draw see-through as built-in see-through parts do, Blend and Faces have no effect, and there is no outline.

A material whose Shader names no file in the project's shaders/ folder fails in DefineMaterial with Materials.DefineMaterial: no shader file 'shaders/<name>.slang' in the project. A shader that does not compile prints Slang's message, with the file and line, to the output, and its parts draw as when the shader is not ready. Luduvo's own compile messages mostly name the fix. A shader that uses half, int16_t, uint16_t or double fails with entry point '<entry>': the SPIR-V declares capability <capability>, which needs a Vulkan feature Luduvo does not enable, because Luduvo enables none of them on any GPU. Use float, int and uint; to read 16-bit floats packed in a uint, call unpackHalf2x16ToFloat, not f16tof32.