Skip to content

Commit 6f52f48

Browse files
committed
Adding dos for texture slicing
1 parent 3946c84 commit 6f52f48

11 files changed

+1500
-3
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ A volume rendering application with different techniques, trying to be as simila
3232
- Cone Shadows
3333

3434
* 1-Pass - Ray Casting - Dir. Occlusion Shading
35-
- Structured Single-pass Ray Casting: Directional Ambient Occlusion and Shadows with Cone Tracing
36-
- Leonardo Q. Campagnolo, Waldemar Celes. Interactive directional ambient occlusion and shadow computations for volume ray casting. Computers & Graphics, Volume 84, 2019, Pages 66-76, ISSN 0097-8493. doi: 10.1016/j.cag.2019.08.009.
37-
- Links: [Elsevier](https://www.sciencedirect.com/science/article/abs/pii/S0097849319301372)
35+
- Structured Single-pass Ray Casting: Directional Ambient Occlusion and Shadows with Cone Tracing
36+
- Leonardo Q. Campagnolo, Waldemar Celes. Interactive directional ambient occlusion and shadow computations for volume ray casting. Computers & Graphics, Volume 84, 2019, Pages 66-76, ISSN 0097-8493. doi: 10.1016/j.cag.2019.08.009.
37+
- Links: [Elsevier](https://www.sciencedirect.com/science/article/abs/pii/S0097849319301372)
38+
39+
* Slice-based - Directional Occlusion
40+
- Structured Slice-based Texture Mapping: Directional Occlusion Shading Model
41+
- Schott, M., Pegoraro, V., Hansen, C., Boulanger, K. and Bouatouch, K. (2009), A Directional Occlusion Shading Model for Interactive Direct Volume Rendering. Computer Graphics Forum, 28: 855-862. doi:10.1111/j.1467-8659.2009.01464.x.
42+
- Links: [ACM](https://dl.acm.org/doi/10.1111/j.1467-8659.2009.01464.x)

cppvolrend/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ add_executable(cppvolrend
4141
structured/rc1pdosct/dosrcrenderer.cpp structured/rc1pdosct/dosrcrenderer.h
4242
structured/rc1pdosct/extcoefvolumegenerator.cpp structured/rc1pdosct/extcoefvolumegenerator.h
4343

44+
# Directional Occlusion Shading for GPU Slice/Texture-based
45+
structured/sbtmdos/sbtmdosrenderer.cpp structured/sbtmdos/sbtmdosrenderer.h
46+
structured/sbtmdos/layeredframebufferobject.cpp structured/sbtmdos/layeredframebufferobject.h
47+
4448
utils/preillumination.cpp utils/preillumination.h
4549

4650
${CMAKE_EXTERNAL_DIRECTORY}/imgui/imconfig.h ${CMAKE_EXTERNAL_DIRECTORY}/imgui/imgui_demo.cpp

cppvolrend/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "structured/rc1pass/rc1prenderer.h"
2424
#include "structured/rc1pcrtgt/crtgtrenderer.h"
2525
#include "structured/rc1pdosct/dosrcrenderer.h"
26+
// Slice based
27+
#include "structured/sbtmdos/sbtmdosrenderer.h"
2628
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
2729

2830
#ifdef USING_FREEGLUT
@@ -56,6 +58,9 @@ int main (int argc, char **argv)
5658
RenderingManager::Instance()->AddVolumeRenderer(new RC1PConeLightGroundTruthSteps());
5759
RenderingManager::Instance()->AddVolumeRenderer(new RC1PConeTracingDirOcclusionShading());
5860
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
61+
// Slice based
62+
RenderingManager::Instance()->AddVolumeRenderer(new SBTMDirectionalOcclusionShading());
63+
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
5964

6065
app.InitImGui();
6166
RenderingManager::Instance()->InitData();
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#version 430 compatibility
2+
3+
layout (location = 0) out vec4 FragColor;
4+
5+
uniform sampler2D EyeBufferSlice;
6+
7+
uniform vec2 ScreenSize;
8+
9+
void main(void)
10+
{
11+
FragColor = texture(EyeBufferSlice, gl_FragCoord.st / ScreenSize);
12+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#version 430
2+
3+
layout(location = 0) in vec3 VerPos;
4+
5+
void main (void)
6+
{
7+
gl_Position = vec4(VerPos, 1.0);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#version 430 compatibility
2+
3+
layout (location = 0) out vec4 EyeBuffer;
4+
layout (location = 1) out vec4 OcclusionBuffer;
5+
6+
in vec3 world_pos;
7+
in vec2 CVector;
8+
in vec4 pos_clip_space;
9+
10+
uniform sampler3D TexVolume;
11+
uniform sampler1D TexTransferFunc;
12+
13+
uniform vec3 VolumeScaledSizes;
14+
15+
uniform float StepSize;
16+
17+
uniform vec2 ScreenSize;
18+
19+
uniform sampler2D EyeBufferPrev;
20+
uniform sampler2D OcclusionBufferPrev;
21+
22+
uniform float OcclusionExtent;
23+
uniform vec2 GridSize;
24+
25+
uniform float VolumeDiagonal;
26+
27+
uniform float UITransparencyScale;
28+
29+
vec4 GetFromTransferFunction (vec3 in_pos)
30+
{
31+
float vol_density = texture(TexVolume, in_pos / VolumeScaledSizes).r;
32+
return texture(TexTransferFunc, vol_density);
33+
}
34+
35+
float Algorithm3 (float st, float slice_distance)
36+
{
37+
//////////////////////////////
38+
// Equation 13
39+
vec2 xy_d = pos_clip_space.xy / pos_clip_space.w;
40+
41+
float s_occlusion = 0.0;
42+
43+
// x of y, they're equal
44+
float x_grid_pos = 0.5;
45+
int xpos_sample = 0;
46+
while(xpos_sample < GridSize.x)
47+
{
48+
float y_grid_pos = 0.5;
49+
int ypos_sample = 0;
50+
while(ypos_sample < GridSize.y)
51+
{
52+
//////////////////////////////
53+
// Generate each sample on an uniform grid an multiply by the current radius to evaluate occlusion
54+
// . center ir 0.0
55+
// ***********
56+
// * X X X *
57+
// * X X X *
58+
// * X X X *
59+
// ***********
60+
vec2 p = ((vec2(x_grid_pos, y_grid_pos) - (GridSize / 2.0f)) / (GridSize / 2.0f)) * OcclusionExtent;
61+
62+
//////////////////////////////
63+
// Equation 14
64+
// must normalize the grid pos to multiply by the radius of the occlusion extent
65+
vec2 p_d = xy_d + CVector * p;
66+
67+
/////////////////////////////////
68+
// Equation 15
69+
vec2 p_t = 0.5 * p_d + vec2(0.5);
70+
71+
float occ_sample = texture(OcclusionBufferPrev, p_t).r;
72+
s_occlusion += occ_sample;
73+
74+
y_grid_pos += 1.0f;
75+
ypos_sample = ypos_sample + 1;
76+
}
77+
x_grid_pos += 1.0f;
78+
xpos_sample = xpos_sample + 1;
79+
}
80+
s_occlusion = (s_occlusion / (GridSize.x * GridSize.y)) * exp(-st * slice_distance * UITransparencyScale);
81+
82+
return s_occlusion;
83+
}
84+
85+
// http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch39.html
86+
void main(void)
87+
{
88+
vec3 aabb = VolumeScaledSizes * 0.5;
89+
if (world_pos.x > aabb.x || world_pos.x < -aabb.x ||
90+
world_pos.y > aabb.y || world_pos.y < -aabb.y ||
91+
world_pos.z > aabb.z || world_pos.z < -aabb.z )
92+
discard;
93+
else
94+
{
95+
vec3 pos_from_zero = world_pos + aabb;
96+
vec4 src = GetFromTransferFunction(pos_from_zero);
97+
98+
float st = src.a;
99+
100+
vec4 dst = texelFetch(EyeBufferPrev, ivec2(gl_FragCoord.st), 0);
101+
102+
float occlusion;
103+
//if (!(dst.a > 0.99))
104+
{
105+
occlusion = texture(OcclusionBufferPrev, (gl_FragCoord.st) / ScreenSize).r;
106+
107+
// Evaluate the current opacity
108+
src.a = 1.0 - exp(-src.a * StepSize);
109+
110+
// Front-to-back composition
111+
src.rgb = src.rgb * occlusion * src.a;
112+
113+
dst = dst + (1.0 - dst.a) * src;
114+
}
115+
occlusion = Algorithm3(st, StepSize);
116+
OcclusionBuffer = vec4(occlusion, 0, 0, 0);
117+
118+
EyeBuffer = dst;
119+
}
120+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#version 430
2+
3+
layout(location = 0) in vec3 VerPos;
4+
5+
out vec3 world_pos;
6+
out vec2 CVector;
7+
out vec4 pos_clip_space;
8+
9+
uniform mat4 ViewMatrix;
10+
uniform mat4 ProjectionMatrix;
11+
12+
uniform vec3 CameraDirection;
13+
uniform float DistanceFromNearSlice;
14+
15+
// https://learnopengl.com/Getting-Started/Coordinate-Systems
16+
// https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space
17+
// http://watkins.cs.queensu.ca/~jstewart/454/notes/454-MVPtransform/
18+
// https://www.khronos.org/opengl/wiki/Vertex_Transformation
19+
// https://www.ntu.edu.sg/home/ehchua/programming/opengl/CG_BasicsTheory.html
20+
void main (void)
21+
{
22+
vec3 vpos = VerPos + CameraDirection * DistanceFromNearSlice;
23+
24+
gl_Position = ProjectionMatrix * ViewMatrix * vec4(vpos, 1.0);
25+
pos_clip_space = gl_Position;
26+
27+
//////////////////////////////
28+
// Equation 12
29+
vec4 viewpos = ViewMatrix * vec4(vpos, 1.0);
30+
vec4 v_scale = ProjectionMatrix * vec4(1, 1, viewpos.z, 1);
31+
CVector = vec2(v_scale.x/v_scale.w, v_scale.y/v_scale.w);
32+
33+
world_pos = vpos;
34+
}

0 commit comments

Comments
 (0)