Filter löschen
Filter löschen

Edge lines not drawn when adjacent patch is transparent

1 Ansicht (letzte 30 Tage)
cTroels
cTroels am 22 Mai 2024
Beantwortet: cTroels am 23 Mai 2024
Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I've attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch('Faces',faces,'Vertices',verts,'Facecolor','flat','EdgeAlpha','flat','FaceAlpha','flat', ...
'FaceVertexAlphaData',facealp,'FaceVertexCData',1-facealp,'Linewidth',2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way?

Akzeptierte Antwort

cTroels
cTroels am 23 Mai 2024
For anyone running into the same problem as me down the line, i figured out that i needed to sort the order of my faces, such that patch plots them in the order of transparency. The lines are then always shown for opaque elements, even if the adjacent element are transparent.

Weitere Antworten (1)

Kunal Kandhari
Kunal Kandhari am 22 Mai 2024
Hi,
To ensure that the edges are always drawn around faces, regardless of the transparency of adjacent faces, you can set the 'EdgeAlpha' property of the patch object to a fixed value, rather than 'flat'. By doing this, you ensure that the edges will always have a consistent transparency level regardless of the transparency of adjacent faces.
In the code, change the value of 'EdgeAlpha' from 'flat' to 0.5.
  1 Kommentar
cTroels
cTroels am 22 Mai 2024
Bearbeitet: cTroels am 22 Mai 2024
But wouldnt that also draw all edges as opaque around the transparant element? I want the transparancy of the lines sorrounding a face being the same as the transparancy of the face itself

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by