From eba1cc6e4fbb23f26f0a15ea875425ae207c8c6b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Aug 2015 20:06:38 +0000 Subject: [PATCH] Refactored workaround of NVidia nan lenght() bug. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15096 16af8721-9629-0410-8352-f15c8da7e697 --- src/osgVolume/Shaders/volume_frag.cpp | 29 ++++++++++---------- src/osgVolume/Shaders/volume_iso_frag.cpp | 28 +++++++++---------- src/osgVolume/Shaders/volume_lit_frag.cpp | 29 ++++++++++---------- src/osgVolume/Shaders/volume_lit_tf_frag.cpp | 29 ++++++++++---------- src/osgVolume/Shaders/volume_mip_frag.cpp | 29 ++++++++++---------- src/osgVolume/Shaders/volume_tf_frag.cpp | 29 ++++++++++---------- src/osgVolume/Shaders/volume_tf_iso_frag.cpp | 28 +++++++++---------- src/osgVolume/Shaders/volume_tf_mip_frag.cpp | 29 ++++++++++---------- 8 files changed, 118 insertions(+), 112 deletions(-) diff --git a/src/osgVolume/Shaders/volume_frag.cpp b/src/osgVolume/Shaders/volume_frag.cpp index 519170c11..8f57ffced 100644 --- a/src/osgVolume/Shaders/volume_frag.cpp +++ b/src/osgVolume/Shaders/volume_frag.cpp @@ -1,13 +1,6 @@ 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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" @@ -73,16 +66,24 @@ char volume_frag[] = "#version 110\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" + "\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(te-t0).xyz/(num_iterations-1.0);\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>loop_type(0))\n" + " while(num_iterations>0.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 7b005c2b0..f062ed19f 100644 --- a/src/osgVolume/Shaders/volume_iso_frag.cpp +++ b/src/osgVolume/Shaders/volume_iso_frag.cpp @@ -1,13 +1,6 @@ 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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" @@ -73,13 +66,20 @@ char volume_iso_frag[] = "#version 110\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" "\n" - " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-loop_type(1));\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = te.xyz;\n" "\n" " vec4 previousColor = texture3D( baseTexture, texcoord);\n" @@ -89,7 +89,7 @@ char volume_iso_frag[] = "#version 110\n" " vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);\n" " vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);\n" "\n" - " while(num_iterations>loop_type(0))\n" + " while(num_iterations>0.0)\n" " {\n" " vec4 color = texture3D( baseTexture, texcoord);\n" "\n" diff --git a/src/osgVolume/Shaders/volume_lit_frag.cpp b/src/osgVolume/Shaders/volume_lit_frag.cpp index ea5ff1c3d..5263e81ed 100644 --- a/src/osgVolume/Shaders/volume_lit_frag.cpp +++ b/src/osgVolume/Shaders/volume_lit_frag.cpp @@ -1,13 +1,6 @@ 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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" @@ -73,12 +66,20 @@ char volume_lit_frag[] = "#version 110\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" + "\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = t0.xyz;\n" "\n" " float normalSampleDistance = 1.0/512.0;\n" @@ -87,7 +88,7 @@ char volume_lit_frag[] = "#version 110\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>loop_type(0))\n" + " while(num_iterations>0.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 58326b305..662f15bad 100644 --- a/src/osgVolume/Shaders/volume_lit_tf_frag.cpp +++ b/src/osgVolume/Shaders/volume_lit_tf_frag.cpp @@ -1,13 +1,6 @@ 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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "\n" @@ -80,12 +73,20 @@ char volume_lit_tf_frag[] = "#version 110\n" "\n" " vec3 eyeDirection = normalize((te-t0).xyz);\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" + "\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = t0.xyz;\n" "\n" " float normalSampleDistance = 1.0/512.0;\n" @@ -94,7 +95,7 @@ char volume_lit_tf_frag[] = "#version 110\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>loop_type(0))\n" + " while(num_iterations>0.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_mip_frag.cpp b/src/osgVolume/Shaders/volume_mip_frag.cpp index 610ebb07b..73b6468df 100644 --- a/src/osgVolume/Shaders/volume_mip_frag.cpp +++ b/src/osgVolume/Shaders/volume_mip_frag.cpp @@ -1,13 +1,6 @@ char volume_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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "uniform float SampleDensityValue;\n" @@ -72,16 +65,24 @@ char volume_mip_frag[] = "#version 110\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" + "\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>loop_type(0))\n" + " while(num_iterations>0.0)\n" " {\n" " vec4 color = texture3D( baseTexture, texcoord);\n" " if (fragColor.wmax_iteratrions) num_iterations = max_iteratrions;\n" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" + "\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>loop_type(0))\n" + " while(num_iterations>0.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 0415a0fc0..2df672f4f 100644 --- a/src/osgVolume/Shaders/volume_tf_iso_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_iso_frag.cpp @@ -1,13 +1,6 @@ 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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "\n" @@ -78,13 +71,20 @@ char volume_tf_iso_frag[] = "#version 110\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" "\n" - " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-loop_type(1));\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(t0-te).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = te.xyz;\n" " float previousV = texture3D( baseTexture, texcoord).a;\n" "\n" @@ -93,7 +93,7 @@ char volume_tf_iso_frag[] = "#version 110\n" " vec3 deltaY = vec3(0.0, normalSampleDistance, 0.0);\n" " vec3 deltaZ = vec3(0.0, 0.0, normalSampleDistance);\n" "\n" - " while(num_iterations>loop_type(0))\n" + " while(num_iterations>0.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 13387f31e..2aaea2201 100644 --- a/src/osgVolume/Shaders/volume_tf_mip_frag.cpp +++ b/src/osgVolume/Shaders/volume_tf_mip_frag.cpp @@ -1,13 +1,6 @@ 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" + "#pragma import_defines(NVIDIA_Corporation)\n" "\n" "uniform sampler3D baseTexture;\n" "\n" @@ -77,16 +70,24 @@ char volume_tf_mip_frag[] = "#version 110\n" " t0 = t0 * texgen;\n" " te = te * texgen;\n" "\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" + " const float min_iteratrions = 2.0;\n" + " const float max_iteratrions = 2048.0;\n" "\n" - " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-loop_type(1));\n" + " float num_iterations = ceil(length((te-t0).xyz)/SampleDensityValue);\n" + "\n" + " #ifdef NVIDIA_Corporation\n" + " // Recent NVidia drivers have a bug in length() where it throws nan for some values of input into length() so catch these\n" + " if (num_iterations!=num_iterations) num_iterations = min_iteratrions;\n" + " #endif\n" + "\n" + " if (num_iterationsmax_iteratrions) num_iterations = max_iteratrions;\n" + "\n" + " vec3 deltaTexCoord=(te-t0).xyz/float(num_iterations-1.0);\n" " vec3 texcoord = t0.xyz;\n" "\n" " vec4 fragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " while(num_iterations>loop_type(0))\n" + " while(num_iterations>0.0)\n" " {\n" " float v = texture3D( baseTexture, texcoord).s * tfScale + tfOffset;\n" " vec4 color = texture1D( tfTexture, v);\n"