No effect of the FaceLighting property on a single patch?

10 Ansichten (letzte 30 Tage)
Sim
Sim am 3 Jan. 2022
Bearbeitet: Sim am 4 Jan. 2022
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 Kommentar
Sim
Sim am 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)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 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 Kommentare
Turlough Hughes
Turlough Hughes am 4 Jan. 2022
Actually, yes, patch allows you to manually modify the vertex norms. From the previous examples you could write the following:
hp(4).VertexNormals = hp(2).VertexNormals([2 3 7 6],:)
Or just the figure on it's own would be the following:
clear, close all
figure()
hp = patch([1 1 1 1], [0 1 1 0], [0 0 1 1],[1 1 0],...
'FaceLighting','Gouraud');
view(30,30)
light('Position',[2 2 2]), view(30,30)
hp.VertexNormals = [-1 1 -1; -1 -1 -1; -1 -1 -1; -1 1 -1];
and from your original question:
figure()
X = [-24 44 44 -24];
Y = [15 15 15 15];
Z = [0 0 22 22];
hp2 = patch(X,Y,Z,'red','FaceLighting', 'Gouraud');
light('Position',[1 -1 1])
view(30,30)
% Actually here the graphics don't always update after changing
% the norms (seems like a bug tbh), so drawnow is a workaround.
drawnow
hp2.VertexNormals([1 4],:) = repmat([1 -1 1], 2, 1);
Sim
Sim am 4 Jan. 2022
Bearbeitet: Sim am 4 Jan. 2022
AMAZING! Exactly what I needed!
If possible, I would press the button "Accept this Answer" a second time !!
All the best :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by