@@ -80,6 +80,8 @@ vec3 ShadeBlinnPhong (vec3 Tpos, vec3 clr)
8080 return clr;
8181}
8282
83+ //#define USE_TRANSPARENCY
84+ //#define USE_TRANSPARENCY_DS
8385void main ()
8486{
8587 ivec2 storePos = ivec2(gl_GlobalInvocationID.xy);
@@ -107,7 +109,11 @@ void main ()
107109 float D = abs(tfar - tnear);
108110
109111 // Initialize Transparency and Radiance color
112+ #ifdef USE_TRANSPARENCY
113+ vec4 dst = vec4(vec3(0.0),1.0);
114+ #else
110115 vec4 dst = vec4(0.0);
116+ #endif
111117
112118 // World position at tnear, translated to the volume [0, VolumeGridSize]
113119 vec3 wld_pos = r.Origin + r.Dir * tnear;
@@ -139,6 +145,17 @@ void main ()
139145 if(ApplyGradientPhongShading == 1)
140146 src.rgb = ShadeBlinnPhong(s_tex_pos, src.rgb);
141147
148+ #ifdef USE_TRANSPARENCY
149+ #ifdef USE_TRANSPARENCY_DS
150+ dst.rgb = dst.rgb + dst.a * src.a * src.rgb * h;
151+ dst.a = dst.a * exp(-src.a * h);
152+ #else
153+ float F = exp(-src.a * h);
154+ dst.rgb = dst.rgb + dst.a * src.rgb * (1.0 - F);
155+ dst.a = dst.a * F;
156+ #endif
157+ if ((1.0 - dst.a) > 0.99) break;
158+ #else
142159 // Evaluate the current opacity
143160 src.a = 1.0 - exp(-src.a * h);
144161
@@ -148,10 +165,14 @@ void main ()
148165
149166 // Opacity threshold: 99%
150167 if (dst.a > 0.99) break;
168+ #endif
151169 }
152170 // Go to the next interval
153171 s = s + h;
154172 }
173+ #ifdef USE_TRANSPARENCY
174+ dst.a = 1.0 - dst.a;
175+ #endif
155176 imageStore(OutputFrag, storePos, dst);
156177 }
157178 }
0 commit comments