Matlab OpenGL 3D rendering

조회 수: 15 (최근 30일)
Sébastien Tosi
Sébastien Tosi 2016년 5월 19일
답변: Vivek Jadye 2016년 6월 8일
I'm trying to understand how Matlab loads texture to GPU (low level) when adding images to OpenGL rendered plots. I'm thinking of stacking 2D images with some transparency to get some sort of interactive alpha blended 3D rendering. This is essentially what popular scripts such as Vol3D v2 (MatlabExchange) are doing, at least in 2D texture mode. I'm looking for a way to minimize GPU memory usage when rendering rather large 3D image stacks with this technique. What format is used internally to load the images as texture on the GPU (conversion from Matlab double to some fixed point format?). Is this approach very unefficient as compared to writing a dedicated mex file that would perform it in pure OpenGL, or should it be reasonably efficient? Here I'm not so concerned by rendering quality, rather speed and memory footprint. Also I would like to implement some advanced features such as overlaying ROIs (possibly as transparent surfaces) and being able to point click them... anybody explored this?
  댓글 수: 2
Vivek Jadye
Vivek Jadye 2016년 6월 7일
Hi Sebastien,
MATLAB converts textures to an intermediate format (RGBA of unsigned char) before uploading them to the GPU. If you use uint8 arrays in MATLAB there should be no overhead. However, because you are trying to overlay transparent textures, the overhead will be due to the way MATLAB API accepts color and alpha data through separate channels.
Here is example code snippet that does similar stacking of textures. Note that I use surface object because it provides an easy interface to create texturemapped quadrilateral.
for i = 1 : 10,
%create a surface with
%color data as uint8 m*n*3 texture
%alphadata as uint8 m*n*1 array
s = surface(1:2,1:2,i*ones(2),...
'EdgeColor','none',...
'FaceColor','texturemap',...
'CData',uint8(255*rand(10,10,3)),...
'FaceAlpha','texturemap',...
'AlphaData',uint8(255*rand(10,10,1)));
end
This could be a good starting point for you.
Also, MATLAB uses deferred rendering for resolving transparency in the scene. If you only wish to render these textures in a certain order, you need to set SortMethod property on the axes. Please refer to Axes sortmethod property for more information.
Does that answer your query?
Walter Roberson
Walter Roberson 2016년 6월 8일
Vivek, you should post that as an Answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Vivek Jadye
Vivek Jadye 2016년 6월 8일
Copying my comment into the answer section.
MATLAB converts textures to an intermediate format (RGBA of unsigned char) before uploading them to the GPU. If you use uint8 arrays in MATLAB there should be no overhead. However, because you are trying to overlay transparent textures, the overhead will be due to the way MATLAB API accepts color and alpha data through separate channels.
Here is example code snippet that does similar stacking of textures. Note that I use surface object because it provides an easy interface to create texturemapped quadrilateral.
for i = 1 : 10,
%create a surface with
%color data as uint8 m*n*3 texture
%alphadata as uint8 m*n*1 array
s = surface(1:2,1:2,i*ones(2),...
'EdgeColor','none',...
'FaceColor','texturemap',...
'CData',uint8(255*rand(10,10,3)),...
'FaceAlpha','texturemap',...
'AlphaData',uint8(255*rand(10,10,1)));
end
This could be a good starting point for you.
Also, MATLAB uses deferred rendering for resolving transparency in the scene. If you only wish to render these textures in a certain order, you need to set SortMethod property on the axes. Please refer to Axes sortmethod property for more information.

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by