45#ifndef CShaderBasicVoxelRGBA8
46#define CShaderBasicVoxelRGBA8
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 float uResolution; \n"
85" uniform float uOpacity; \n"
87" varying vec4 vPosition; \n"
90" //---------------------------------------------------------------------- \n"
91" // Finds the entering intersection between a ray e1+d and the volume's \n"
93" //---------------------------------------------------------------------- \n"
95" float entry(vec3 e1, vec3 d) \n"
97" float t = distance(uMinCorner, uMaxCorner); \n"
99" vec3 a = (uMinCorner - e1) / d; \n"
100" vec3 b = (uMaxCorner - e1) / d; \n"
101" vec3 u = min(a, b); \n"
103" return max( max(-t, u.x), max(u.y, u.z) ); \n"
107" //---------------------------------------------------------------------- \n"
108" // Performs interval bisection and returns the value between a and b \n"
109" // closest to isosurface. When s(b) > s(a), direction should be +1.0, \n"
110" // and -1.0 otherwise. \n"
111" //---------------------------------------------------------------------- \n"
113" vec3 refine(vec3 a, vec3 b, float direction) \n"
115" for (int i = 0; i < 6; ++i) \n"
117" vec3 m = 0.5 * (a + b); \n"
118" float v = texture3D(uVolume, m).a * direction; \n"
119" if (v >= 0.0) b = m; \n"
126" //---------------------------------------------------------------------- \n"
127" // Main fragment shader code. \n"
128" //---------------------------------------------------------------------- \n"
132" vec4 camera = gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0); \n"
133" vec3 raydir = normalize(vPosition.xyz - camera.xyz); \n"
135" float t_entry = entry(vPosition.xyz, raydir); \n"
136" t_entry = max(t_entry, -distance(camera.xyz, vPosition.xyz)); \n"
138" // estimate a reasonable step size \n"
139" float t_step = distance(uMinCorner, uMaxCorner) / uResolution; \n"
140" vec3 tc_step = uTextureScale * (t_step * raydir); \n"
142" float sigma = 100.0 * uOpacity; \n"
143" if (uOpacity == 1.0) \n"
148" // cast the ray (in model space) \n"
149" vec4 sum = vec4(0.0); \n"
150" vec3 tc = gl_TexCoord[0].stp + t_entry * tc_step / t_step; \n"
151" bool flag = true; \n"
152" for (float t = t_entry; t < 0.0; t += t_step, tc += tc_step) \n"
154" vec4 colour = texture3D(uVolume, tc); \n"
155" float intensity = colour.a; \n"
157" float Tr = exp(-sigma * t_step); \n"
158" colour *= 1.0 - Tr; \n"
162" if (intensity > 0.0) \n"
164" vec3 tcr = refine(tc - tc_step, tc, 1.0); \n"
166" float dt = length(tcr - tc) / length(tc_step); \n"
167" vec3 position = vPosition.xyz + (t - dt * t_step) * raydir; \n"
168" vec4 clip = gl_ModelViewProjectionMatrix * vec4(position, 1.0); \n"
169" gl_FragDepth = (gl_DepthRange.diff * clip.z/clip.w + gl_DepthRange.near + gl_DepthRange.far) * 0.5; \n"
173" if (intensity > 0.0) \n"
175" sum += (1.0 - sum.a) * colour; \n"
179" // discard the fragment if no geometry was intersected \n"
180" if (sum.a <= 0.0) discard; \n"
182" gl_FragColor = sum; \n"
Implements option settings for CHAI3D.
Definition CAudioBuffer.cpp:57
const std::string C_SHADER_BASIC_VOXEL_RGBA8_FRAG
Definition CShaderBasicVoxel-RGBA8.h:78
const std::string C_SHADER_BASIC_VOXEL_RGBA8_VERT
Definition CShaderBasicVoxel-RGBA8.h:55