Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

Why does the Painter's renderer in MATLAB display 3-D graphics incorrectly?


Date Last Modified: Monday, December 14, 2009
Solution ID:   1-1B33H
Product:   MATLAB
Reported in Release:   R13
Platform:   All Platforms
Operating System:   All OS
 

Subject:

Why does the Painter's renderer in MATLAB display 3-D graphics incorrectly?

Problem Description:

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?

Solution:

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 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.

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 infomation 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

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page