MATLAB: Does the Painter’s renderer in MATLAB display 3-D graphics incorrectly

3dbetweendifferenceMATLABopenglpainterspatchrendererzbuffer

Why does the Painter's renderer in MATLAB display 3-D graphics incorrectly?
In my figure, a lot of intersections and hidden faces and lines seem to be showing up incorrectly, are not being hidden properly or are hidden when they should be showing. These inconsistencies do not occur with Z-Buffer; does the Painter's renderer have a bug?

Best Answer

This is not due to a bug in MATLAB but rather to a limitation in the Painter's algorithm itself. The Painter's algorithm is so named because of how it works: objects are painted on the screen in much the same way as a simple painter could. Whole polygons are painted at once and cannot be painted in parts or pixel by pixel, as other methods of rendering work.
Z-Buffer takes the polygons and splits them into pixels. It then sorts the pixels based on how far they are from the screen. Therefore, it is always correct, but it can be slower. Please note that Z-Buffer is no longer available in MATLAB R2014b and newer versions. More information concerning this can be found at the following link:
Here is an animated example showing how the painters renderer fails. Try to imagine attempting to paint the stacked beams with just four paint strokes, being unable to just paint the visible parts of the beam. This will help explain the limitations of this renderer:
clc;
clear all;
close all;
% specify the vertices of the beams
vert = [ 0, 0, 0; % beam 1
1, 0, 0;
1, 6, 1;
0, 6, 1;
0, 0, 1; % beam 2
0, 1, 1;
6, 1, 0;
6, 0, 0;
5, 0, 1; % beam 3
6, 0, 1;
6, 6, 0;
5, 6, 0;
6, 5, 1; % beam 4
6, 6, 1;
0, 6, 0;
0, 5, 0 ];
% specify the faces of the beams by listing the vertices
surf1 = [ 1 2 3 4;
5 6 7 8;
9 10 11 12;
13 14 15 16 ];
f = figure;
set(f,'doublebuffer','on');
set(f,'menubar','none');
set(f,'name','Comparison of Painters, ZBuffer, and Open GL Rendering Modes');
set(f,'renderermode','man');
patch('Faces',surf1,...
'Vertices',vert,...
'FaceColor','red',...
'EdgeColor','black');
axis equal;
xlabel('X');
ylabel('Y');
zlabel('Z');
view( 3 );
grid on;
set(f,'renderer','painters');
title('Painters Renderer');
for i=1:25
view(-45,45 - i );
pause( 0.1 );
end;
for i=1:25
view(-45,20 + i );
pause( 0.1 );
end;
pause( 2 );
set(f,'renderer','zbuffer');
title('Zbuffer Renderer');
pause( 2 );
set(f,'renderer','opengl');
title('OpenGL Renderer');
pause( 2 );
set(f,'renderer','painters');
title('Painters Renderer');
Here is some generalized information on each of the three renderers:
Painter's
- Draws figures using vector graphics
- Generally produces higher resolution results
- The fastest renderer when the figure contains only simple or small graphics objects
- The only renderer possible when printing with the HPGL print driver or exporting to an Adobe Illustrator file
- The best renderer for creating PostScript or EPS files
- Cannot render figures that use RGB color for patch or surface objects
- Does not show lighting or transparency
Z-buffer
- Draws figures using bitmap (raster) graphics
- Faster and more accurate than painters
- Can consume a lot of system memory if MATLAB is displaying a complex scene
- Shows lighting, but not transparency
OpenGL
- Draws figures using bitmap (raster) graphics
- Generally faster than painters or Zbuffer
- In some cases, enables MATLAB to access graphics hardware that is available on some systems
- Shows both lighting and transparency