image thumbnail

MATLAB Plot Gallery - Change Lighting to Flat



23 Feb 2012 (Updated )

Change lighting algorithm to flat (uniform lighting)


This is an example of how to produce a uniform lighting across the surfaces in MATLAB®. This lighting is good for viewing faceted surfaces.

Read about the light and lighting functions in MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Create a grid of x and y points
points = linspace(-2, 0, 20);
[X, Y] = meshgrid(points, -points);

% Define the function Z = f(X,Y)
Z = 2./exp((X-.5).^2+Y.^2)-2./exp((X+.5).^2+Y.^2);

% "flat" lighting is good for faceted surfaces
surf(X, Y, Z)
view(30, 30)
shading faceted
lighting flat
title('Lighting flat')

Contact us