45#ifndef CShaderBasicVoxelLUT8
46#define CShaderBasicVoxelLUT8
57" attribute vec3 aPosition; \n"
58" attribute vec3 aNormal; \n"
59" attribute vec3 aTexCoord; \n"
60" attribute vec4 aColor; \n"
61" attribute vec3 aTangent; \n"
62" attribute vec3 aBitangent; \n"
64" varying vec4 vPosition; \n"
66" //---------------------------------------------------------------------- \n"
67" // Main vertex shader code. \n"
68" //---------------------------------------------------------------------- \n"
72" gl_TexCoord[0] = gl_TextureMatrix[0] * vec4(aTexCoord, 1.0); \n"
73" vPosition = gl_Vertex; \n"
74" gl_Position = ftransform(); \n"
80" uniform vec3 uMinCorner; \n"
81" uniform vec3 uMaxCorner; \n"
82" uniform vec3 uTextureScale; \n"
83" uniform sampler3D uVolume; \n"
84" uniform sampler1D uColorLUT; \n"
85" uniform float uResolution; \n"
86" uniform float uOpacity; \n"
88" varying vec4 vPosition; \n"
91" //---------------------------------------------------------------------- \n"
92" // Finds the entering intersection between a ray e1+d and the volume's \n"
94" //---------------------------------------------------------------------- \n"
96" float entry(vec3 e1, vec3 d) \n"
98" float t = distance(uMinCorner, uMaxCorner); \n"
100" vec3 a = (uMinCorner - e1) / d; \n"
101" vec3 b = (uMaxCorner - e1) / d; \n"
102" vec3 u = min(a, b); \n"
104" return max( max(-t, u.x), max(u.y, u.z) ); \n"
108" //---------------------------------------------------------------------- \n"
109" // Performs interval bisection and returns the value between a and b \n"
110" // closest to isosurface. When s(b) > s(a), direction should be +1.0, \n"
111" // and -1.0 otherwise. \n"
112" //---------------------------------------------------------------------- \n"
114" vec3 refine(vec3 a, vec3 b, float direction) \n"
116" for (int i = 0; i < 6; ++i) \n"
118" vec3 m = 0.5 * (a + b); \n"
119" float v = texture3D(uVolume, m).a * direction; \n"
120" if (v >= 0.0) b = m; \n"
127" //---------------------------------------------------------------------- \n"
128" // Main fragment shader code. \n"
129" //---------------------------------------------------------------------- \n"
133" vec4 camera = gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0); \n"
134" vec3 raydir = normalize(vPosition.xyz - camera.xyz); \n"
136" float t_entry = entry(vPosition.xyz, raydir); \n"
137" t_entry = max(t_entry, -distance(camera.xyz, vPosition.xyz)); \n"
139" // estimate a reasonable step size \n"
140" float t_step = distance(uMinCorner, uMaxCorner) / uResolution; \n"
141" vec3 tc_step = uTextureScale * (t_step * raydir); \n"
143" float sigma = 100.0 * uOpacity; \n"
144" if (uOpacity == 1.0) \n"
149" // cast the ray (in model space) \n"
150" vec4 sum = vec4(0.0); \n"
151" vec3 tc = gl_TexCoord[0].stp + t_entry * tc_step / t_step; \n"
152" bool flag = true; \n"
153" for (float t = t_entry; t < 0.0; t += t_step, tc += tc_step) \n"
155" vec4 voxel = texture3D(uVolume, tc); \n"
156" vec4 colour = texture1D(uColorLUT, voxel.r); \n"
158" float Tr = exp(-sigma * t_step); \n"
159" colour *= 1.0 - Tr; \n"
163" if (voxel.r > 0.0) \n"
165" vec3 tcr = refine(tc - tc_step, tc, 1.0); \n"
167" float dt = length(tcr - tc) / length(tc_step); \n"
168" vec3 position = vPosition.xyz + (t - dt * t_step) * raydir; \n"
169" vec4 clip = gl_ModelViewProjectionMatrix * vec4(position, 1.0); \n"
170" gl_FragDepth=(gl_DepthRange.diff * clip.z / clip.w + gl_DepthRange.near + gl_DepthRange.far) * 0.5; \n"
174" if (voxel.r > 0.0) \n"
176" sum += (1.0 - sum.a) * colour; \n"
180" // discard the fragment if no geometry was intersected \n"
181" if (sum.a <= 0.0) discard; \n"
183" gl_FragColor = sum; \n"
Implements option settings for CHAI3D.
Definition CAudioBuffer.cpp:57
const std::string C_SHADER_BASIC_VOXEL_LUT8_FRAG
Definition CShaderBasicVoxel-LUT8.h:78
const std::string C_SHADER_BASIC_VOXEL_LUT8_VERT
Definition CShaderBasicVoxel-LUT8.h:55