Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup, slight speedup, improved 4D uniformity

  • Loading branch information...
commit fa6321b8931a4f9a5c0bf7c513f889e3a8b4c12e 1 parent 46d926d
@stegu stegu authored
Showing with 44 additions and 37 deletions.
  1. +4 −3 benchmark/common/noisebench.c
  2. +20 −22 src/noise3D.glsl
  3. +20 −12 src/noise4D.glsl
View
7 benchmark/common/noisebench.c
@@ -372,9 +372,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, "Noise version: %s\n", NOISEVERSION);
// Create the shader object from two external GLSL source files
createShader(&programObject, VERTEXSHADERFILE2D, FRAGMENTSHADERFILE2D);
View
42 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 ;
@@ -104,5 +104,3 @@ float simplexNoise(vec3 v)
return 58.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}
-
-
View
32 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);
Please sign in to comment.
Something went wrong with that request. Please try again.