No effect of the FaceLighting property on a single patch?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
Réponse acceptée
Turlough Hughes
le 3 Jan 2022
There are two reasons.
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 commentaires
Turlough Hughes
le 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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!