shading — Set surface shading to flat, interpolated, or faceted modes with MATLAB-compatible shading syntax.
shading controls how surface-family plots render color interpolation and facet edges. It supports MATLAB-compatible forms such as shading flat, shading interp, and shading faceted for surf/mesh workflows.
Syntax
ok = shading(mode)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
mode | StringScalar | Yes | — | Shading mode token: 'flat'|'interp'|'faceted'. |
Returns
| Name | Type | Description |
|---|---|---|
ok | LogicalArray | True on successful shading mode update. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:shading:InvalidArgument | Shading mode is missing, non-string, or unsupported. | shading: invalid argument |
How shading works
shading flatuses flat shading across faces.shading interpenables interpolated/smooth shading across the rendered surface.shading facetedrestores faceted surface presentation.- Shading state is subplot-local through the shared plotting metadata model.
Examples
Apply interpolated shading to a surface
[X, Y] = meshgrid(linspace(-3, 3, 50), linspace(-3, 3, 50));
Z = sin(X) .* cos(Y);
surf(X, Y, Z);
shading interp;Compare flat and faceted shading across subplots
[X, Y] = meshgrid(linspace(-3, 3, 40), linspace(-3, 3, 40));
Z = sin(X) .* cos(Y);
subplot(1, 2, 1);
surf(X, Y, Z);
shading flat;
subplot(1, 2, 2);
surf(X, Y, Z);
shading faceted;Using shading with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how shading changes the result.
Run a small shading example, explain the result, then change one input and compare the output.
FAQ
What's the difference between interp, flat, and faceted shading?⌄
flat fills each face with a single color (the value at one vertex). interp smoothly interpolates color across each face, producing a continuous gradient. faceted is like flat but with visible black edge lines between faces — this is the default surf appearance.
When should I use shading interp vs faceted?⌄
Use interp when you want a smooth, publication-quality surface without visible grid edges — good for dense meshes or photorealistic renders. Use faceted (the default) when you want to see the mesh structure, which helps during debugging or when the grid resolution matters to the reader.
Does shading affect mesh plots or just surf?⌄
It applies to both surf and mesh (and their variants like surfc, meshc). On a mesh plot the effect is most visible in how face colors are computed — interp smooths them, flat locks each face to one value. Edge visibility is controlled separately.
Related Plotting functions
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how shading is executed, line by line, in Rust.
- View the source for shading in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.