Why does the 'shading interp' function produce different results depending on the selected renderer?

1 view (last 30 days)
Using the following code, I get different results depending on which renderer I use.
figure;
pcolor(peaks(10));
shading interp;
set(gcf,'renderer','opengl');
title('OpenGL renderer');
figure;
pcolor(peaks(10));
shading interp;
set(gcf,'renderer','painters');
title('Painters renderer');
I would like to know why I get different results for the same dataset.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Feb 2023
Edited: MathWorks Support Team on 16 Apr 2023
The differences in the figure is because the algorithm used by the different renderers is not the same. The OpenGL renderer does the colormap lookup at each vertex and performs the interpolation in RGB space. The Painters renderer does the interpolation on the raw data and then converts the interpolated data to RGB space.
In the example code, the difference is clearly visible if the colormap is set as follows
colormap flag
To get consistent results on different computers and when exporting the figures, it is a good practice to specify the renderer explicitly rather than let MATLAB choose the renderer. Use the following syntax to specify the figure renderer for the current figure:
set(gcf,'renderer','opengl')
Please note that choosing Painters over OpenGL involves tradeoffs, as mentioned in Solution # 1-16VZI located at the following URL:

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!