shading — Control flat, interpolated, or faceted surface shading with MATLAB shading workflows.
shading controls how surfaces and related scalar-field plots interpolate or facet their color/geometry presentation. In RunMat it is most relevant for the surface family (surf, mesh, surfc, meshc) and complements colormap-driven visualization workflows with the standard MATLAB shading flat, shading interp, and shading faceted styles.
How shading works in RunMat
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;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 functions to explore
These functions work well alongside shading. Each page has runnable examples you can try in the browser.
surf, mesh, colormap, colorbar
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how shading works, line by line, in Rust.
- View shading.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.