diff --git a/src/osgVolume/Shaders/volume_frag.cpp b/src/osgVolume/Shaders/volume_frag.cpp index 6351da4f9..519170c11 100644 --- a/src/osgVolume/Shaders/volume_frag.cpp +++ b/src/osgVolume/Shaders/volume_frag.cpp @@ -1,4 +1,15 @@ -char volume_frag[] = "uniform sampler3D baseTexture;\n" +char volume_frag[] = "#version 110\n" + "\n" + "##pragma import_defines(NVIDIA_Corporation)\n" + "\n" + "#if defined(NVIDIA_Corporation)\n" + " // workaround a NVidia hang when the loop variable is a float, but works fine when it's an int\n" + " #define loop_type int\n" + "#else\n" + " #define loop_type float\n" + "#endif\n" + "\n" + "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float AlphaFuncValue;\n" @@ -10,6 +21,7 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n" "\n" "void main(void)\n" "{\n" + "\n" " vec4 t0 = vertexPos;\n" " vec4 te = cameraPos;\n" "\n" @@ -61,16 +73,16 @@ char volume_frag[] = "uniform sampler3D baseTexture;\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\n" - " const int max_iteratrions = 2048;\n" - " int num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" - " if (num_iterations<2) num_iterations = 2;\n" + " const loop_type max_iteratrions = loop_type(2048);\n" + " loop_type num_iterations = loop_type(ceil(length((te-t0).xyz)/SampleDensityValue));\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>0)\n" + " while(num_iterations>loop_type(0))\n" " {\n" " vec4 color = texture3D( baseTexture, texcoord);\n" " float r = color[3]*TransparencyValue;\n" diff --git a/src/osgVolume/Shaders/volume_iso_frag.cpp b/src/osgVolume/Shaders/volume_iso_frag.cpp index 85542b7ac..7b005c2b0 100644 --- a/src/osgVolume/Shaders/volume_iso_frag.cpp +++ b/src/osgVolume/Shaders/volume_iso_frag.cpp @@ -1,4 +1,15 @@ -char volume_iso_frag[] = "uniform sampler3D baseTexture;\n" +char volume_iso_frag[] = "#version 110\n" + "\n" + "##pragma import_defines(NVIDIA_Corporation)\n" + "\n" + "#if defined(NVIDIA_Corporation)\n" + " // workaround a NVidia hang when the loop variable is a float, but works fine when it's an int\n" + " #define loop_type int\n" + "#else\n" + " #define loop_type float\n" + "#endif\n" + "\n" + "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float IsoSurfaceValue;\n" @@ -62,23 +73,23 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\n" - " const int max_iteratrions = 2048;\n" - " int num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" - " if (num_iterations<2) num_iterations = 2;\n" + " const loop_type max_iteratrions = loop_type(2048);\n" + " loop_type num_iterations = loop_type(ceil(length((te-t0).xyz)/SampleDensityValue));\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" "\n" - " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = te.xyz;\n" "\n" " vec4 previousColor = texture3D( baseTexture, texcoord);\n" - " \n" + "\n" " float normalSampleDistance = 1.0/512.0;\n" " vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0);\n" " vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);\n" " vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);\n" - " \n" - " while(num_iterations>0)\n" + "\n" + " while(num_iterations>loop_type(0))\n" " {\n" " vec4 color = texture3D( baseTexture, texcoord);\n" "\n" @@ -87,7 +98,7 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n" " {\n" " float r = (IsoSurfaceValue-color.a)/(previousColor.a-color.a);\n" " texcoord = texcoord - r*deltaTexCoord;\n" - " \n" + "\n" " float a = color.a;\n" " float px = texture3D( baseTexture, texcoord + deltaX).a;\n" " float py = texture3D( baseTexture, texcoord + deltaY).a;\n" @@ -96,7 +107,7 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n" " float nx = texture3D( baseTexture, texcoord - deltaX).a;\n" " float ny = texture3D( baseTexture, texcoord - deltaY).a;\n" " float nz = texture3D( baseTexture, texcoord - deltaZ).a;\n" - " \n" + "\n" " vec3 grad = vec3(px-nx, py-ny, pz-nz);\n" " if (grad.x!=0.0 || grad.y!=0.0 || grad.z!=0.0)\n" " {\n" @@ -114,13 +125,13 @@ char volume_iso_frag[] = "uniform sampler3D baseTexture;\n" " color *= baseColor;\n" "\n" " gl_FragColor = color;\n" - " \n" + "\n" " return;\n" " }\n" - " \n" + "\n" " previousColor = color;\n" - " \n" - " texcoord += deltaTexCoord; \n" + "\n" + " texcoord += deltaTexCoord;\n" "\n" " --num_iterations;\n" " }\n" diff --git a/src/osgVolume/Shaders/volume_lit_frag.cpp b/src/osgVolume/Shaders/volume_lit_frag.cpp index 97b4ef05b..ea5ff1c3d 100644 --- a/src/osgVolume/Shaders/volume_lit_frag.cpp +++ b/src/osgVolume/Shaders/volume_lit_frag.cpp @@ -1,4 +1,15 @@ -char volume_lit_frag[] = "uniform sampler3D baseTexture;\n" +char volume_lit_frag[] = "#version 110\n" + "\n" + "##pragma import_defines(NVIDIA_Corporation)\n" + "\n" + "#if defined(NVIDIA_Corporation)\n" + " // workaround a NVidia hang when the loop variable is a float, but works fine when it's an int\n" + " #define loop_type int\n" + "#else\n" + " #define loop_type float\n" + "#endif\n" + "\n" + "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" "uniform float TransparencyValue;\n" "uniform float AlphaFuncValue;\n" @@ -62,12 +73,12 @@ char volume_lit_frag[] = "uniform sampler3D baseTexture;\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\n" - " const int max_iteratrions = 2048;\n" - " int num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" - " if (num_iterations<2) num_iterations = 2;\n" + " const loop_type max_iteratrions = loop_type(2048);\n" + " loop_type num_iterations = loop_type(ceil(length((te-t0).xyz)/SampleDensityValue));\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = t0.xyz;\n" "\n" " float normalSampleDistance = 1.0/512.0;\n" @@ -75,8 +86,8 @@ char volume_lit_frag[] = "uniform sampler3D baseTexture;\n" " vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);\n" " vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);\n" "\n" - " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" - " while(num_iterations>0)\n" + " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" + " while(num_iterations>loop_type(0))\n" " {\n" " vec4 color = texture3D( baseTexture, texcoord);\n" "\n" diff --git a/src/osgVolume/Shaders/volume_lit_tf_frag.cpp b/src/osgVolume/Shaders/volume_lit_tf_frag.cpp index 63e02dc2e..58326b305 100644 --- a/src/osgVolume/Shaders/volume_lit_tf_frag.cpp +++ b/src/osgVolume/Shaders/volume_lit_tf_frag.cpp @@ -1,4 +1,15 @@ -char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n" +char volume_lit_tf_frag[] = "#version 110\n" + "\n" + "##pragma import_defines(NVIDIA_Corporation)\n" + "\n" + "#if defined(NVIDIA_Corporation)\n" + " // workaround a NVidia hang when the loop variable is a float, but works fine when it's an int\n" + " #define loop_type int\n" + "#else\n" + " #define loop_type float\n" + "#endif\n" + "\n" + "uniform sampler3D baseTexture;\n" "\n" "uniform sampler1D tfTexture;\n" "uniform float tfScale;\n" @@ -69,12 +80,12 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n" "\n" " vec3 eyeDirection = normalize((te-t0).xyz);\n" "\n" - " const int max_iteratrions = 2048;\n" - " int num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" - " if (num_iterations<2) num_iterations = 2;\n" + " const loop_type max_iteratrions = loop_type(2048);\n" + " loop_type num_iterations = loop_type(ceil(length((te-t0).xyz)/SampleDensityValue));\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = t0.xyz;\n" "\n" " float normalSampleDistance = 1.0/512.0;\n" @@ -82,8 +93,8 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n" " vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);\n" " vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);\n" "\n" - " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0); \n" - " while(num_iterations>0)\n" + " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" + " while(num_iterations>loop_type(0))\n" " {\n" " float v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n" @@ -126,9 +137,9 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n" "\n" " fragColor.w *= TransparencyValue;\n" "\n" - " if (fragColor.w>1.0) fragColor.w = 1.0; \n" + " if (fragColor.w>1.0) fragColor.w = 1.0;\n" " if (fragColor.wmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>0)\n" + " while(num_iterations>loop_type(0))\n" " {\n" " vec4 color = texture3D( baseTexture, texcoord);\n" " if (fragColor.wmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>0)\n" + " while(num_iterations>loop_type(0))\n" " {\n" " float v = texture3D( baseTexture, texcoord).a * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n" diff --git a/src/osgVolume/Shaders/volume_tf_iso_frag.cpp b/src/osgVolume/Shaders/volume_tf_iso_frag.cpp index e0df5217c..0415a0fc0 100644 --- a/src/osgVolume/Shaders/volume_tf_iso_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_iso_frag.cpp @@ -1,4 +1,15 @@ -char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" +char volume_tf_iso_frag[] = "#version 110\n" + "\n" + "##pragma import_defines(NVIDIA_Corporation)\n" + "\n" + "#if defined(NVIDIA_Corporation)\n" + " // workaround a NVidia hang when the loop variable is a float, but works fine when it's an int\n" + " #define loop_type int\n" + "#else\n" + " #define loop_type float\n" + "#endif\n" + "\n" + "uniform sampler3D baseTexture;\n" "\n" "uniform sampler1D tfTexture;\n" "uniform float tfScale;\n" @@ -67,13 +78,13 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\n" - " const int max_iteratrions = 2048;\n" - " int num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" - " if (num_iterations<2) num_iterations = 2;\n" + " const loop_type max_iteratrions = loop_type(2048);\n" + " loop_type num_iterations = loop_type(ceil(length((te-t0).xyz)/SampleDensityValue));\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" "\n" - " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = te.xyz;\n" " float previousV = texture3D( baseTexture, texcoord).a;\n" "\n" @@ -81,8 +92,8 @@ char volume_tf_iso_frag[] = "uniform sampler3D baseTexture;\n" " vec3 deltaX = vec3(normalSampleDistance, 0.0, 0.0);\n" " vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);\n" " vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);\n" - " \n" - " while(num_iterations>0)\n" + "\n" + " while(num_iterations>loop_type(0))\n" " {\n" "\n" " float v = texture3D( baseTexture, texcoord).a;\n" diff --git a/src/osgVolume/Shaders/volume_tf_mip_frag.cpp b/src/osgVolume/Shaders/volume_tf_mip_frag.cpp index fed843298..13387f31e 100644 --- a/src/osgVolume/Shaders/volume_tf_mip_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_mip_frag.cpp @@ -1,4 +1,15 @@ -char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n" +char volume_tf_mip_frag[] = "#version 110\n" + "\n" + "##pragma import_defines(NVIDIA_Corporation)\n" + "\n" + "#if defined(NVIDIA_Corporation)\n" + " // workaround a NVidia hang when the loop variable is a float, but works fine when it's an int\n" + " #define loop_type int\n" + "#else\n" + " #define loop_type float\n" + "#endif\n" + "\n" + "uniform sampler3D baseTexture;\n" "\n" "uniform sampler1D tfTexture;\n" "uniform float tfScale;\n" @@ -66,16 +77,16 @@ char volume_tf_mip_frag[] = "uniform sampler3D baseTexture;\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\n" - " const int max_iteratrions = 2048;\n" - " int num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" - " if (num_iterations<2) num_iterations = 2;\n" + " const loop_type max_iteratrions = loop_type(2048);\n" + " loop_type num_iterations = loop_type(ceil(length((te-t0).xyz)/SampleDensityValue));\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1);\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>0)\n" + " while(num_iterations>loop_type(0))\n" " {\n" " float v = texture3D( baseTexture, texcoord).s * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n"