Refactored workaround of NVidia nan lenght() bug.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15096 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2015-08-11 20:06:38 +00:00
parent 41f284b678
commit eba1cc6e4f
8 changed files with 118 additions and 112 deletions

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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.w<color.w)\n"

View File

@ -1,13 +1,6 @@
char volume_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"
@ -77,16 +70,24 @@ char volume_tf_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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"

View File

@ -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_iterations<loop_type(2)) num_iterations = loop_type(2);\n"
" if (num_iterations>max_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_iterations<min_iteratrions) num_iterations = min_iteratrions;\n"
" else if (num_iterations>max_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"