ERROR: In vtkShaderProgram.cxx, line 452 vtkShaderProgram (000001E6C389E050): 1: #version 150 2: #ifdef GL_ES 3: #ifdef GL_FRAGMENT_PRECISION_HIGH 4: precision highp float; 5: precision highp sampler2D; 6: precision highp sampler3D; 7: #else 8: precision mediump float; 9: precision mediump sampler2D; 10: precision mediump sampler3D; 11: #endif 12: #define texelFetchBuffer texelFetch 13: #define texture1D texture 14: #define texture2D texture 15: #define texture3D texture 16: #else // GL_ES 17: #define highp 18: #define mediump 19: #define lowp 20: #if __VERSION__ == 150 21: #define texelFetchBuffer texelFetch 22: #define texture1D texture 23: #define texture2D texture 24: #define texture3D texture 25: #endif 26: #endif // GL_ES 27: #define varying in 28: 29: 30: /*========================================================================= 31: 32: Program: Visualization Toolkit 33: Module: raycasterfs.glsl 34: 35: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 36: All rights reserved. 37: See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 38: 39: This software is distributed WITHOUT ANY WARRANTY; without even 40: the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 41: PURPOSE. See the above copyright notice for more information. 42: 43: =========================================================================*/ 44: 45: ////////////////////////////////////////////////////////////////////////////// 46: /// 47: /// Inputs 48: /// 49: ////////////////////////////////////////////////////////////////////////////// 50: 51: /// 3D texture coordinates form vertex shader 52: in vec3 ip_textureCoords; 53: in vec3 ip_vertexPos; 54: 55: ////////////////////////////////////////////////////////////////////////////// 56: /// 57: /// Outputs 58: /// 59: ////////////////////////////////////////////////////////////////////////////// 60: 61: vec4 g_fragColor = vec4(0.0); 62: 63: ////////////////////////////////////////////////////////////////////////////// 64: /// 65: /// Uniforms, attributes, and globals 66: /// 67: ////////////////////////////////////////////////////////////////////////////// 68: vec3 g_dirStep; 69: float g_lengthStep = 0.0; 70: vec4 g_srcColor; 71: vec4 g_eyePosObj; 72: bool g_exit; 73: bool g_skip; 74: float g_currentT; 75: float g_terminatePointMax; 76: 77: // These describe the entire ray for this scene, not just the current depth 78: // peeling segment. These are texture coordinates. 79: vec3 g_rayOrigin; // Entry point of volume or clip point 80: vec3 g_rayTermination; // Termination point (depth, clip, etc) 81: 82: // These describe the current segment. If not peeling, they are initialized to 83: // the ray endpoints. 84: vec3 g_dataPos; 85: vec3 g_terminatePos; 86: 87: float g_jitterValue = 0.0; 88: 89: 90: 91: out vec4 fragOutput0; 92: 93: 94: uniform sampler3D in_volume[1]; 95: uniform vec4 in_volume_scale[1]; 96: uniform vec4 in_volume_bias[1]; 97: uniform int in_noOfComponents; 98: 99: uniform sampler2D in_depthSampler; 100: 101: // Camera position 102: uniform vec3 in_cameraPos; 103: uniform mat4 in_volumeMatrix[1]; 104: uniform mat4 in_inverseVolumeMatrix[1]; 105: uniform mat4 in_textureDatasetMatrix[1]; 106: uniform mat4 in_inverseTextureDatasetMatrix[1]; 107: uniform mat4 in_textureToEye[1]; 108: uniform vec3 in_texMin[1]; 109: uniform vec3 in_texMax[1]; 110: uniform mat4 in_cellToPoint[1]; 111: // view and model matrices 112: uniform mat4 in_projectionMatrix; 113: uniform mat4 in_inverseProjectionMatrix; 114: uniform mat4 in_modelViewMatrix; 115: uniform mat4 in_inverseModelViewMatrix; 116: in mat4 ip_inverseTextureDataAdjusted; 117: 118: // Ray step size 119: uniform vec3 in_cellStep[1]; 120: uniform vec2 in_scalarsRange[4]; 121: uniform vec3 in_cellSpacing[1]; 122: 123: // Sample distance 124: uniform float in_sampleDistance; 125: 126: // Scales 127: uniform vec2 in_windowLowerLeftCorner; 128: uniform vec2 in_inverseOriginalWindowSize; 129: uniform vec2 in_inverseWindowSize; 130: uniform vec3 in_textureExtentsMax; 131: uniform vec3 in_textureExtentsMin; 132: 133: // Material and lighting 134: uniform vec3 in_diffuse[4]; 135: uniform vec3 in_ambient[4]; 136: uniform vec3 in_specular[4]; 137: uniform float in_shininess[4]; 138: 139: // Others 140: vec3 g_rayJitter = vec3(0.0); 141: 142: uniform vec2 in_averageIPRange; 143: vec4 g_eyePosObjs[1]; 144: 145: 146: 147: const float g_opacityThreshold = 1.0 - 1.0 / 255.0; 148: 149: 150: 151: 152: 153: #define EPSILON 0.001 154: 155: // Computes the intersection between a ray and a box 156: // The box should be axis aligned so we only give two arguments 157: struct Hit 158: { 159: float tmin; 160: float tmax; 161: }; 162: 163: struct Ray 164: { 165: vec3 origin; 166: vec3 dir; 167: vec3 invDir; 168: }; 169: 170: bool BBoxIntersect(const vec3 boxMin, const vec3 boxMax, const Ray r, out Hit hit) 171: { 172: vec3 tbot = r.invDir * (boxMin - r.origin); 173: vec3 ttop = r.invDir * (boxMax - r.origin); 174: vec3 tmin = min(ttop, tbot); 175: vec3 tmax = max(ttop, tbot); 176: vec2 t = max(tmin.xx, tmin.yz); 177: float t0 = max(t.x, t.y); 178: t = min(tmax.xx, tmax.yz); 179: float t1 = min(t.x, t.y); 180: hit.tmin = t0; 181: hit.tmax = t1; 182: return t1 > max(t0, 0.0); 183: } 184: 185: // As BBoxIntersect requires the inverse of the ray coords, 186: // this function is used to avoid numerical issues 187: void safe_0_vector(inout Ray ray) 188: { 189: if(abs(ray.dir.x) < EPSILON) ray.dir.x = sign(ray.dir.x) * EPSILON; 190: if(abs(ray.dir.y) < EPSILON) ray.dir.y = sign(ray.dir.y) * EPSILON; 191: if(abs(ray.dir.z) < EPSILON) ray.dir.z = sign(ray.dir.z) * EPSILON; 192: } 193: 194: // the phase function should be normalized to 4pi for compatibility with surface rendering 195: //VTK::PhaseFunction::Dec 196: 197: uniform sampler2D in_colorTransferFunc_0[1]; 198: 199: 200: 201: 202: 203: 204: 205: 206: //VTK::GradientCache::Dec 207: 208: //VTK::Transfer2D::Dec 209: 210: 211: 212: uniform sampler2D in_opacityTransferFunc_0[1]; 213: 214: float computeOpacity(vec4 scalar) 215: { 216: return texture2D(in_opacityTransferFunc_0[0], vec2(scalar.w, 0)).r; 217: } 218: 219: //VTK::ComputeRGBA2DWithGradient::Dec 220: 221: vec4 computeGradient(in vec3 texPos, in int c, in sampler3D volume, in int index) 222: { 223: return vec4(0.0); 224: } 225: 226: 227: //VTK::ComputeDensityGradient::Dec 228: 229: //VTK::ComputeVolumetricShadow::Dec 230: 231: 232: vec4 computeLighting(vec4 color, int component, float label) 233: { 234: vec4 finalColor = vec4(0.0); 235: 236: finalColor = vec4(color.rgb, 0.0); 237: finalColor.a = color.a; 238: return finalColor; 239: } 240: 241: 242: vec4 computeColor(vec4 scalar, float opacity) 243: { 244: return clamp(computeLighting(vec4(texture2D(in_colorTransferFunc_0[0], 245: vec2(scalar.w, 0.0)).xyz, opacity), 0, 0.0), 0.0, 1.0); 246: } 247: 248: 249: vec3 computeRayDirection() 250: { 251: return normalize(ip_vertexPos.xyz - g_eyePosObj.xyz); 252: } 253: 254: //VTK::Picking::Dec 255: 256: //VTK::RenderToImage::Dec 257: 258: //VTK::DepthPeeling::Dec 259: 260: uniform float in_scale; 261: uniform float in_bias; 262: 263: ////////////////////////////////////////////////////////////////////////////// 264: /// 265: /// Helper functions 266: /// 267: ////////////////////////////////////////////////////////////////////////////// 268: 269: /** 270: * Transform window coordinate to NDC. 271: */ 272: vec4 WindowToNDC(const float xCoord, const float yCoord, const float zCoord) 273: { 274: vec4 NDCCoord = vec4(0.0, 0.0, 0.0, 1.0); 275: 276: NDCCoord.x = (xCoord - in_windowLowerLeftCorner.x) * 2.0 * 277: in_inverseWindowSize.x - 1.0; 278: NDCCoord.y = (yCoord - in_windowLowerLeftCorner.y) * 2.0 * 279: in_inverseWindowSize.y - 1.0; 280: NDCCoord.z = (2.0 * zCoord - (gl_DepthRange.near + gl_DepthRange.far)) / 281: gl_DepthRange.diff; 282: 283: return NDCCoord; 284: } 285: 286: /** 287: * Transform NDC coordinate to window coordinates. 288: */ 289: vec4 NDCToWindow(const float xNDC, const float yNDC, const float zNDC) 290: { 291: vec4 WinCoord = vec4(0.0, 0.0, 0.0, 1.0); 292: 293: WinCoord.x = (xNDC + 1.f) / (2.f * in_inverseWindowSize.x) + 294: in_windowLowerLeftCorner.x; 295: WinCoord.y = (yNDC + 1.f) / (2.f * in_inverseWindowSize.y) + 296: in_windowLowerLeftCorner.y; 297: WinCoord.z = (zNDC * gl_DepthRange.diff + 298: (gl_DepthRange.near + gl_DepthRange.far)) / 2.f; 299: 300: return WinCoord; 301: } 302: 303: /** 304: * Clamps the texture coordinate vector @a pos to a new position in the set 305: * { start + i * step }, where i is an integer. If @a ceiling 306: * is true, the sample located further in the direction of @a step is used, 307: * otherwise the sample location closer to the eye is used. 308: * This function assumes both start and pos already have jittering applied. 309: */ 310: vec3 ClampToSampleLocation(vec3 start, vec3 step, vec3 pos, bool ceiling) 311: { 312: vec3 offset = pos - start; 313: float stepLength = length(step); 314: 315: // Scalar projection of offset on step: 316: float dist = dot(offset, step / stepLength); 317: if (dist < 0.) // Don't move before the start position: 318: { 319: return start; 320: } 321: 322: // Number of steps 323: float steps = dist / stepLength; 324: 325: // If we're reeaaaaallly close, just round -- it's likely just numerical noise 326: // and the value should be considered exact. 327: if (abs(mod(steps, 1.)) > 1e-5) 328: { 329: if (ceiling) 330: { 331: steps = ceil(steps); 332: } 333: else 334: { 335: steps = floor(steps); 336: } 337: } 338: else 339: { 340: steps = floor(steps + 0.5); 341: } 342: 343: return start + steps * step; 344: } 345: 346: ////////////////////////////////////////////////////////////////////////////// 347: /// 348: /// Ray-casting 349: /// 350: ////////////////////////////////////////////////////////////////////////////// 351: 352: /** 353: * Global initialization. This method should only be called once per shader 354: * invocation regardless of whether castRay() is called several times (e.g. 355: * vtkDualDepthPeelingPass). Any castRay() specific initialization should be 356: * placed within that function. 357: */ 358: void initializeRayCast() 359: { 360: /// Initialize g_fragColor (output) to 0 361: g_fragColor = vec4(0.0); 362: g_dirStep = vec3(0.0); 363: g_srcColor = vec4(0.0); 364: g_exit = false; 365: 366: 367: // Get the 3D texture coordinates for lookup into the in_volume dataset 368: g_rayOrigin = ip_textureCoords.xyz; 369: 370: // Eye position in dataset space 371: g_eyePosObj = in_inverseVolumeMatrix[0] * vec4(in_cameraPos, 1.0); 372: g_eyePosObjs[0] = in_inverseVolumeMatrix[0] * vec4(in_cameraPos, 1.0); 373: 374: // Getting the ray marching direction (in dataset space) 375: vec3 rayDir = computeRayDirection(); 376: 377: // 2D Texture fragment coordinates [0,1] from fragment coordinates. 378: // The frame buffer texture has the size of the plain buffer but 379: // we use a fraction of it. The texture coordinate is less than 1 if 380: // the reduction factor is less than 1. 381: // Device coordinates are between -1 and 1. We need texture 382: // coordinates between 0 and 1. The in_depthSampler 383: // buffer has the original size buffer. 384: vec2 fragTexCoord = (gl_FragCoord.xy - in_windowLowerLeftCorner) * 385: in_inverseWindowSize; 386: 387: // Multiply the raymarching direction with the step size to get the 388: // sub-step size we need to take at each raymarching step 389: g_dirStep = (ip_inverseTextureDataAdjusted * 390: vec4(rayDir, 0.0)).xyz * in_sampleDistance; 391: g_lengthStep = length(g_dirStep); 392: 393: float jitterValue = 0.0; 394: 395: // Flag to determine if voxel should be considered for the rendering 396: g_skip = false; 397: 398: 399: 400: 401: // Flag to indicate if the raymarch loop should terminate 402: bool stop = false; 403: 404: g_terminatePointMax = 0.0; 405: 406: vec4 l_depthValue = texture2D(in_depthSampler, fragTexCoord); 407: // Depth test 408: if(gl_FragCoord.z >= l_depthValue.x) 409: { 410: discard; 411: } 412: 413: // color buffer or max scalar buffer have a reduced size. 414: fragTexCoord = (gl_FragCoord.xy - in_windowLowerLeftCorner) * 415: in_inverseOriginalWindowSize; 416: 417: // Compute max number of iterations it will take before we hit 418: // the termination point 419: 420: // Abscissa of the point on the depth buffer along the ray. 421: // point in texture coordinates 422: vec4 rayTermination = WindowToNDC(gl_FragCoord.x, gl_FragCoord.y, l_depthValue.x); 423: 424: // From normalized device coordinates to eye coordinates. 425: // in_projectionMatrix is inversed because of way VT 426: // From eye coordinates to texture coordinates 427: rayTermination = ip_inverseTextureDataAdjusted * 428: in_inverseVolumeMatrix[0] * 429: in_inverseModelViewMatrix * 430: in_inverseProjectionMatrix * 431: rayTermination; 432: g_rayTermination = rayTermination.xyz / rayTermination.w; 433: 434: // Setup the current segment: 435: g_dataPos = g_rayOrigin; 436: g_terminatePos = g_rayTermination; 437: 438: g_terminatePointMax = length(g_terminatePos.xyz - g_dataPos.xyz) / 439: length(g_dirStep); 440: g_currentT = 0.0; 441: 442: 443: 444: //VTK::RenderToImage::Init 445: 446: //VTK::DepthPass::Init 447: 448: //VTK::Matrices::Init 449: 450: g_jitterValue = jitterValue; 451: } 452: 453: /** 454: * March along the ray direction sampling the volume texture. This function 455: * takes a start and end point as arguments but it is up to the specific render 456: * pass implementation to use these values (e.g. vtkDualDepthPeelingPass). The 457: * mapper does not use these values by default, instead it uses the number of 458: * steps defined by g_terminatePointMax. 459: */ 460: vec4 castRay(const float zStart, const float zEnd) 461: { 462: //VTK::DepthPeeling::Ray::Init 463: 464: 465: 466: //VTK::DepthPeeling::Ray::PathCheck 467: 468: 469: 470: /// For all samples along the ray 471: while (!g_exit) 472: { 473: 474: g_skip = false; 475: g_dataPos = g_intersection; 476: 477: 478: 479: 480: 481: 482: 483: 484: //VTK::PreComputeGradients::Impl 485: 486: 487: if (!g_skip) 488: { 489: vec4 scalar; 490: 491: scalar = texture3D(in_volume[0], g_dataPos); 492: 493: scalar.r = scalar.r * in_volume_scale[0].r + in_volume_bias[0].r; 494: scalar = vec4(scalar.r); 495: // test if the intersection is inside the volume bounds 496: if (any(greaterThan(g_dataPos, vec3(1.0))) || any(lessThan(g_dataPos, vec3(0.0)))) 497: { 498: discard; 499: } 500: float opacity = computeOpacity(scalar); 501: g_fragColor = computeColor(scalar, opacity); 502: g_fragColor.rgb *= opacity; 503: g_exit = true; 504: } 505: 506: //VTK::RenderToImage::Impl 507: 508: //VTK::DepthPass::Impl 509: 510: /// Advance ray 511: g_dataPos += g_dirStep; 512: 513: 514: if(any(greaterThan(max(g_dirStep, vec3(0.0))*(g_dataPos - in_texMax[0]),vec3(0.0))) || 515: any(greaterThan(min(g_dirStep, vec3(0.0))*(g_dataPos - in_texMin[0]),vec3(0.0)))) 516: { 517: break; 518: } 519: 520: // Early ray termination 521: // if the currently composited colour alpha is already fully saturated 522: // we terminated the loop or if we have hit an obstacle in the 523: // direction of they ray (using depth buffer) we terminate as well. 524: if((g_fragColor.a > g_opacityThreshold) || 525: g_currentT >= g_terminatePointMax) 526: { 527: break; 528: } 529: ++g_currentT; 530: } 531: 532: 533: 534: return g_fragColor; 535: } 536: 537: /** 538: * Finalize specific modes and set output data. 539: */ 540: void finalizeRayCast() 541: { 542: 543: 544: 545: 546: 547: 548: 549: 550: //VTK::Picking::Exit 551: 552: g_fragColor.r = g_fragColor.r * in_scale + in_bias * g_fragColor.a; 553: g_fragColor.g = g_fragColor.g * in_scale + in_bias * g_fragColor.a; 554: g_fragColor.b = g_fragColor.b * in_scale + in_bias * g_fragColor.a; 555: fragOutput0 = g_fragColor; 556: 557: //VTK::RenderToImage::Exit 558: 559: //VTK::DepthPass::Exit 560: } 561: 562: ////////////////////////////////////////////////////////////////////////////// 563: /// 564: /// Main 565: /// 566: ////////////////////////////////////////////////////////////////////////////// 567: void main() 568: { 569: 570: initializeRayCast(); 571: castRay(-1.0, -1.0); 572: finalizeRayCast(); 573: } ERROR: In vtkShaderProgram.cxx, line 453 vtkShaderProgram (000001E6C389E050): 0(475) : error C1503: undefined variable "g_intersection" ERROR: In vtkOpenGLGPUVolumeRayCastMapper.cxx, line 2833 vtkOpenGLGPUVolumeRayCastMapper (000001E6C27B28F0): Shader failed to compile