Permalink
Browse files

Very slight optimizations

  • Loading branch information...
1 parent db450db commit e29258adfcbeb0a02315e2658e3f4e18d9896f60 stegu committed Aug 3, 2011
Showing with 44 additions and 44 deletions.
  1. +1 −1 benchmark/common/commonShader.frag
  2. +3 −3 src/classicnoise2D.glsl
  3. +9 −9 src/classicnoise3D.glsl
  4. +25 −25 src/classicnoise4D.glsl
  5. +1 −1 src/noise2D.glsl
  6. +1 −1 src/noise3D.glsl
  7. +4 −4 src/noise4D.glsl
@@ -12,5 +12,5 @@ varying VTYPE VNAME ;
void main( void )
{
float n = NOISEFUN(VNAME);
- gl_FragColor = vec4(0.5 + 0.5 * vec3(n, n, n), 1.0);
+ gl_FragColor = vec4(vec3(n * 0.5 + 0.5), 1.0);
}
View
@@ -2,7 +2,7 @@
// GLSL textureless classic 2D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
-// Version: 2011-04-10
+// Version: 2011-08-03
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
@@ -38,7 +38,7 @@ float cnoise(vec2 P)
vec4 i = permute(permute(ix) + iy);
- vec4 gx = 2.0 * fract(i / 41.0) - 1.0 ;
+ vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
vec4 gy = abs(gx) - 0.5 ;
vec4 tx = floor(gx + 0.5);
gx = gx - tx;
@@ -79,7 +79,7 @@ float pnoise(vec2 P, vec2 rep)
vec4 i = permute(permute(ix) + iy);
- vec4 gx = 2.0 * fract(i / 41.0) - 1.0 ;
+ vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
vec4 gy = abs(gx) - 0.5 ;
vec4 tx = floor(gx + 0.5);
gx = gx - tx;
View
@@ -2,7 +2,7 @@
// GLSL textureless classic 3D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
-// Version: 2011-04-10
+// Version: 2011-08-03
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
@@ -43,16 +43,16 @@ float cnoise(vec3 P)
vec4 ixy0 = permute(ixy + iz0);
vec4 ixy1 = permute(ixy + iz1);
- vec4 gx0 = ixy0 / 7.0;
- vec4 gy0 = fract(floor(gx0) / 7.0) - 0.5;
+ vec4 gx0 = ixy0 * (1.0 / 7.0);
+ vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = fract(gx0);
vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
vec4 sz0 = step(gz0, vec4(0.0));
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
- vec4 gx1 = ixy1 / 7.0;
- vec4 gy1 = fract(floor(gx1) / 7.0) - 0.5;
+ vec4 gx1 = ixy1 * (1.0 / 7.0);
+ vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = fract(gx1);
vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
vec4 sz1 = step(gz1, vec4(0.0));
@@ -113,16 +113,16 @@ float pnoise(vec3 P, vec3 rep)
vec4 ixy0 = permute(ixy + iz0);
vec4 ixy1 = permute(ixy + iz1);
- vec4 gx0 = ixy0 / 7.0;
- vec4 gy0 = fract(floor(gx0) / 7.0) - 0.5;
+ vec4 gx0 = ixy0 * (1.0 / 7.0);
+ vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = fract(gx0);
vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
vec4 sz0 = step(gz0, vec4(0.0));
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
- vec4 gx1 = ixy1 / 7.0;
- vec4 gy1 = fract(floor(gx1) / 7.0) - 0.5;
+ vec4 gx1 = ixy1 * (1.0 / 7.0);
+ vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = fract(gx1);
vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
vec4 sz1 = step(gz1, vec4(0.0));
View
@@ -2,7 +2,7 @@
// GLSL textureless classic 4D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
-// Version: 2011-04-10
+// Version: 2011-08-03
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
@@ -49,9 +49,9 @@ float cnoise(vec4 P)
vec4 ixy10 = permute(ixy1 + iw0);
vec4 ixy11 = permute(ixy1 + iw1);
- vec4 gx00 = ixy00 / 7.0;
- vec4 gy00 = floor(gx00) / 7.0;
- vec4 gz00 = floor(gy00) / 6.0;
+ vec4 gx00 = ixy00 * (1.0 / 7.0);
+ vec4 gy00 = floor(gx00) * (1.0 / 7.0);
+ vec4 gz00 = floor(gy00) * (1.0 / 6.0);
gx00 = fract(gx00) - 0.5;
gy00 = fract(gy00) - 0.5;
gz00 = fract(gz00) - 0.5;
@@ -60,9 +60,9 @@ float cnoise(vec4 P)
gx00 -= sw00 * (step(0.0, gx00) - 0.5);
gy00 -= sw00 * (step(0.0, gy00) - 0.5);
- vec4 gx01 = ixy01 / 7.0;
- vec4 gy01 = floor(gx01) / 7.0;
- vec4 gz01 = floor(gy01) / 6.0;
+ vec4 gx01 = ixy01 * (1.0 / 7.0);
+ vec4 gy01 = floor(gx01) * (1.0 / 7.0);
+ vec4 gz01 = floor(gy01) * (1.0 / 6.0);
gx01 = fract(gx01) - 0.5;
gy01 = fract(gy01) - 0.5;
gz01 = fract(gz01) - 0.5;
@@ -71,9 +71,9 @@ float cnoise(vec4 P)
gx01 -= sw01 * (step(0.0, gx01) - 0.5);
gy01 -= sw01 * (step(0.0, gy01) - 0.5);
- vec4 gx10 = ixy10 / 7.0;
- vec4 gy10 = floor(gx10) / 7.0;
- vec4 gz10 = floor(gy10) / 6.0;
+ vec4 gx10 = ixy10 * (1.0 / 7.0);
+ vec4 gy10 = floor(gx10) * (1.0 / 7.0);
+ vec4 gz10 = floor(gy10) * (1.0 / 6.0);
gx10 = fract(gx10) - 0.5;
gy10 = fract(gy10) - 0.5;
gz10 = fract(gz10) - 0.5;
@@ -82,9 +82,9 @@ float cnoise(vec4 P)
gx10 -= sw10 * (step(0.0, gx10) - 0.5);
gy10 -= sw10 * (step(0.0, gy10) - 0.5);
- vec4 gx11 = ixy11 / 7.0;
- vec4 gy11 = floor(gx11) / 7.0;
- vec4 gz11 = floor(gy11) / 6.0;
+ vec4 gx11 = ixy11 * (1.0 / 7.0);
+ vec4 gy11 = floor(gx11) * (1.0 / 7.0);
+ vec4 gz11 = floor(gy11) * (1.0 / 6.0);
gx11 = fract(gx11) - 0.5;
gy11 = fract(gy11) - 0.5;
gz11 = fract(gz11) - 0.5;
@@ -182,9 +182,9 @@ float cnoise(vec4 P, vec4 rep)
vec4 ixy10 = permute(ixy1 + iw0);
vec4 ixy11 = permute(ixy1 + iw1);
- vec4 gx00 = ixy00 / 7.0;
- vec4 gy00 = floor(gx00) / 7.0;
- vec4 gz00 = floor(gy00) / 6.0;
+ vec4 gx00 = ixy00 * (1.0 / 7.0);
+ vec4 gy00 = floor(gx00) * (1.0 / 7.0);
+ vec4 gz00 = floor(gy00) * (1.0 / 6.0);
gx00 = fract(gx00) - 0.5;
gy00 = fract(gy00) - 0.5;
gz00 = fract(gz00) - 0.5;
@@ -193,9 +193,9 @@ float cnoise(vec4 P, vec4 rep)
gx00 -= sw00 * (step(0.0, gx00) - 0.5);
gy00 -= sw00 * (step(0.0, gy00) - 0.5);
- vec4 gx01 = ixy01 / 7.0;
- vec4 gy01 = floor(gx01) / 7.0;
- vec4 gz01 = floor(gy01) / 6.0;
+ vec4 gx01 = ixy01 * (1.0 / 7.0);
+ vec4 gy01 = floor(gx01) * (1.0 / 7.0);
+ vec4 gz01 = floor(gy01) * (1.0 / 6.0);
gx01 = fract(gx01) - 0.5;
gy01 = fract(gy01) - 0.5;
gz01 = fract(gz01) - 0.5;
@@ -204,9 +204,9 @@ float cnoise(vec4 P, vec4 rep)
gx01 -= sw01 * (step(0.0, gx01) - 0.5);
gy01 -= sw01 * (step(0.0, gy01) - 0.5);
- vec4 gx10 = ixy10 / 7.0;
- vec4 gy10 = floor(gx10) / 7.0;
- vec4 gz10 = floor(gy10) / 6.0;
+ vec4 gx10 = ixy10 * (1.0 / 7.0);
+ vec4 gy10 = floor(gx10) * (1.0 / 7.0);
+ vec4 gz10 = floor(gy10) * (1.0 / 6.0);
gx10 = fract(gx10) - 0.5;
gy10 = fract(gy10) - 0.5;
gz10 = fract(gz10) - 0.5;
@@ -215,9 +215,9 @@ float cnoise(vec4 P, vec4 rep)
gx10 -= sw10 * (step(0.0, gx10) - 0.5);
gy10 -= sw10 * (step(0.0, gy10) - 0.5);
- vec4 gx11 = ixy11 / 7.0;
- vec4 gy11 = floor(gx11) / 7.0;
- vec4 gz11 = floor(gy11) / 6.0;
+ vec4 gx11 = ixy11 * (1.0 / 7.0);
+ vec4 gy11 = floor(gx11) * (1.0 / 7.0);
+ vec4 gz11 = floor(gy11) * (1.0 / 6.0);
gx11 = fract(gx11) - 0.5;
gy11 = fract(gy11) - 0.5;
gz11 = fract(gz11) - 0.5;
View
@@ -2,7 +2,7 @@
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
-// Lastmod : 20110410 (stegu)
+// Lastmod : 20110803 (stegu)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
//
View
@@ -3,7 +3,7 @@
// noise functions.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
-// Lastmod : 20110410 (stegu)
+// Lastmod : 20110803 (stegu)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
//
View
@@ -3,7 +3,7 @@
// noise functions.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
-// Lastmod : 20110410 (stegu)
+// Lastmod : 20110803 (stegu)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
//
@@ -76,9 +76,9 @@ float snoise(vec4 v)
vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );
// x0 = x0 - 0.0 + 0.0 * C.xxxx
- // x1 = x0 - i1 + 0.0 * C.xxxx
- // x2 = x0 - i2 + 0.0 * C.xxxx
- // x3 = x0 - i3 + 0.0 * C.xxxx
+ // x1 = x0 - i1 + 1.0 * C.xxxx
+ // x2 = x0 - i2 + 2.0 * C.xxxx
+ // x3 = x0 - i3 + 3.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
vec4 x1 = x0 - i1 + C.xxxx;
vec4 x2 = x0 - i2 + C.yyyy;

0 comments on commit e29258a

Please sign in to comment.