diff --git a/benchmark/common/noisebench.c b/benchmark/common/noisebench.c index 7dd3643..759a831 100755 --- a/benchmark/common/noisebench.c +++ b/benchmark/common/noisebench.c @@ -352,14 +352,24 @@ int main(int argc, char *argv[]) { double performance = 0.0; int ndims = 2; // Currently running version of noise: 2D, 3D or 4D FILE *logfile; + GLFWvidmode vidmode; GLboolean running = GL_TRUE; // Main loop exits when this is set to GL_FALSE // Initialise GLFW glfwInit(); - // Open the OpenGL window - if( !glfwOpenWindow(4096, 4096, 8,8,8,8, 32,0, GLFW_FULLSCREEN) ) + // Open a temporary OpenGL window just to determine the desktop size + if( !glfwOpenWindow(256, 256, 8,8,8,8, 32,0, GLFW_WINDOW) ) + { + glfwTerminate(); // glfwOpenWindow failed, quit the program. + return 1; + } + glfwGetDesktopMode(&vidmode); + glfwCloseWindow(); + + // Open a fullscreen window using the current desktop resolution + if( !glfwOpenWindow(vidmode.Width, vidmode.Height, 8,8,8,8, 32,0, GLFW_FULLSCREEN) ) { glfwTerminate(); // glfwOpenWindow failed, quit the program. return 1; @@ -372,9 +382,10 @@ int main(int argc, char *argv[]) { logfile = fopen(LOGFILENAME, "w"); - fprintf(logfile, "GL vendor: %s\n", glGetString(GL_VENDOR)); - fprintf(logfile, "GL renderer: %s\n", glGetString(GL_RENDERER)); - fprintf(logfile, "GL version: %s\n", glGetString(GL_VERSION)); + fprintf(logfile, "GL vendor: %s\n", glGetString(GL_VENDOR)); + fprintf(logfile, "GL renderer: %s\n", glGetString(GL_RENDERER)); + fprintf(logfile, "GL version: %s\n", glGetString(GL_VERSION)); + fprintf(logfile, "Desktop size: %d x %d pixels\n", vidmode.Width, vidmode.Height); // Create the shader object from two external GLSL source files createShader(&programObject, VERTEXSHADERFILE2D, FRAGMENTSHADERFILE2D); diff --git a/src/noise2D.glsl b/src/noise2D.glsl index 34e624e..adfcbcd 100644 --- a/src/noise2D.glsl +++ b/src/noise2D.glsl @@ -10,9 +10,9 @@ float simplexNoise(vec2 v) { - const vec2 C = vec2(0.211324865405187134, // (3.0-sqrt(3.0))/6.; - 0.366025403784438597); // 0.5*(sqrt(3.0)-1.); - const vec3 D = vec3( 0., 0.5, 2.0) * 3.14159265358979312; + const vec2 C = vec2(0.211324865405187134, // (3.0-sqrt(3.0))/6.0; + 0.366025403784438597); // 0.5*(sqrt(3.0)-1.0); + const vec3 D = vec3( 0.0, 0.5, 2.0) * 3.14159265358979312; // First corner vec2 i = floor(v + dot(v, C.yy) ); vec2 x0 = v - i + dot(i, C.xx); @@ -20,27 +20,27 @@ float simplexNoise(vec2 v) // Other corners vec2 i1; i1.x = float( (x0.x>x0.y) ); - i1.y = 1. - i1.x; + i1.y = 1.0 - i1.x; - // x0 = x0 - 0. + 0. * C.xx ; - // x1 = x0 - i1 + 1. * C.xx ; - // x2 = x0 - 1. + 2. * C.xx ; + // x0 = x0 - 0.0 + 0.0 * C.xx ; + // x1 = x0 - i1 + 1.0 * C.xx ; + // x2 = x0 - 1.0 + 2.0 * C.xx ; - vec4 xC = x0.xyxy + vec4( C.xx, -1. + 2.* C.xx); + vec4 xC = x0.xyxy + vec4( C.xx, -1.0 + 2.0 * C.xx); xC.xy -= i1; // Permutations i = mod(i, pParam.x); vec3 p = permute( permute( - i.y + vec3(0., i1.y, 1. ), pParam.xyz) - + i.x + vec3(0., i1.x, 1. ), pParam.xyz); + i.y + vec3(0.0, i1.y, 1.0 ), pParam.xyz) + + i.x + vec3(0.0, i1.x, 1.0 ), pParam.xyz); - vec3 m = max(0.5 - vec3(dot(x0,x0), dot(xC.xy,xC.xy), dot(xC.zw,xC.zw)), 0.); + vec3 m = max(0.5 - vec3(dot(x0,x0), dot(xC.xy,xC.xy), dot(xC.zw,xC.zw)), 0.0); m = m*m ; m = m*m ; #ifndef USE_CIRCLE // ( N points uniformly over a line, mapped onto a diamond.) - vec3 x = 2.0 * fract(p / pParam.w) - 1. ; + vec3 x = 2.0 * fract(p / pParam.w) - 1.0 ; vec3 h = abs(x) - 0.5 ; vec3 ox = floor(x+0.5); @@ -61,7 +61,6 @@ float simplexNoise(vec2 v) g.x = a0.x * x0.x + h.x * x0.y; g.yz = a0.yz * xC.xz + h.yz * xC.yw; - return 160.0 * dot(m, g); #else // N points around a unit circle. vec3 phi = D.z * mod(p,pParam.w) /pParam.w ; @@ -69,6 +68,8 @@ float simplexNoise(vec2 v) vec2 a1 = sin(phi.zz +D.xy); // mix vec3 g = vec3( dot(a0.xy, x0), dot(a0.zw, xC.xy), dot(a1.xy, xC.zw) ); - return 160.0 * dot(m, g); #endif + + return 130.0 * dot(m, g); + } diff --git a/src/noise3D.glsl b/src/noise3D.glsl index 910bdf1..83d7edc 100644 --- a/src/noise3D.glsl +++ b/src/noise3D.glsl @@ -10,24 +10,24 @@ float simplexNoise(vec3 v) { - const vec2 C = vec2(1./6. , 1./3. ) ; - const vec4 D = vec4(0., 0.5, 1.0, 2.0); + const vec2 C = vec2(1.0/6.0, 1.0/3.0 ) ; + const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); // First corner vec3 i = floor(v + dot(v, C.yyy) ); vec3 x0 = v - i + dot(i, C.xxx) ; - + // Other corners #ifdef COLLAPSE_SORTNET vec3 g = vec3( greaterThan( x0.xyz, x0.yzx) ); // vec3 l = vec3( lessThanEqual( x0.xyz, x0.yzx) ); - vec3 l = 1. - g; - vec3 i1 = g.xyz * l.zxy; - vec3 i2 = max( g.xyz, l.zxy); + vec3 l = 1.0 - g; + vec3 i1 = min( g.xyz, l.zxy ); + vec3 i2 = max( g.xyz, l.zxy ); #else // Keeping this clean - let the compiler optimize. -// Force existance of strict total ordering in sort. - vec3 q0 = floor(x0 * 1024.0) + vec3( 0., 1./4., 2./4.); +// Force existence of strict total ordering in sort. + vec3 q0 = floor(x0 * 1024.0) + vec3( 0.0, 1.0/4.0, 2.0/4.0); vec3 q1; q1.x = max(q0.x, q0.y); q1.y = min(q0.x, q0.y); @@ -47,17 +47,17 @@ float simplexNoise(vec3 v) vec3 i2 = vec3(lessThanEqual(q3.yyy, q0)); #endif - // x0 = x0 - 0. + 0. * C - vec3 x1 = x0 - i1 + 1. * C.xxx; - vec3 x2 = x0 - i2 + 2. * C.xxx; - vec3 x3 = x0 - 1. + 3. * C.xxx; + // x0 = x0 - 0. + 0.0 * C + vec3 x1 = x0 - i1 + 1.0 * C.xxx; + vec3 x2 = x0 - i2 + 2.0 * C.xxx; + vec3 x3 = x0 - 1. + 3.0 * C.xxx; // Permutations i = mod(i, pParam.x ); vec4 p = permute( permute( permute( - i.z + vec4(0., i1.z, i2.z, 1. ), pParam.xyz) - + i.y + vec4(0., i1.y, i2.y, 1. ), pParam.xyz) - + i.x + vec4(0., i1.x, i2.x, 1. ), pParam.xyz); + i.z + vec4(0.0, i1.z, i2.z, 1.0 ), pParam.xyz) + + i.y + vec4(0.0, i1.y, i2.y, 1.0 ), pParam.xyz) + + i.x + vec4(0.0, i1.x, i2.x, 1.0 ), pParam.xyz); // Gradients // ( N*N points uniformly over a square, mapped onto a octohedron.) @@ -71,15 +71,15 @@ float simplexNoise(vec3 v) vec4 x = x_ *ns.x + ns.yyyy; vec4 y = y_ *ns.x + ns.yyyy; - vec4 h = 1. - abs(x) - abs(y); + vec4 h = 1.0 - abs(x) - abs(y); vec4 b0 = vec4( x.xy, y.xy ); vec4 b1 = vec4( x.zw, y.zw ); - //vec4 s0 = vec4(lessThan(b0,D.xxxx)) *2. -1.; - //vec4 s1 = vec4(lessThan(b1,D.xxxx)) *2. -1.; - vec4 s0 = floor(b0) *2. +1.; - vec4 s1 = floor(b1) *2. +1.; + //vec4 s0 = vec4(lessThan(b0,D.xxxx)) *2.0 -1.0; + //vec4 s1 = vec4(lessThan(b1,D.xxxx)) *2.0 -1.0; + vec4 s0 = floor(b0) *2.0 +1.0; + vec4 s1 = floor(b1) *2.0 +1.0; vec4 sh = -vec4(lessThan(h, D.xxxx)); vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ; @@ -100,9 +100,6 @@ float simplexNoise(vec3 v) // Mix vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.); m = m * m; -//used to be 64. - return 58.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), + return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3,x3) ) ); } - - diff --git a/src/noise4D.glsl b/src/noise4D.glsl index cb4458e..e0da2ed 100644 --- a/src/noise4D.glsl +++ b/src/noise4D.glsl @@ -10,10 +10,10 @@ vec4 grad4(float j, vec4 ip) { - const vec4 ones = vec4(1.0,1.0,1.0,-1.0); + const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); vec4 p,s; - p.xyz = floor( fract (vec3(j) * ip.xyz) *pParam.w) * ip.z -1.0; + p.xyz = floor( fract (vec3(j) * ip.xyz) *pParam.w) * ip.z - 1.0; p.w = 1.5 - dot(abs(p.xyz), ones.xyz); s = vec4(lessThan(p, vec4(0.0))); p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; @@ -32,15 +32,17 @@ float simplexNoise(vec4 v) // Other corners #ifdef COLLAPSE_SORTNET - // Rank sorting contributed by Bill Licea-Kane, AMD (formerly ATI) + // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) vec4 i0; vec3 isX = step( x0.yzw, x0.xxx ); - i0.x = dot( isX, vec3( 1.0 ) ); + vec3 isYZ = step( x0.zww, x0.yyz ); +// i0.x = dot( isX, vec3( 1.0 ) ); + i0.x = isX.x + isX.y + isX.z; i0.yzw = 1.0 - isX; - vec3 isYZ = step( x0.zww, x0.yyz ); - i0.y += dot( isYZ.xy, vec2( 1.0 ) ); +// i0.y += dot( isYZ.xy, vec2( 1.0 ) ); + i0.y += isYZ.x + isYZ.y; i0.zw += 1.0 - isYZ.xy; i0.z += isYZ.z; @@ -51,7 +53,7 @@ float simplexNoise(vec4 v) vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); #else -// Force existance of strict total ordering in sort. +// Force existence of strict total ordering in sort. vec4 q0 = floor(x0 * 1024.0) + vec4( 0.0, 1.0/4.0, 2.0/4.0 , 3.0/4.0); vec4 q1; q1.xy = max(q0.xy, q0.zw); // x:z y:w @@ -88,11 +90,17 @@ float simplexNoise(vec4 v) + i.y + vec4(i1.y, i2.y, i3.y, 1.0 ), pParam.xyz) + i.x + vec4(i1.x, i2.x, i3.x, 1.0 ), pParam.xyz); // Gradients -// ( N*N*N points uniformly over a cube, mapped onto a 4-octohedron.) - vec4 ip = vec4(pParam.w) ; - ip.xy *= pParam.w ; - ip.x *= pParam.w ; - ip = vec4(1.0,1.0,1.0,2.0) / ip ; +// ( 7*7*6 points uniformly over a cube, mapped onto a 4-octahedron.) +// The permutation ring is 17*17, and that should be close +// to an even multiple of the number of points to avoid +// directional preferences for the noise field. +// 7*7*6 = 294, which is close to 17*17 = 289. + + vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; +// vec4 ip = vec4(pParam.w) ; +// ip.xy *= pParam.w ; +// ip.x *= pParam.w ; +// ip = vec4(1.0, 1.0, 1.0, 2.0) / ip ; vec4 p0 = grad4(j0, ip); vec4 p1 = grad4(j1.x, ip); @@ -113,7 +121,7 @@ float simplexNoise(vec4 v) vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0); m0 = m0 * m0; m1 = m1 * m1; - return 70.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) + return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ; } diff --git a/src/noiseStdLib.glsl b/src/noiseStdLib.glsl index f268b7a..a534bb8 100644 --- a/src/noiseStdLib.glsl +++ b/src/noiseStdLib.glsl @@ -23,7 +23,7 @@ PERMFUN(vec3) PERMFUN(vec4) #define TAYLOR_L07(X) X taylorInvSqrt(X r) { \ - return ( 0.83666002653408 + 0.7*0.85373472095314 - 0.85373472095314 * r ); } + return ( 1.195228609334394 + 0.7*0.85373472095314 - 0.85373472095314 * r ); } TAYLOR_L07(float) TAYLOR_L07(vec2)