45 #ifndef CShaderDVRLUT8
46 #define CShaderDVRLUT8
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; // lower bounding corner, model space \n"
81 " uniform vec3 uMaxCorner; // upper bounding corner, model space \n"
82 " uniform vec3 uTextureScale; // convert model to texture coordinates \n"
83 " uniform vec3 uGradientDelta; // one voxel step in texture space \n"
84 " uniform sampler3D uVolume; // volume texture \n"
85 " uniform sampler1D uColorLUT; // 1D transfer function texture \n"
86 " uniform float uIsosurface; // isosurface level \n"
87 " uniform float uOpacityThreshold; // opacity threshold \n"
88 " uniform float uOpticalDensityFactor; // Optical density factor \n"
89 " uniform float uResolution; // max samples to take on ray traversal \n"
91 " varying vec4 vPosition; \n"
93 " // deltas for gradient estimation along each axis in texture space \n"
94 " vec3 dx = vec3(uGradientDelta.x, 0.0, 0.0); \n"
95 " vec3 dy = vec3(0.0, uGradientDelta.y, 0.0); \n"
96 " vec3 dz = vec3(0.0, 0.0, uGradientDelta.z); \n"
99 " //---------------------------------------------------------------------- \n"
100 " // Finds the entering intersection between a ray e1+d and the volume's \n"
101 " // bounding box. \n"
102 " //---------------------------------------------------------------------- \n"
104 " float entry(vec3 e1, vec3 d) \n"
106 " float t = distance(uMinCorner, uMaxCorner); \n"
108 " vec3 a = (uMinCorner - e1) / d; \n"
109 " vec3 b = (uMaxCorner - e1) / d; \n"
110 " vec3 u = min(a, b); \n"
112 " return max( max(-t, u.x), max(u.y, u.z) ); \n"
116 " //---------------------------------------------------------------------- \n"
117 " // Estimates the intensity gradient of the volume in model space \n"
118 " //---------------------------------------------------------------------- \n"
120 " vec3 gradient(vec3 tc) \n"
122 " vec3 nabla = vec3( \n"
123 " texture3D(uVolume, tc + dx).r - texture3D(uVolume, tc - dx).r, \n"
124 " texture3D(uVolume, tc + dy).r - texture3D(uVolume, tc - dy).r, \n"
125 " texture3D(uVolume, tc + dz).r - texture3D(uVolume, tc - dz).r \n"
128 " return (nabla / uGradientDelta) * uTextureScale; \n"
132 " //---------------------------------------------------------------------- \n"
133 " // Computes phong shading based on current light and material \n"
135 " //---------------------------------------------------------------------- \n"
137 " vec3 shade(vec3 p, vec3 v, vec3 n) \n"
139 " vec4 lp = gl_ModelViewMatrixInverse * gl_LightSource[0].position; \n"
140 " vec3 l = normalize(lp.xyz - p * lp.w); \n"
141 " vec3 h = normalize(l+v); \n"
142 " float cos_i = max(dot(n, l), 0.0); \n"
143 " float cos_h = max(dot(n, h), 0.0); \n"
145 " vec3 Ia = gl_FrontLightProduct[0].ambient.rgb; \n"
146 " vec3 Id = gl_FrontLightProduct[0].diffuse.rgb * cos_i; \n"
147 " vec3 Is = gl_FrontLightProduct[0].specular.rgb * pow(cos_h, gl_FrontMaterial.shininess); \n"
148 " return (Ia + Id + Is); \n"
152 " //---------------------------------------------------------------------- \n"
153 " // Main fragment shader code. \n"
154 " //---------------------------------------------------------------------- \n"
156 " void main(void) \n"
158 " vec4 camera = gl_ModelViewMatrixInverse * vec4(0.0, 0.0, 0.0, 1.0); \n"
159 " vec3 raydir = normalize(vPosition.xyz - camera.xyz); \n"
161 " float t_entry = entry(vPosition.xyz, raydir); \n"
162 " t_entry = max(t_entry, -distance(camera.xyz, vPosition.xyz)); \n"
164 " // estimate a reasonable step size \n"
165 " float t_step = distance(uMinCorner, uMaxCorner) / uResolution; \n"
166 " vec3 tc_step = uTextureScale * (t_step * raydir); \n"
168 " // cast the ray (in model space) \n"
169 " vec4 sum = vec4(0.0); \n"
170 " vec3 tc = gl_TexCoord[0].stp + t_entry * tc_step / t_step; \n"
172 " for (float t = t_entry; t < 0.0; t += t_step, tc += tc_step) \n"
174 " // sample the volume for intensity (red channel) \n"
175 " float intensity = texture3D(uVolume, tc).r; \n"
177 " // look up intensity in the colour LUT \n"
178 " vec4 colour = texture1D(uColorLUT, intensity); \n"
180 " // skip empty space \n"
181 " if (colour.a < 0.001) continue; \n"
183 " // estimate gradient \n"
184 " vec3 nabla = gradient(tc); \n"
186 " // compute shading \n"
187 " vec3 position = vPosition.xyz + t * raydir; \n"
188 " vec3 normal = -normalize(nabla); \n"
189 " vec3 view = -raydir; \n"
190 " vec3 shaded = shade(position, view, normal); \n"
191 " colour.rgb *= shaded; \n"
193 " // compute transmission for this segment \n"
194 " float Tr = exp(-colour.a * uOpticalDensityFactor); \n"
195 " colour.rgb *= 1.0 - Tr; \n"
196 " colour.a = 1.0 - Tr; \n"
198 " // accumulate colour and opacity \n"
199 " sum += (1.0 - sum.a) * colour; \n"
201 " // early ray termination test \n"
202 " if (sum.a > uOpacityThreshold) \n"
204 " // calculate fragment depth \n"
205 " vec4 clip = gl_ModelViewProjectionMatrix * vec4(position, 1.0); \n"
206 " gl_FragDepth = (gl_DepthRange.diff * clip.z / clip.w + \n"
207 " gl_DepthRange.near + gl_DepthRange.far) * 0.5; \n"
213 " gl_FragColor = sum; \n"
const std::string C_SHADER_DVR_LUT8_FRAG
Definition: CShaderDVR-LUT8.h:78
Implements option settings for CHAI3D.
const std::string C_SHADER_DVR_LUT8_VERT
Definition: CShaderDVR-LUT8.h:55
Definition: CAudioBuffer.cpp:56