No effect of the FaceLighting property on a single patch?

4 views (last 30 days)
Hi, I was trying the FaceLighting property on a single patch but I could not see any difference between "with" and "without" that FaceLighting property:
X = [-24 44 44 -24];
Y = [15 15 15 15];
Z = [0 0 22 22];
patch(X,Y,Z,'red','FaceLighting', 'Gouraud');
view(30,30)
Do you know why? What mistake did I make?
  1 Comment
Sim
Sim on 3 Jan 2022
I get the same result:
figure()
patch(X,Y,Z,'red','FaceLighting', 'Gouraud');
view(30,30)
figure()
patch(X,Y,Z,'red');
view(30,30)

Sign in to comment.

Accepted Answer

Turlough Hughes
Turlough Hughes on 3 Jan 2022
There are two reasons.
First is that you need to add a light object to the axes. To do that, use the light function.
The second reason, is that a unifaceted patch with Gouraud or Flat lighting is actually the same lighting effect. I suggest reading about how Gouraud lighting is calculated - in short, the shades over each face depend on intensities calculated at each vertex which depend the direction of the nearest surface or surfaces. For a unifaceted patch, the vertices' intesities are based on the direction of a single surface, i.e. they are all equal. However, when a vertex joins multiple faces, the vertex intensity is calculated from an average direction of the adjoining faces.
The following shows how lighting changes for a multifaceted patch, while a unifaceted patch (the same yellow one shown in the cube) results in the same distributions for Gouraud and Flat lighting:
clear, close all
vert = [0 0 0; 1 0 0;1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1];
fac = [1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8];
figure()
subplot(2,2,1), title('Flat Lighting')
hp(1) = patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat',...
'FaceLighting','flat'); % note, flat is the default
light('Position',[2 2 2]), view(30,30)
subplot(2,2,2), title('Gouraud Lighting')
hp(2) = patch('Vertices',vert,'Faces',fac,...
'FaceVertexCData',hsv(6),'FaceColor','flat',...
'FaceLighting','gouraud');
light('Position',[2 2 2]), view(30,30)
subplot(2,2,3), title('Flat Lighting')
hp(3) = patch([1 1 1 1], [0 1 1 0], [0 0 1 1],[1 1 0],...
'FaceLighting','flat');
light('Position',[2 2 2]), view(30,30)
subplot(2,2,4), title('Gouraud Lighting')
hp(4) = patch([1 1 1 1], [0 1 1 0], [0 0 1 1],[1 1 0],...
'FaceLighting','Gouraud');
light('Position',[2 2 2]), view(30,30)
[hp(:).DiffuseStrength] = deal(0.8);
  3 Comments
Sim
Sim on 4 Jan 2022
Edited: Sim on 4 Jan 2022
AMAZING! Exactly what I needed!
If possible, I would press the button "Accept this Answer" a second time !!
All the best :)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!