image thumbnail

MATLAB Plot Gallery - Change Lighting to Phong

by

 

23 Feb 2012 (Updated )

Change lighting algorithm to phong

Lighting_Phong

This is an example of how to produce an interpolated lighting across the surfaces in MATLAB®. This lighting is good for viewing curved 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);

% "phong" lighting is good for curved, interpolated surfaces. "gouraud"
% is also good for curved surfaces
surf(X, Y, Z)
view(30, 30)
shading interp
light
lighting phong
title('Lighting phong')

Contact us