Matlab OpenGL 3D rendering
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Vivek Jadye
il 7 Giu 2016
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?
Risposte (1)
Vivek Jadye
il 8 Giu 2016
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Lighting, Transparency, and Shading in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!