Problem with rendering patch object when FaceVertexAlphaData is given

10 次查看(过去 30 天)
When I create a single patch object with different transparency and color per face, Matlab R2016b under OSX seems having a bug in rendering it. A simple example with two cubes gives the following plot, see Matlab code below.
The main problem with this image is, that the red cube should be in the front, and it is non-transparent (alpha=1), still I see the green cube behind. I tested the same code on R2015b and the rendering looks the same.
% vertices for a cube
Vcube = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1];
% faces for a cube
Fcube = [1:4;1 2 6 5;2 3 7 6;3 4 8 7;4 1 5 8;5:8];
% red color for the faces of the cube
Cred = repmat([1 0 0],[6 1]);
% green color for the faces of the second cube
Cgreen = repmat([0 1 0],[6 1]);
% non-transparent first cube (defined on all 6 faces)
A = ones(6,1);
% two cubes
V2 = [Vcube;bsxfun(@plus,Vcube,[2 2 -1])];
F2 = [Fcube;Fcube+8];
% color for the 2 cube
C2 = [Cred;Cgreen];
% different transparency for the two cubes, red one is non-transparent,
% green is semi transparent
A2 = [A;A/2];
clf
hPatch = patch('Vertices',V2,'Faces',F2,...
'FaceColor','flat','FaceVertexCData',C2,...
'FaceAlpha','flat','FaceVertexAlphaData',A2,...
'AlphaDataMapping','none');
axis off
axis equal
axis([-1 4 -1 4 -2 2])
view(3)
If this is a bug (I believe it is), is there any known workaround?
Thanks!

采纳的回答

Sandor Toth
Sandor Toth 2017-1-19
It seems a simple command fixed the problem:
opengl hardware
After running this command and replotting the figure, I get the following image:
Before the opengl was set to:
opengl hardwarebasic

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by