SlideShare a Scribd company logo
1 of 11
Download to read offline
3D Texture Volume
Rendering
Real-time (delay < 0.5 sec) volume rendering
Zhen-Yu Liu 5/19/15 Scientific Visualization
OVERVIEW
Thank to advance of graphic card, we can put a volume data into graphic memory as a 3D texture, and visualize result
by slice the 3D texture using given texture coordinate. Just like 2D texture, we can retrieval the data value between non-
continues data points by interpolation done by graphic hardware, and use this information to draw the pixel. Because most
mass computation (interpolation) is done by hardware, it can speed up the rendering process almost 100 times compare to
splatting method, and create even smoother image (reconstruct using volume itself not kernel function).
3D TEXTURE CREATION
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, SHA_UPBO_TEXTURE3D_R32F_VolumeData);
glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLfloat) * volume_size,
CORE_TEX_3D0x1000000R32F_VolumeData, GL_STATIC_DRAW);
glBindTexture(GL_TEXTURE_3D, SHA_TEX_TEXTURE3D_R32F_VolumeData);
glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, resolution[0], resolution[1], resolution[2], 0, GL_RED, GL_FLOAT, NULL);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, vmath::vec4(0.0,0.0,0.0,0.0));
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
SLICE METHOD
We can using a billboard “slice” the billboard from:
“center – max” to “center + max”
Where center is center of data, max is distance from center to edge along the w vector of view matrix;
The center of billboard is:
[center.x + w.x*d, center.y + w.y*d, center.z + w.z*d]
Where “d” is d’s slice
And compute the coordinate of 4 points of billboard using matrix:
mat4 billboardTran = mat4(
ViewMat[0].x, ViewMat[1].x, ViewMat[2].x, 0,
ViewMat[0].y, ViewMat[1].y, ViewMat[2].y, 0,
ViewMat[0].z, ViewMat[1].z, ViewMat[2].z, 0,
Billboard_center.x, Billboard_center.y, Billboard_center.z, 1);
vec4 realVrt = (billboardTran * Vrt);
The texture coordinate (of 3D texture) then can be compute as follow:
TexCoor = vec3(
realVrt.x/VoxelRes.x,
realVrt.y/VoxelRes.y,
realVrt.z/VoxelRes.z);
VoxelRes is resolution of 3D texture.
The projection space of billboard is:
gl_Position = ProjectionMat * (ViewMat * realVrt);
FRAGMENT
When 3D texture coordinate pass to fragment shader it can outside 0~1. If so, discard rendering of this pixel.
if(
TexCoor.x >= 0 && TexCoor.x <= 1.0 &&
TexCoor.y >= 0 && TexCoor.y <= 1.0 &&
TexCoor.z >= 0 && TexCoor.z <= 1.0
){
// Rendering …
}else{
discard;
}
To do the blending you need a buffer store the previous color of this pixel, and compute the blending equation then store the
result back to the buffer, output the result when final slice been compute.
vec4 ImageColor = ImageBufferColor[ImageBufferId];
vec4 SrcColor = vec4(
MapColor.r*MapColor.a,
MapColor.g*MapColor.a,
MapColor.b*MapColor.a,
MapColor.a);
vec4 DstColor = vec4(
ImageColor.r*(1-SrcColor.a),
ImageColor.g*(1-SrcColor.a),
ImageColor.b*(1-SrcColor.a),
ImageColor.a*(1-SrcColor.a));
ImageBufferColor[ImageBufferId] = SrcColor + DstColor;
fargColor = SrcColor + DstColor;
ImageBufferId can compute using gl_FragCoord the pixel location on screen. And ImageBufferColor is buffer store at most
2000x2000 pixel.
int ImageBufferId = int(gl_FragCoord.x)+2000*int(gl_FragCoord.y);
the volume data can retrieval using:
vec4 VolumeFetch = texture(VolumeData, TexCoor);
FRONT-BACK BACK-FRONT
Between front-back and back-front will make result total different:
Front-back: Back-front:
There are different, but hard to know which is right, to decide the order of drawing it invoke how you implement the blending
equation and w-vector, if you using [src alpha,1-src alpha] for your blending equation, and w-vector is come from view matrix
(eye-center), the back to front slicing order may be the correct one.
SLICE SIMPLE RATE
The different of slice rate will create different density of stripe on the image. Higher simple rate make more stripe thus look
more continue.
Sample rate = max_of_res: Sample rate = max_of_res x 2:
COMPARE
As you can see, 3D texture method create more smooth result.
And also faster rendering.
3D texture: Splatting:
3D texture: Splatting:
PICTURE-ENGINE
PICTURE-ENGINE
PICTURE-ENGINE
PICTURE-ENGINE
VERTEX SHADER
#version 430 core
uniform ivec3 VoxelRes;
uniform mat4 ViewMat;
uniform mat4 ProjectionMat;
uniform float slide;
in vec4 Vrt;
out vec3 TexCoor;
void main()
{
vec3 center = vec3(
VoxelRes.x/2 + slide*ViewMat[0].z,
VoxelRes.y/2 + slide*ViewMat[1].z,
VoxelRes.z/2 + slide*ViewMat[2].z);
mat4 billboardTran = mat4(
ViewMat[0].x, ViewMat[1].x, ViewMat[2].x, 0,
ViewMat[0].y, ViewMat[1].y, ViewMat[2].y, 0,
ViewMat[0].z, ViewMat[1].z, ViewMat[2].z, 0,
center.x, center.y, center.z, 1);
vec4 realVrt = (billboardTran * Vrt);
TexCoor = vec3(
realVrt.x/VoxelRes.x,
realVrt.y/VoxelRes.y,
realVrt.z/VoxelRes.z);
gl_Position = ProjectionMat * (ViewMat * realVrt);
}
FRAGMENT SHADER
#version 430 core
uniform sampler3D VolumeData;
uniform sampler1D ColorMap;
layout (std430, binding=2) buffer ImageBuffer
{
vec4 ImageBufferColor[];
};
uniform float colorDiv;
in vec3 TexCoor;
out vec4 fargColor;
void main()
{
if(
TexCoor.x >= 0 && TexCoor.x <= 1.0 &&
TexCoor.y >= 0 && TexCoor.y <= 1.0 &&
TexCoor.z >= 0 && TexCoor.z <= 1.0
){
vec4 VolumeFetch = texture(VolumeData, TexCoor);
float data = VolumeFetch.r;
vec4 MapColor = texture(ColorMap, data/(colorDiv*0x2710));
if (MapColor.a > 0.0){
int ImageBufferId =
int(gl_FragCoord.x)+2000*int(gl_FragCoord.y);
vec4 ImageColor = ImageBufferColor[ImageBufferId];
vec4 SrcColor = vec4(
MapColor.r*MapColor.a,
MapColor.g*MapColor.a,
MapColor.b*MapColor.a,
MapColor.a);
vec4 DstColor = vec4(
ImageColor.r*(1-SrcColor.a),
ImageColor.g*(1-SrcColor.a),
ImageColor.b*(1-SrcColor.a),
ImageColor.a*(1-SrcColor.a));
ImageBufferColor[ImageBufferId] = SrcColor + DstColor;
fargColor = SrcColor + DstColor;
}else{
discard;
}
}else{
discard;
}
}

More Related Content

What's hot

IIR filter realization using direct form I & II
IIR filter realization using direct form I & IIIIR filter realization using direct form I & II
IIR filter realization using direct form I & IISarang Joshi
 
DPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture MappingDPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture MappingMrLawler
 
Zooming an image in visual basic
Zooming an image in visual basicZooming an image in visual basic
Zooming an image in visual basicHotland Sitorus
 
Opengl texturing
Opengl texturingOpengl texturing
Opengl texturingSardar Alam
 
Texture mapping overview
Texture mapping overviewTexture mapping overview
Texture mapping overviewJ Le Rossignol
 
Geometry Batching Using Texture-Arrays
Geometry Batching Using Texture-ArraysGeometry Batching Using Texture-Arrays
Geometry Batching Using Texture-ArraysMatthias Trapp
 
A NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLE
A NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLEA NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLE
A NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLEsatya kishore
 
Circular Convolution
Circular ConvolutionCircular Convolution
Circular ConvolutionSarang Joshi
 
2.5D Clip-Surfaces for Technical Visualization
2.5D Clip-Surfaces for Technical Visualization2.5D Clip-Surfaces for Technical Visualization
2.5D Clip-Surfaces for Technical VisualizationMatthias Trapp
 
Rendering of Complex 3D Treemaps (GRAPP 2013)
Rendering of Complex 3D Treemaps (GRAPP 2013)Rendering of Complex 3D Treemaps (GRAPP 2013)
Rendering of Complex 3D Treemaps (GRAPP 2013)Matthias Trapp
 
Cascades Demo Secrets
Cascades Demo SecretsCascades Demo Secrets
Cascades Demo Secretsicastano
 
Computer Graphics Modellering engels
Computer Graphics Modellering engelsComputer Graphics Modellering engels
Computer Graphics Modellering engelsChristian Kehl
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Interactive Rendering and Stylization of Transportation Networks Using Distan...
Interactive Rendering and Stylization of Transportation Networks Using Distan...Interactive Rendering and Stylization of Transportation Networks Using Distan...
Interactive Rendering and Stylization of Transportation Networks Using Distan...Matthias Trapp
 
The reversible residual network
The reversible residual networkThe reversible residual network
The reversible residual networkThyrixYang1
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewingMohd Arif
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksJinTaek Seo
 
2018 06-19 paris cybersecurity meetup
2018 06-19 paris cybersecurity meetup2018 06-19 paris cybersecurity meetup
2018 06-19 paris cybersecurity meetupRaphaël Laffitte
 

What's hot (20)

IIR filter realization using direct form I & II
IIR filter realization using direct form I & IIIIR filter realization using direct form I & II
IIR filter realization using direct form I & II
 
DPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture MappingDPI 1 and DPI 2 Texture Mapping
DPI 1 and DPI 2 Texture Mapping
 
Resize image vb.net
Resize image vb.netResize image vb.net
Resize image vb.net
 
Zooming an image in visual basic
Zooming an image in visual basicZooming an image in visual basic
Zooming an image in visual basic
 
Opengl texturing
Opengl texturingOpengl texturing
Opengl texturing
 
Texture mapping overview
Texture mapping overviewTexture mapping overview
Texture mapping overview
 
Geometry Batching Using Texture-Arrays
Geometry Batching Using Texture-ArraysGeometry Batching Using Texture-Arrays
Geometry Batching Using Texture-Arrays
 
A NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLE
A NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLEA NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLE
A NOVEL IMAGE SCRAMBLING BASED ON SUDOKU PUZZLE
 
Computer Organisation Part 3
Computer Organisation Part 3Computer Organisation Part 3
Computer Organisation Part 3
 
Circular Convolution
Circular ConvolutionCircular Convolution
Circular Convolution
 
2.5D Clip-Surfaces for Technical Visualization
2.5D Clip-Surfaces for Technical Visualization2.5D Clip-Surfaces for Technical Visualization
2.5D Clip-Surfaces for Technical Visualization
 
Rendering of Complex 3D Treemaps (GRAPP 2013)
Rendering of Complex 3D Treemaps (GRAPP 2013)Rendering of Complex 3D Treemaps (GRAPP 2013)
Rendering of Complex 3D Treemaps (GRAPP 2013)
 
Cascades Demo Secrets
Cascades Demo SecretsCascades Demo Secrets
Cascades Demo Secrets
 
Computer Graphics Modellering engels
Computer Graphics Modellering engelsComputer Graphics Modellering engels
Computer Graphics Modellering engels
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Interactive Rendering and Stylization of Transportation Networks Using Distan...
Interactive Rendering and Stylization of Transportation Networks Using Distan...Interactive Rendering and Stylization of Transportation Networks Using Distan...
Interactive Rendering and Stylization of Transportation Networks Using Distan...
 
The reversible residual network
The reversible residual networkThe reversible residual network
The reversible residual network
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
2018 06-19 paris cybersecurity meetup
2018 06-19 paris cybersecurity meetup2018 06-19 paris cybersecurity meetup
2018 06-19 paris cybersecurity meetup
 

Similar to 3Dtexture_doc_rep

Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksBeginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksJinTaek Seo
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture MappingMark Kilgard
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupMark Kilgard
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerJanie Clayton
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksJinTaek Seo
 
I need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfI need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfConint29
 
maXbox starter68 machine learning VI
maXbox starter68 machine learning VImaXbox starter68 machine learning VI
maXbox starter68 machine learning VIMax Kleiner
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2Sardar Alam
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014Jarosław Pleskot
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Takao Wada
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APITomi Aarnio
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptxssuser255bf1
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfcontact41
 
Signature recognition using clustering techniques dissertati
Signature recognition using clustering techniques dissertatiSignature recognition using clustering techniques dissertati
Signature recognition using clustering techniques dissertatiDr. Vinayak Bharadi
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf AtlantaJanie Clayton
 

Similar to 3Dtexture_doc_rep (20)

Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksBeginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
 
paper
paperpaper
paper
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
 
A0280105
A0280105A0280105
A0280105
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
Scmad Chapter06
Scmad Chapter06Scmad Chapter06
Scmad Chapter06
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
I need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdfI need help with this assignment Ive gotten abit stuck with the cod.pdf
I need help with this assignment Ive gotten abit stuck with the cod.pdf
 
maXbox starter68 machine learning VI
maXbox starter68 machine learning VImaXbox starter68 machine learning VI
maXbox starter68 machine learning VI
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014
 
K10765 Matlab 3D Mesh Plots
K10765 Matlab 3D Mesh PlotsK10765 Matlab 3D Mesh Plots
K10765 Matlab 3D Mesh Plots
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
Signature recognition using clustering techniques dissertati
Signature recognition using clustering techniques dissertatiSignature recognition using clustering techniques dissertati
Signature recognition using clustering techniques dissertati
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 

3Dtexture_doc_rep

  • 1. 3D Texture Volume Rendering Real-time (delay < 0.5 sec) volume rendering Zhen-Yu Liu 5/19/15 Scientific Visualization
  • 2. OVERVIEW Thank to advance of graphic card, we can put a volume data into graphic memory as a 3D texture, and visualize result by slice the 3D texture using given texture coordinate. Just like 2D texture, we can retrieval the data value between non- continues data points by interpolation done by graphic hardware, and use this information to draw the pixel. Because most mass computation (interpolation) is done by hardware, it can speed up the rendering process almost 100 times compare to splatting method, and create even smoother image (reconstruct using volume itself not kernel function). 3D TEXTURE CREATION glBindBuffer(GL_PIXEL_UNPACK_BUFFER, SHA_UPBO_TEXTURE3D_R32F_VolumeData); glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(GLfloat) * volume_size, CORE_TEX_3D0x1000000R32F_VolumeData, GL_STATIC_DRAW); glBindTexture(GL_TEXTURE_3D, SHA_TEX_TEXTURE3D_R32F_VolumeData); glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, resolution[0], resolution[1], resolution[2], 0, GL_RED, GL_FLOAT, NULL); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); glTexParameterfv(GL_TEXTURE_3D, GL_TEXTURE_BORDER_COLOR, vmath::vec4(0.0,0.0,0.0,0.0)); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); SLICE METHOD We can using a billboard “slice” the billboard from: “center – max” to “center + max” Where center is center of data, max is distance from center to edge along the w vector of view matrix; The center of billboard is: [center.x + w.x*d, center.y + w.y*d, center.z + w.z*d] Where “d” is d’s slice And compute the coordinate of 4 points of billboard using matrix: mat4 billboardTran = mat4( ViewMat[0].x, ViewMat[1].x, ViewMat[2].x, 0, ViewMat[0].y, ViewMat[1].y, ViewMat[2].y, 0, ViewMat[0].z, ViewMat[1].z, ViewMat[2].z, 0, Billboard_center.x, Billboard_center.y, Billboard_center.z, 1); vec4 realVrt = (billboardTran * Vrt); The texture coordinate (of 3D texture) then can be compute as follow: TexCoor = vec3( realVrt.x/VoxelRes.x, realVrt.y/VoxelRes.y, realVrt.z/VoxelRes.z); VoxelRes is resolution of 3D texture. The projection space of billboard is: gl_Position = ProjectionMat * (ViewMat * realVrt);
  • 3. FRAGMENT When 3D texture coordinate pass to fragment shader it can outside 0~1. If so, discard rendering of this pixel. if( TexCoor.x >= 0 && TexCoor.x <= 1.0 && TexCoor.y >= 0 && TexCoor.y <= 1.0 && TexCoor.z >= 0 && TexCoor.z <= 1.0 ){ // Rendering … }else{ discard; } To do the blending you need a buffer store the previous color of this pixel, and compute the blending equation then store the result back to the buffer, output the result when final slice been compute. vec4 ImageColor = ImageBufferColor[ImageBufferId]; vec4 SrcColor = vec4( MapColor.r*MapColor.a, MapColor.g*MapColor.a, MapColor.b*MapColor.a, MapColor.a); vec4 DstColor = vec4( ImageColor.r*(1-SrcColor.a), ImageColor.g*(1-SrcColor.a), ImageColor.b*(1-SrcColor.a), ImageColor.a*(1-SrcColor.a)); ImageBufferColor[ImageBufferId] = SrcColor + DstColor; fargColor = SrcColor + DstColor; ImageBufferId can compute using gl_FragCoord the pixel location on screen. And ImageBufferColor is buffer store at most 2000x2000 pixel. int ImageBufferId = int(gl_FragCoord.x)+2000*int(gl_FragCoord.y); the volume data can retrieval using: vec4 VolumeFetch = texture(VolumeData, TexCoor);
  • 4. FRONT-BACK BACK-FRONT Between front-back and back-front will make result total different: Front-back: Back-front: There are different, but hard to know which is right, to decide the order of drawing it invoke how you implement the blending equation and w-vector, if you using [src alpha,1-src alpha] for your blending equation, and w-vector is come from view matrix (eye-center), the back to front slicing order may be the correct one. SLICE SIMPLE RATE The different of slice rate will create different density of stripe on the image. Higher simple rate make more stripe thus look more continue. Sample rate = max_of_res: Sample rate = max_of_res x 2:
  • 5. COMPARE As you can see, 3D texture method create more smooth result. And also faster rendering. 3D texture: Splatting: 3D texture: Splatting:
  • 10. VERTEX SHADER #version 430 core uniform ivec3 VoxelRes; uniform mat4 ViewMat; uniform mat4 ProjectionMat; uniform float slide; in vec4 Vrt; out vec3 TexCoor; void main() { vec3 center = vec3( VoxelRes.x/2 + slide*ViewMat[0].z, VoxelRes.y/2 + slide*ViewMat[1].z, VoxelRes.z/2 + slide*ViewMat[2].z); mat4 billboardTran = mat4( ViewMat[0].x, ViewMat[1].x, ViewMat[2].x, 0, ViewMat[0].y, ViewMat[1].y, ViewMat[2].y, 0, ViewMat[0].z, ViewMat[1].z, ViewMat[2].z, 0, center.x, center.y, center.z, 1); vec4 realVrt = (billboardTran * Vrt); TexCoor = vec3( realVrt.x/VoxelRes.x, realVrt.y/VoxelRes.y, realVrt.z/VoxelRes.z); gl_Position = ProjectionMat * (ViewMat * realVrt); }
  • 11. FRAGMENT SHADER #version 430 core uniform sampler3D VolumeData; uniform sampler1D ColorMap; layout (std430, binding=2) buffer ImageBuffer { vec4 ImageBufferColor[]; }; uniform float colorDiv; in vec3 TexCoor; out vec4 fargColor; void main() { if( TexCoor.x >= 0 && TexCoor.x <= 1.0 && TexCoor.y >= 0 && TexCoor.y <= 1.0 && TexCoor.z >= 0 && TexCoor.z <= 1.0 ){ vec4 VolumeFetch = texture(VolumeData, TexCoor); float data = VolumeFetch.r; vec4 MapColor = texture(ColorMap, data/(colorDiv*0x2710)); if (MapColor.a > 0.0){ int ImageBufferId = int(gl_FragCoord.x)+2000*int(gl_FragCoord.y); vec4 ImageColor = ImageBufferColor[ImageBufferId]; vec4 SrcColor = vec4( MapColor.r*MapColor.a, MapColor.g*MapColor.a, MapColor.b*MapColor.a, MapColor.a); vec4 DstColor = vec4( ImageColor.r*(1-SrcColor.a), ImageColor.g*(1-SrcColor.a), ImageColor.b*(1-SrcColor.a), ImageColor.a*(1-SrcColor.a)); ImageBufferColor[ImageBufferId] = SrcColor + DstColor; fargColor = SrcColor + DstColor; }else{ discard; } }else{ discard; } }