RunMat
GitHub

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

NameTypeRequiredDefaultDescription
modeStringScalarYesShading mode token: 'flat'|'interp'|'faceted'.

Returns

NameTypeDescription
okLogicalArrayTrue on successful shading mode update.

Errors

IdentifierWhenMessage
RunMat:shading:InvalidArgumentShading mode is missing, non-string, or unsupported.shading: invalid argument

How shading works

  • shading flat uses flat shading across faces.
  • shading interp enables interpolated/smooth shading across the rendered surface.
  • shading faceted restores 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.

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · polarplot · print · suptitle · xline · yline

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.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.