From 53128b6a55adf4c21aa71135a911f306c573fe2b Mon Sep 17 00:00:00 2001 From: mccannd Date: Sun, 22 Jan 2017 18:49:43 -0500 Subject: [PATCH 1/5] 2D and 3D perlin --- npm-debug.log | 35 ++++++++ src/main.js | 39 ++++++++- src/shaders/adam-frag.glsl | 18 ++++- src/shaders/adam-vert.glsl | 159 ++++++++++++++++++++++++++++++++++++- 4 files changed, 243 insertions(+), 8 deletions(-) create mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..2c36485 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,35 @@ +0 info it worked if it ends with ok +1 verbose cli [ 'D:\\nodejs\\node.exe', +1 verbose cli 'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', +1 verbose cli 'start' ] +2 info using npm@3.10.10 +3 info using node@v6.9.4 +4 verbose run-script [ 'prestart', 'start', 'poststart' ] +5 info lifecycle @~prestart: @ +6 silly lifecycle @~prestart: no script for prestart, continuing +7 info lifecycle @~start: @ +8 verbose lifecycle @~start: unsafe-perm in lifecycle true +9 verbose lifecycle @~start: PATH: D:\nodejs\node_modules\npm\bin\node-gyp-bin;D:\Procedural\Project1-Noise\node_modules\.bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\cmd;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\share\git-tfs;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4;C:\Users\Daniel\AppData\Local\GitHub\lfs-amd64_1.3.1;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4\NativeBinaries\x86;C:\Users\Daniel\introcs\java\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\nodejs\;D:\MinGW\bin;C:\Users\Daniel\introcs\j3d\bin;C:\Users\Daniel\introcs\bin;C:\Users\Daniel\introcs\java\bin;D:\Qt\5.5\mingw492_32\bin;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Users\Daniel\AppData\Roaming\npm;C:\Program Files (x86)\MSBuild\14.0\bin\;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64;C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\ +10 verbose lifecycle @~start: CWD: D:\Procedural\Project1-Noise +11 silly lifecycle @~start: Args: [ '/d /s /c', 'webpack-dev-server --hot --inline' ] +12 verbose stack Error: kill ENOSYS +12 verbose stack at exports._errnoException (util.js:1022:11) +12 verbose stack at process.kill (internal/process.js:172:13) +12 verbose stack at process.listener (D:\nodejs\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:86:15) +12 verbose stack at emitNone (events.js:91:20) +12 verbose stack at process.emit (events.js:185:7) +12 verbose stack at processEmit (D:\nodejs\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32) +12 verbose stack at processEmit (D:\nodejs\node_modules\npm\node_modules\npm-registry-client\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32) +12 verbose stack at Signal.wrap.onsignal (internal/process.js:199:44) +13 verbose cwd D:\Procedural\Project1-Noise +14 error Windows_NT 10.0.14393 +15 error argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" +16 error node v6.9.4 +17 error npm v3.10.10 +18 error code ENOSYS +19 error errno ENOSYS +20 error syscall kill +21 error kill ENOSYS +22 error If you need help, you may report this error at: +22 error +23 verbose exit [ 1, true ] diff --git a/src/main.js b/src/main.js index 5fa221d..0b89b36 100644 --- a/src/main.js +++ b/src/main.js @@ -14,13 +14,48 @@ function onLoad(framework) { // var {scene, camera, renderer, gui, stats} = framework; // initialize a simple box and material - var box = new THREE.BoxGeometry(1, 1, 1); + var box = new THREE.IcosahedronBufferGeometry(1, 6); var adamMaterial = new THREE.ShaderMaterial({ uniforms: { image: { // Check the Three.JS documentation for the different allowed types and values type: "t", value: THREE.ImageUtils.loadTexture('./adam.jpg') + }, + gradients: {type: "v2v", value: [new THREE.Vector2(1.0, 0), new THREE.Vector2(-1.0, 0), + new THREE.Vector2(0, 1.0), new THREE.Vector2(0, -1.0), + new THREE.Vector2(0.7071, 0.7071), new THREE.Vector2(-0.7071, 0.7071), + new THREE.Vector2(0.7071, -0.7071), new THREE.Vector2(-0.7071, -0.7071)]}, + + gradients3d: {type: "v3v", value: [ + new THREE.Vector3(0.7071, 0.7071, 0), new THREE.Vector3(-0.7071, 0.7071, 0), new THREE.Vector3(0.7071, -0.7071, 0), + new THREE.Vector3(-0.7071, -0.7071, 0), new THREE.Vector3(0.7071, 0, 0.7071), new THREE.Vector3(-0.7071, 0, 0.7071), + new THREE.Vector3(0.7071, 0, -0.7071),new THREE.Vector3(-0.7071, 0, -0.7071), new THREE.Vector3(0, 0.7071, 0.7071), + new THREE.Vector3(0, -0.7071, 0.7071),new THREE.Vector3(0 ,0.7071, -0.7071),new THREE.Vector3(0, -0.7071, -0.7071)]}, + + table: { + type: "iv1", + value: [151,160,137,91,90,15, + 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, + 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, + 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, + 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, + 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, + 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, + 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, + 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, + 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, + 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, + 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, + 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]}, + time: { + type: "i", + value: 0 + }, + + seed: { + type: "i", + value: 97 } }, vertexShader: require('./shaders/adam-vert.glsl'), @@ -29,7 +64,7 @@ function onLoad(framework) { var adamCube = new THREE.Mesh(box, adamMaterial); // set camera position - camera.position.set(1, 1, 2); + camera.position.set(0, 0, 4); camera.lookAt(new THREE.Vector3(0,0,0)); scene.add(adamCube); diff --git a/src/shaders/adam-frag.glsl b/src/shaders/adam-frag.glsl index 64ca0e0..ee12a15 100644 --- a/src/shaders/adam-frag.glsl +++ b/src/shaders/adam-frag.glsl @@ -1,12 +1,22 @@ varying vec2 vUv; +varying float dprod; varying float noise; uniform sampler2D image; +varying vec3 test; -void main() { - - vec4 color = texture2D( image, vUv ); +vec3 lerpvec(in vec3 a, in vec3 b, in float t) +{ + float tx = t * b[0] + (1.0 - t) * a[0]; + float ty = t * b[1] + (1.0 - t) * a[1]; + float tz = t * b[2] + (1.0 - t) * a[2]; + return vec3(tx, ty, tz); +} - gl_FragColor = vec4( color.rgb, 1.0 ); +void main() { + float brightness = (noise + 1.0 / 2.0); + vec4 color = texture2D( image, vUv ); + vec3 newcol = lerpvec(vec3(0.4, 0.5, 0.9), vec3(brightness, brightness, brightness), 0.99); + gl_FragColor = vec4( newcol, 1.0 ); } \ No newline at end of file diff --git a/src/shaders/adam-vert.glsl b/src/shaders/adam-vert.glsl index e4b8cc0..b8ab08a 100644 --- a/src/shaders/adam-vert.glsl +++ b/src/shaders/adam-vert.glsl @@ -1,6 +1,161 @@ - varying vec2 vUv; +varying float dprod; +varying float noise; +uniform vec2 gradients[8]; +uniform vec3 gradients3d[12]; +uniform int time; +uniform int table[512]; +uniform int seed; + +varying vec3 test; + +float lerp(in float a, in float b, in float t) +{ + t = clamp(t, 0.0, 1.0); + float val = t * b + (1.0 - t) * a; + return val; +} + +vec3 vmod(in vec3 v, float m) +{ + return v - floor(v * (1.0 / m)) * m; +} + +// the ease curve by Ken Perlin, which gives smoother results for LERP +float ecurve(in float t) +{ + return (t * t * t * (t * (t * 6.0 - 15.0) + 10.0)); +} + +// randomly select a 3d gradient given a corner's coordinates +vec3 pickGradient(in int x, in int y, in int z) +{ + int hash = table[z + table[y + table[x]]]; + float t = float(hash) / 256.0; + return gradients3d[int(t * 12.0)]; +} + +float getnoise3d(in float x, in float y, in float z, in int numSamples) +{ + //vec3 vm = vmod(float(numSamples) * (vec3(x, y, z) + vec3(2, 2, 2)), float(numSamples)); + + // position within gradient grid + float xs = mod(x * float(numSamples) + 289.0, 255.0); + float ys = mod(y * float(numSamples) + 289.0, 255.0); + float zs = mod(z * float(numSamples) + 289.0, 255.0); + // lower bound of grid cube + int xlb = int(floor(xs)); + int ylb = int(floor(ys)); + int zlb = int(floor(zs)); + // 0 - 1 parameterization of grid cube + float tx = ecurve(xs - float(xlb)); + float ty = ecurve(ys - float(ylb)); + float tz = ecurve(zs - float(zlb)); + + // position in grid cube + float px = xs - floor(xs); + float py = ys - floor(ys); + float pz = zs - floor(zs); + + // sample each corner + + // back left bottom + float blb = dot(pickGradient(xlb, ylb, zlb), vec3(px, py, pz)); + // back right bottom + float brb = dot(pickGradient(xlb + 1, ylb, zlb), vec3(px - 1.0, py, pz)); + // front left bottom + float flb = dot(pickGradient(xlb, ylb, zlb + 1), vec3(px, py, pz - 1.0)); + // front right bottom + float frb = dot(pickGradient(xlb + 1, ylb, zlb + 1), vec3(px - 1.0, py, pz - 1.0)); + // back left top + float blt = dot(pickGradient(xlb, ylb + 1, zlb), vec3(px, py - 1.0, pz)); + // back right top + float brt = dot(pickGradient(xlb + 1, ylb + 1, zlb), vec3(px - 1.0, py - 1.0, pz)); + // front left top + float flt = dot(pickGradient(xlb, ylb + 1, zlb + 1), vec3(px, py - 1.0, pz - 1.0)); + // front right top + float frt = dot(pickGradient(xlb + 1, ylb + 1, zlb + 1), vec3(px - 1.0, py - 1.0, pz - 1.0)); + + + // trilinear sample + // left to right + float l1 = lerp(brb, frb, tz); + float l2 = lerp(blb, flb, tz); + float l3 = lerp(brt, frt, tz); + float l4 = lerp(blt, flt, tz); + // back to front + float l13 = lerp(l1, l3, ty); + float l24 = lerp(l2, l4, ty); + // bottom to top + return lerp (l24, l13, tx); +} + +float getnoise(in float u, in float v, in int numSamples) +{ + //position within gradient grid + float xs = u * float(numSamples); + float ys = v * float(numSamples); + + // lower bound of grid square + int xlb = int(floor(xs)); + int ylb = int(floor(ys)); + + // 0 - 1 parameterization of grid square + float tx = ecurve(xs - float(xlb)); + float ty = ecurve(ys - float(ylb)); + + + + // sample each corner: + // Lower Left + int hash3 = table[table[xlb + table[ylb]]]; + float proportion = float(hash3) / 256.0; + vec2 ll = gradients[int(proportion * 8.0)]; + + // Lower Right + hash3 = table[table[xlb + 1 + table[ylb]]]; + proportion = float(hash3) / 256.0; + vec2 lr = gradients[int(proportion * 8.0)]; + + // Upper Left + hash3 = table[table[xlb + table[ylb + 1]]]; + proportion = float(hash3) / 256.0; + vec2 ul = gradients[int(proportion * 8.0)]; + + // Upper Right + hash3 = table[table[xlb + 1 + table[ylb + 1]]]; + proportion = float(hash3) / 256.0; + vec2 ur = gradients[int(proportion * 8.0)]; + + float d1 = dot(ll, (vec2(xs - floor(xs), ys - floor(ys)))); + float d2 = dot(lr, (vec2(xs - floor(xs) - 1.0, ys - floor(ys)))); + float d3 = dot(ul, (vec2(xs - floor(xs), ys - floor(ys) - 1.0))); + float d4 = dot(ur, (vec2(xs - floor(xs) - 1.0, ys - floor(ys) - 1.0))); + + float d12 = lerp(d1, d2, tx); + float d34 = lerp(d3, d4, tx); + return lerp(d12, d34, ty); +} + + void main() { vUv = uv; - gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); + //noise = getnoise(uv[0], uv[1], 16); + //float samp = 2.0; + //for (int i = 0; i < 6; i++) { + // samp = 2.0 * samp; + // noise = noise + 4.0 / samp * getnoise(uv[0], uv[1], int(samp)); + //} + //noise = getnoise3d((normal.x + 1.0) / 2.0, (normal.y + 1.0) / 2.0, (normal.z + 1.0) / 2.0, 2); + float samp = 1.0; + for (int i = 0; i < 6; i++) { + samp = 2.0 * samp; + noise = noise + 2.0 / samp * getnoise3d((normal.x + 1.0) / 2.0, + (normal.y + 1.0) / 2.0, + (normal.z + 1.0) / 2.0, int(samp)); + } + dprod = dot(normalize(cameraPosition.xyz), normal.xyz); + clamp(dprod, 0.0, 1.0); + test = vec3((position.x + 1.0) / 2.0, (position.y + 1.0) / 2.0, (position.z + 1.0) / 2.0); + gl_Position = projectionMatrix * modelViewMatrix * vec4(noise * 0.2 * normal + position, 1.0 ); } \ No newline at end of file From 10b8f7a5763be1b70563c360d513735a2839bd76 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 24 Jan 2017 12:33:51 -0500 Subject: [PATCH 2/5] more tweaks to 3d, time --- npm-debug.log | 54 +++++++++++++++++------------ src/main.js | 51 ++++++++++++++++++---------- src/shaders/adam-frag.glsl | 7 ++-- src/shaders/adam-vert.glsl | 69 ++++++++++++++++++++------------------ 4 files changed, 105 insertions(+), 76 deletions(-) diff --git a/npm-debug.log b/npm-debug.log index 2c36485..592d9f1 100644 --- a/npm-debug.log +++ b/npm-debug.log @@ -12,24 +12,36 @@ 9 verbose lifecycle @~start: PATH: D:\nodejs\node_modules\npm\bin\node-gyp-bin;D:\Procedural\Project1-Noise\node_modules\.bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\cmd;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\share\git-tfs;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4;C:\Users\Daniel\AppData\Local\GitHub\lfs-amd64_1.3.1;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4\NativeBinaries\x86;C:\Users\Daniel\introcs\java\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\nodejs\;D:\MinGW\bin;C:\Users\Daniel\introcs\j3d\bin;C:\Users\Daniel\introcs\bin;C:\Users\Daniel\introcs\java\bin;D:\Qt\5.5\mingw492_32\bin;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Users\Daniel\AppData\Roaming\npm;C:\Program Files (x86)\MSBuild\14.0\bin\;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64;C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\ 10 verbose lifecycle @~start: CWD: D:\Procedural\Project1-Noise 11 silly lifecycle @~start: Args: [ '/d /s /c', 'webpack-dev-server --hot --inline' ] -12 verbose stack Error: kill ENOSYS -12 verbose stack at exports._errnoException (util.js:1022:11) -12 verbose stack at process.kill (internal/process.js:172:13) -12 verbose stack at process.listener (D:\nodejs\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:86:15) -12 verbose stack at emitNone (events.js:91:20) -12 verbose stack at process.emit (events.js:185:7) -12 verbose stack at processEmit (D:\nodejs\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32) -12 verbose stack at processEmit (D:\nodejs\node_modules\npm\node_modules\npm-registry-client\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32) -12 verbose stack at Signal.wrap.onsignal (internal/process.js:199:44) -13 verbose cwd D:\Procedural\Project1-Noise -14 error Windows_NT 10.0.14393 -15 error argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" -16 error node v6.9.4 -17 error npm v3.10.10 -18 error code ENOSYS -19 error errno ENOSYS -20 error syscall kill -21 error kill ENOSYS -22 error If you need help, you may report this error at: -22 error -23 verbose exit [ 1, true ] +12 silly lifecycle @~start: Returned: code: 3221225786 signal: null +13 info lifecycle @~start: Failed to exec start script +14 verbose stack Error: @ start: `webpack-dev-server --hot --inline` +14 verbose stack Exit status 3221225786 +14 verbose stack at EventEmitter. (D:\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (D:\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:877:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) +15 verbose pkgid @ +16 verbose cwd D:\Procedural\Project1-Noise +17 error Windows_NT 10.0.14393 +18 error argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" +19 error node v6.9.4 +20 error npm v3.10.10 +21 error code ELIFECYCLE +22 error @ start: `webpack-dev-server --hot --inline` +22 error Exit status 3221225786 +23 error Failed at the @ start script 'webpack-dev-server --hot --inline'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error webpack-dev-server --hot --inline +23 error You can get information on how to open an issue for this project with: +23 error npm bugs +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/src/main.js b/src/main.js index 0b89b36..ed9f92f 100644 --- a/src/main.js +++ b/src/main.js @@ -2,22 +2,7 @@ const THREE = require('three'); // older modules are imported like this. You shouldn't have to worry about this much import Framework from './framework' -// called after the scene loads -function onLoad(framework) { - var scene = framework.scene; - var camera = framework.camera; - var renderer = framework.renderer; - var gui = framework.gui; - var stats = framework.stats; - - // LOOK: the line below is synyatic sugar for the code above. Optional, but I sort of recommend it. - // var {scene, camera, renderer, gui, stats} = framework; - - // initialize a simple box and material - var box = new THREE.IcosahedronBufferGeometry(1, 6); - - var adamMaterial = new THREE.ShaderMaterial({ - uniforms: { +var sUniforms = { image: { // Check the Three.JS documentation for the different allowed types and values type: "t", value: THREE.ImageUtils.loadTexture('./adam.jpg') @@ -56,12 +41,41 @@ function onLoad(framework) { seed: { type: "i", value: 97 + }, + + + minOctave: { + type: "i", + value: 2 + }, + + maxOctave: { + type: "i", + value: 7 } - }, + } +var baseTime = Date.now(); + +// called after the scene loads +function onLoad(framework) { + var scene = framework.scene; + var camera = framework.camera; + var renderer = framework.renderer; + var gui = framework.gui; + var stats = framework.stats; + + // LOOK: the line below is synyatic sugar for the code above. Optional, but I sort of recommend it. + // var {scene, camera, renderer, gui, stats} = framework; + + // initialize a simple box and material + var box = new THREE.IcosahedronBufferGeometry(1, 6); + + var mat = new THREE.ShaderMaterial({ + uniforms: sUniforms, vertexShader: require('./shaders/adam-vert.glsl'), fragmentShader: require('./shaders/adam-frag.glsl') }); - var adamCube = new THREE.Mesh(box, adamMaterial); + var adamCube = new THREE.Mesh(box, mat); // set camera position camera.position.set(0, 0, 4); @@ -79,6 +93,7 @@ function onLoad(framework) { // called on frame updates function onUpdate(framework) { console.log(`the time is ${new Date()}`); + sUniforms.time.value = Date.now() - baseTime; } // when the scene is done initializing, it will call onLoad, then on frame updates, call onUpdate diff --git a/src/shaders/adam-frag.glsl b/src/shaders/adam-frag.glsl index ee12a15..d04148e 100644 --- a/src/shaders/adam-frag.glsl +++ b/src/shaders/adam-frag.glsl @@ -3,6 +3,7 @@ varying float dprod; varying float noise; uniform sampler2D image; +varying vec3 newNormal; varying vec3 test; vec3 lerpvec(in vec3 a, in vec3 b, in float t) @@ -14,9 +15,7 @@ vec3 lerpvec(in vec3 a, in vec3 b, in float t) } void main() { - float brightness = (noise + 1.0 / 2.0); - vec4 color = texture2D( image, vUv ); - vec3 newcol = lerpvec(vec3(0.4, 0.5, 0.9), vec3(brightness, brightness, brightness), 0.99); - gl_FragColor = vec4( newcol, 1.0 ); + float brightness = noise * 0.5 + 0.5; + gl_FragColor = vec4( brightness, brightness, brightness, 1.0 ); } \ No newline at end of file diff --git a/src/shaders/adam-vert.glsl b/src/shaders/adam-vert.glsl index b8ab08a..b5d94f9 100644 --- a/src/shaders/adam-vert.glsl +++ b/src/shaders/adam-vert.glsl @@ -7,6 +7,11 @@ uniform int time; uniform int table[512]; uniform int seed; +uniform int minOctave; +uniform int maxOctave; + +varying vec3 newNormal; + varying vec3 test; float lerp(in float a, in float b, in float t) @@ -16,11 +21,6 @@ float lerp(in float a, in float b, in float t) return val; } -vec3 vmod(in vec3 v, float m) -{ - return v - floor(v * (1.0 / m)) * m; -} - // the ease curve by Ken Perlin, which gives smoother results for LERP float ecurve(in float t) { @@ -37,12 +37,12 @@ vec3 pickGradient(in int x, in int y, in int z) float getnoise3d(in float x, in float y, in float z, in int numSamples) { - //vec3 vm = vmod(float(numSamples) * (vec3(x, y, z) + vec3(2, 2, 2)), float(numSamples)); + float tOffset = float(time) / 1000.0; // position within gradient grid - float xs = mod(x * float(numSamples) + 289.0, 255.0); - float ys = mod(y * float(numSamples) + 289.0, 255.0); - float zs = mod(z * float(numSamples) + 289.0, 255.0); + float xs = mod(x * float(numSamples) + tOffset, 255.0); + float ys = mod(y * float(numSamples) + tOffset, 255.0); + float zs = mod(z * float(numSamples) + tOffset, 255.0); // lower bound of grid cube int xlb = int(floor(xs)); int ylb = int(floor(ys)); @@ -65,28 +65,24 @@ float getnoise3d(in float x, in float y, in float z, in int numSamples) float brb = dot(pickGradient(xlb + 1, ylb, zlb), vec3(px - 1.0, py, pz)); // front left bottom float flb = dot(pickGradient(xlb, ylb, zlb + 1), vec3(px, py, pz - 1.0)); - // front right bottom float frb = dot(pickGradient(xlb + 1, ylb, zlb + 1), vec3(px - 1.0, py, pz - 1.0)); // back left top float blt = dot(pickGradient(xlb, ylb + 1, zlb), vec3(px, py - 1.0, pz)); - // back right top float brt = dot(pickGradient(xlb + 1, ylb + 1, zlb), vec3(px - 1.0, py - 1.0, pz)); - // front left top float flt = dot(pickGradient(xlb, ylb + 1, zlb + 1), vec3(px, py - 1.0, pz - 1.0)); - // front right top float frt = dot(pickGradient(xlb + 1, ylb + 1, zlb + 1), vec3(px - 1.0, py - 1.0, pz - 1.0)); // trilinear sample - // left to right + // back to front float l1 = lerp(brb, frb, tz); float l2 = lerp(blb, flb, tz); float l3 = lerp(brt, frt, tz); float l4 = lerp(blt, flt, tz); - // back to front + // bottom to top float l13 = lerp(l1, l3, ty); float l24 = lerp(l2, l4, ty); - // bottom to top + // left to right return lerp (l24, l13, tx); } @@ -137,25 +133,32 @@ float getnoise(in float u, in float v, in int numSamples) return lerp(d12, d34, ty); } +float multiOctave3d(in float x, in float y, in float z) +{ + int numSamples = int(pow(2.0, float(minOctave))); + float sample = 0.0; + int octaves = maxOctave - minOctave; + for (int i = 0; i <= 7; i++) { + + sample = sample + 2.0 * float(minOctave) / float(numSamples) * + getnoise3d(x * 0.5 + 0.5, + y * 0.5 + 0.5, + z * 0.5 + 0.5, numSamples); + numSamples = 2 * numSamples; + } + + return sample; +} + void main() { vUv = uv; - //noise = getnoise(uv[0], uv[1], 16); - //float samp = 2.0; - //for (int i = 0; i < 6; i++) { - // samp = 2.0 * samp; - // noise = noise + 4.0 / samp * getnoise(uv[0], uv[1], int(samp)); - //} - //noise = getnoise3d((normal.x + 1.0) / 2.0, (normal.y + 1.0) / 2.0, (normal.z + 1.0) / 2.0, 2); - float samp = 1.0; - for (int i = 0; i < 6; i++) { - samp = 2.0 * samp; - noise = noise + 2.0 / samp * getnoise3d((normal.x + 1.0) / 2.0, - (normal.y + 1.0) / 2.0, - (normal.z + 1.0) / 2.0, int(samp)); - } - dprod = dot(normalize(cameraPosition.xyz), normal.xyz); - clamp(dprod, 0.0, 1.0); + float samp = 1.0; + noise = multiOctave3d(position.x, position.y, position.z); + noise = sin(3.14159 * noise); + noise = noise * noise * 2.0 - 1.0; + float noise2 = multiOctave3d(sin(2.0 * 3.14159 * position.x), position.y, sin(2.0 * 3.14159 * position.z)); + test = vec3((position.x + 1.0) / 2.0, (position.y + 1.0) / 2.0, (position.z + 1.0) / 2.0); - gl_Position = projectionMatrix * modelViewMatrix * vec4(noise * 0.2 * normal + position, 1.0 ); + gl_Position = projectionMatrix * modelViewMatrix * vec4(noise * 0.4 * normal + position, 1.0 ); } \ No newline at end of file From f4e6bc3740dcfb281c272a6f9365a515d3f9a259 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 24 Jan 2017 15:01:51 -0500 Subject: [PATCH 3/5] fixed blinn, more lighting --- gradient1.jpg | Bin 0 -> 11012 bytes gradient2.jpg | Bin 0 -> 11302 bytes gradspec.jpg | Bin 0 -> 10758 bytes src/main.js | 7 ++++++- src/shaders/adam-frag.glsl | 13 ++++++++++-- src/shaders/adam-vert.glsl | 41 ++++++++++++++++++++++++++++--------- 6 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 gradient1.jpg create mode 100644 gradient2.jpg create mode 100644 gradspec.jpg diff --git a/gradient1.jpg b/gradient1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..fc3a63de9b4e0b45f31aea1db9b44e61d0adf1cb GIT binary patch literal 11012 zcmeG?d0bP+)^qR8O2QHn5EV6qRg@*{M3E(|3WBU|RYP(Kk!&V6fJ>`Vs;%0(RH<9t ztD=3{YDKGcL#^6c_qEnO(7IJ?u~u!hZN8Zs5`wj@-}`>=ug`%y_sltG&YU@O?kp!` zy=ZMEbQ!gp3IOu*Kqvr!1K5}+ARvUnKY(=uOd1BD9P93Y$6_JvJUHZ$0+@rI@G)Ug zG%SMfoaq|CXs^2lzE6U%&vyb4>|uYWsto0%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 100644 --- a/src/main.js +++ b/src/main.js @@ -5,8 +5,13 @@ import Framework from './framework' var sUniforms = { image: { // Check the Three.JS documentation for the different allowed types and values type: "t", - value: THREE.ImageUtils.loadTexture('./adam.jpg') + value: THREE.ImageUtils.loadTexture('./gradient2.jpg') }, + blinnimage: { // Check the Three.JS documentation for the different allowed types and values + type: "t", + value: THREE.ImageUtils.loadTexture('./gradspec.jpg') + }, + gradients: {type: "v2v", value: [new THREE.Vector2(1.0, 0), new THREE.Vector2(-1.0, 0), new THREE.Vector2(0, 1.0), new THREE.Vector2(0, -1.0), new THREE.Vector2(0.7071, 0.7071), new THREE.Vector2(-0.7071, 0.7071), diff --git a/src/shaders/adam-frag.glsl b/src/shaders/adam-frag.glsl index d04148e..a2415b2 100644 --- a/src/shaders/adam-frag.glsl +++ b/src/shaders/adam-frag.glsl @@ -2,9 +2,11 @@ varying vec2 vUv; varying float dprod; varying float noise; uniform sampler2D image; +uniform sampler2D blinnimage; varying vec3 newNormal; -varying vec3 test; +varying float lighting; +varying float shininess; vec3 lerpvec(in vec3 a, in vec3 b, in float t) { @@ -16,6 +18,13 @@ vec3 lerpvec(in vec3 a, in vec3 b, in float t) void main() { float brightness = noise * 0.5 + 0.5; - gl_FragColor = vec4( brightness, brightness, brightness, 1.0 ); + vec4 col = texture2D(image, vUv); + vec4 shine = texture2D(blinnimage, vec2(0.0, brightness)); + + vec3 lightCol = lerpvec(vec3(0.2, 0.2, 0.4), vec3(1.0, 1.0, 1.0), lighting); + + vec3 col2 = min(0.8 * shininess * shine.xyz + lightCol * col.xyz, vec3(1.0, 1.0, 1.0)); + vec3 aerialPersp = lightCol * vec3(0.5, 0.82, 0.95); + gl_FragColor = vec4( lerpvec(col2, aerialPersp, dprod), 1.0 ); } \ No newline at end of file diff --git a/src/shaders/adam-vert.glsl b/src/shaders/adam-vert.glsl index b5d94f9..25a2b66 100644 --- a/src/shaders/adam-vert.glsl +++ b/src/shaders/adam-vert.glsl @@ -11,8 +11,8 @@ uniform int minOctave; uniform int maxOctave; varying vec3 newNormal; - -varying vec3 test; +varying float shininess; +varying float lighting; float lerp(in float a, in float b, in float t) { @@ -37,7 +37,7 @@ vec3 pickGradient(in int x, in int y, in int z) float getnoise3d(in float x, in float y, in float z, in int numSamples) { - float tOffset = float(time) / 1000.0; + float tOffset = 4.0 * float(time) / 1000.0 / float(numSamples); // position within gradient grid float xs = mod(x * float(numSamples) + tOffset, 255.0); @@ -154,11 +154,32 @@ float multiOctave3d(in float x, in float y, in float z) void main() { vUv = uv; float samp = 1.0; - noise = multiOctave3d(position.x, position.y, position.z); - noise = sin(3.14159 * noise); - noise = noise * noise * 2.0 - 1.0; - float noise2 = multiOctave3d(sin(2.0 * 3.14159 * position.x), position.y, sin(2.0 * 3.14159 * position.z)); - - test = vec3((position.x + 1.0) / 2.0, (position.y + 1.0) / 2.0, (position.z + 1.0) / 2.0); - gl_Position = projectionMatrix * modelViewMatrix * vec4(noise * 0.4 * normal + position, 1.0 ); + noise = 1.2 * multiOctave3d(position.x, position.y, position.z); + //noise = sin(3.14159 * noise); + //noise = noise * noise * 2.0 - 1.0; + dprod = dot(normalize(cameraPosition.xyz), normal.xyz); + dprod = 1.0 - max(0.0, dprod); + dprod = dprod * dprod; + float noise2 = getnoise3d(position.x, position.y, position.z, 8); + float seaNoise = max(noise, 0.0); + + // texture is read through noise + vUv.y = noise * 0.5 + 0.5; + vUv.x = noise2 * 0.5 + 0.5; + + // apply shininess to water + vec3 lightDir = normalize(vec3(1, 1, 1)); + + + + vec3 halfVec = normalize(cameraPosition.xyz - position.xyz); + halfVec = normalize(halfVec + lightDir); + float blinn = max(0.0, dot(normal.xyz, halfVec)); + shininess = pow(blinn, 128.0); + + // diffuse lighting + lighting = max(dot(lightDir, normal.xyz), 0.0); + lighting = pow(lighting, 1.0 / 2.2); + + gl_Position = projectionMatrix * modelViewMatrix * vec4((seaNoise * 0.4)* normal + position, 1.0 ); } \ No newline at end of file From 79d468a04150f75b4bb0b2cbee31c22546b36a7c Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 24 Jan 2017 16:19:12 -0500 Subject: [PATCH 4/5] better light controls --- src/main.js | 26 +++++++++++++++++++++++--- src/shaders/adam-vert.glsl | 10 +++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index b0dc825..76521e6 100644 --- a/src/main.js +++ b/src/main.js @@ -2,12 +2,13 @@ const THREE = require('three'); // older modules are imported like this. You shouldn't have to worry about this much import Framework from './framework' +// shader uniforms are here so the time can be changed / accessed globally var sUniforms = { - image: { // Check the Three.JS documentation for the different allowed types and values + image: { // used for height color type: "t", value: THREE.ImageUtils.loadTexture('./gradient2.jpg') }, - blinnimage: { // Check the Three.JS documentation for the different allowed types and values + blinnimage: { // used for specular highlight type: "t", value: THREE.ImageUtils.loadTexture('./gradspec.jpg') }, @@ -57,9 +58,20 @@ var sUniforms = { maxOctave: { type: "i", value: 7 + }, + + light: { + type: "v3", + value: new THREE.Vector3(1, 1, 1) } } var baseTime = Date.now(); +var settings = { + time: true, + yaw: Math.PI / 4.0, + pitch: Math.PI / 4.0 +}; + // called after the scene loads function onLoad(framework) { @@ -93,12 +105,20 @@ function onLoad(framework) { gui.add(camera, 'fov', 0, 180).onChange(function(newVal) { camera.updateProjectionMatrix(); }); + gui.add(settings, "time"); + gui.add(settings, 'yaw', -Math.PI, Math.PI); + gui.add(settings, 'pitch', -Math.PI / 2.0, Math.PI / 2.0); + } // called on frame updates function onUpdate(framework) { console.log(`the time is ${new Date()}`); - sUniforms.time.value = Date.now() - baseTime; + if (settings.time) { + sUniforms.time.value = (Date.now() - baseTime); + } + sUniforms.light.value = new THREE.Vector3(Math.sin(settings.yaw) * Math.cos(settings.pitch) + , Math.sin(settings.pitch), Math.cos(settings.yaw) * Math.cos(settings.pitch)); } // when the scene is done initializing, it will call onLoad, then on frame updates, call onUpdate diff --git a/src/shaders/adam-vert.glsl b/src/shaders/adam-vert.glsl index 25a2b66..eca6b9d 100644 --- a/src/shaders/adam-vert.glsl +++ b/src/shaders/adam-vert.glsl @@ -10,6 +10,8 @@ uniform int seed; uniform int minOctave; uniform int maxOctave; +uniform vec3 light; + varying vec3 newNormal; varying float shininess; varying float lighting; @@ -38,7 +40,7 @@ vec3 pickGradient(in int x, in int y, in int z) float getnoise3d(in float x, in float y, in float z, in int numSamples) { float tOffset = 4.0 * float(time) / 1000.0 / float(numSamples); - + //tOffset = 3.0; // position within gradient grid float xs = mod(x * float(numSamples) + tOffset, 255.0); float ys = mod(y * float(numSamples) + tOffset, 255.0); @@ -133,6 +135,7 @@ float getnoise(in float u, in float v, in int numSamples) return lerp(d12, d34, ty); } +// wanted to have octaves controlled by UI, unfortunately for loop must have const var float multiOctave3d(in float x, in float y, in float z) { int numSamples = int(pow(2.0, float(minOctave))); @@ -168,10 +171,7 @@ void main() { vUv.x = noise2 * 0.5 + 0.5; // apply shininess to water - vec3 lightDir = normalize(vec3(1, 1, 1)); - - - + vec3 lightDir = normalize(light); vec3 halfVec = normalize(cameraPosition.xyz - position.xyz); halfVec = normalize(halfVec + lightDir); float blinn = max(0.0, dot(normal.xyz, halfVec)); From 44bed81b7d7f92b0d2ce291980db70f0fe50d714 Mon Sep 17 00:00:00 2001 From: mccannd Date: Tue, 24 Jan 2017 21:44:36 -0500 Subject: [PATCH 5/5] updated readme --- README.md | 133 +++++++------------------------------------------- npm-debug.log | 47 ------------------ 2 files changed, 17 insertions(+), 163 deletions(-) delete mode 100644 npm-debug.log diff --git a/README.md b/README.md index d4ef264..2f8a593 100644 --- a/README.md +++ b/README.md @@ -1,118 +1,19 @@ # [Project 1: Noise](https://github.com/CIS700-Procedural-Graphics/Project1-Noise) -## Objective - -Get comfortable with using three.js and its shader support and generate an interesting 3D, continuous surface using a multi-octave noise algorithm. - -## Getting Started - -1. [Install Node.js](https://nodejs.org/en/download/). Node.js is a JavaScript runtime. It basically allows you to run JavaScript when not in a browser. For our purposes, this is not necessary. The important part is that with it comes `npm`, the Node Package Manager. This allows us to easily declare and install external dependencies such as [three.js](https://threejs.org/), [dat.GUI](https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage), and [glMatrix](http://glmatrix.net/). Some other packages we'll be using make it significantly easier to develop your code and create modules for better code reuse and clarity. These tools make it _signficantly_ easier to write code in multiple `.js` files without globally defining everything. - -2. Fork and clone [this repository](https://github.com/CIS700-Procedural-Graphics/Project1-Noise). - -3. In the root directory of your project, run `npm install`. This will download all of those dependencies. - -4. Do either of the following (but I highly recommend the first one for reasons I will explain later). - - a. Run `npm start` and then go to `localhost:7000` in your web browser - - b. Run `npm run build` and then go open `index.html` in your web browser - - You should hopefully see the framework code with a 3D cube at the center of the screen! - - -## Developing Your Code -All of the JavaScript code is living inside the `src` directory. The main file that gets executed when you load the page as you may have guessed is `main.js`. Here, you can make any changes you want, import functions from other files, etc. The reason that I highly suggest you build your project with `npm start` is that doing so will start a process that watches for any changes you make to your code. If it detects anything, it'll automagically rebuild your project and then refresh your browser window for you. Wow. That's cool. If you do it the other way, you'll need to run `npm build` and then refresh your page every time you want to test something. - -## Publishing Your Code -We highly suggest that you put your code on GitHub. One of the reasons we chose to make this course using JavaScript is that the Web is highly accessible and making your awesome work public and visible can be a huge benefit when you're looking to score a job or internship. To aid you in this process, running `npm run deploy` will automatically build your project and push it to `gh-pages` where it will be visible at `username.github.io/repo-name`. - -## What is Actually Happening? -You can skip this part if you really want, but I highly suggest you read it. - -### npm install -`npm install` will install all dependencies into a folder called `node_modules`. That's about it. - -### package.json - -This is the important file that `npm` looks at. In it, you can see the commands it's using for the `start`, `build`, and `deploy` scripts mentioned above. You can also see all of the dependencies the project requires. I will briefly go through what each of these is. - - dat-gui: Gives us a nice and simple GUI for modifying variables in our program - - - gl-matrix: Useful library for linear algebra, much like glm - - - stats-js: Gives us a nice graph for timing things. We use it to report how long it takes to render each frame - - - three: Three.js is the main library we're using to draw stuff - - - three-orbit-controls: Handles mouse / touchscreen camera controls - - - babel-core, babel-loader, babel-preset-es2015: JavaScript is a a really fast moving language. It is constantly, constantly changing. Unfortunately, web browsers don't keep up nearly as quickly. Babel does the job of converting your code to a form that current browsers support. This allows us to use newer JavaScript features such as classes and imports without worrying about compatibility. - - - gh-pages-deploy: This is the library that automates publishing your code to Github - - - webpack: Webpack serves the role of packaging your project into a single file. Browsers don't actually support "importing" from other files, so without Webpack, to access data and functions in other files we would need to globally define EVERYTHING. This is an extremely bad idea. Webpack lets us use imports and develop code in separate files. Running `npm build` or `npm start` is what bundles all of your code together. - -- webpack-dev-server: This is an extremely useful tool for development. It essentially creates a file watcher and rebuilds your project whenever you make changes. It also injects code into your page that gets notified when these changes occur so it can automatically refresh your page. - - - webpack-glsl-loader: Webpack does much more than just JavaScript. We can use it to load glsl, css, images, etc. For whatever you want to import, somebody has probably made a webpack loader for it. - -### webpack.config.js - -This is the configuration file in webpack. The most important part is `entry` and `output`. These define the input and output for webpack. It will start from `entry`, explore all dependencies, and package them all into `output`. Here, the `output` is `bundle.js`. If you look in `index.html`, you can see that the page is loading `bundle.js`, not `main.js`. - -The other sections are just configuration settings for `webpack-dev-server` and setup for loading different types of files. - -## Setting up a shader - -Using the provided framework code, create a new three.js material which references a vertex and fragment shader. Look at the adamMaterial for reference. It should reference at least one uniform variable (you'll need a time variable to animate your mesh later on). - -Create [an icosahedron](https://threejs.org/docs/index.html#Reference/Geometries/IcosahedronBufferGeometry), instead of the default cube geometry provided in the scene. Test your shader setup by applying the material to the icosahedron and color the mesh in the fragment shader using the normals' XYZ components as RGB. - -Note that three.js automatically injects several uniform and attribute variables into your shaders by default; they are listed in the [documentation](https://threejs.org/docs/api/renderers/webgl/WebGLProgram.html) for three.js's WebGLProgram class. - -## Noise Generation - -In the shader, write a 3D multi-octave lattice-value noise function that takes three input parameters and generates output in a controlled range, say [0,1] or [-1, 1]. This will require the following steps. - -1. Write several (for however many octaves of noise you want) basic pseudo-random 3D noise functions (the hash-like functions we discussed in class). It's fine to reference one from the slides or elsewhere on the Internet. Again, this should just be a set of math operations, often using large prime numbers to random-looking output from three input parameters. - -2. Write an interpolation function. Lerp is fine, but for better results, we suggest cosine interpolation. - -3. (Optional) Write a smoothing function that will average the results of the noise value at some (x, y, z) with neighboring values, that is (x+-1, y+-1, z+-1). - -4. Write an 'interpolate noise' function that takes some (x, y, z) point as input and produces a noise value for that point by interpolating the surrounding lattice values (for 3D, this means the surrounding eight 'corner' points). Use your interpolation function and pseudo-random noise generator to accomplish this. - -5. Write a multi-octave noise generation function that sums multiple noise functions together, with each subsequent noise function increasing in frequency and decreasing in amplitude. You should use the interpolate noise function you wrote previously to accomplish this, as it generates a single octave of noise. The slides contain pseudocode for writing your multi-octave noise function. - - -## Noise Application - -View your noise in action by applying it as a displacement on the surface of your icosahedron, giving your icosahedron a bumpy, cloud-like appearance. Simply take the noise value as a height, and offset the vertices along the icosahedron's surface normals. You are, of course, free to alter the way your noise perturbs your icosahedron's surface as you see fit; we are simply recommending an easy way to visualize your noise. You could even apply a couple of different noise functions to perturb your surface to make it even less spherical. - -In order to animate the vertex displacement, use time as the third dimension or as some offset to the (x, y, z) input to the noise function. Pass the current time since start of program as a uniform to the shaders. - -For both visual impact and debugging help, also apply color to your geometry using the noise value at each point. There are several ways to do this. For example, you might use the noise value to create UV coordinates to read from a texture (say, a simple gradient image), or just compute the color by hand by lerping between values. - -## Interactivity - -Using dat.GUI and the examples provided in the reference code, make some aspect of your demo an interactive variable. For example, you could add a slider to adjust the strength or scale of the noise, change the number of noise octaves, etc. - -## For the overachievers (extra credit) - -- More interactivity (easy): pretty self-explanatory. Make more aspects of your demo interactive by adding more controlable variables in the GUI. - -- Custom mesh (easy): Figure out how to import a custom mesh rather than using an icosahedron for a fancy-shaped cloud. - -- Mouse interactivity (medium): Find out how to get the current mouse position in your scene and use it to deform your cloud, such that users can deform the cloud with their cursor. - -- Music (hard): Figure out a way to use music to drive your noise animation in some way, such that your noise cloud appears to dance. - -## Submission - -- Update README.md to contain a solid description of your project - -- Publish your project to gh-pages. `npm run deploy`. It should now be visible at http://username.github.io/repo-name - -- Create a [pull request](https://help.github.com/articles/creating-a-pull-request/) to this repository, and in the comment, include a link to your published project. - -- Submit the link to your pull request on Canvas. \ No newline at end of file +#LINK TO THE DEMO: #[HERE](https://mccannd.github.io/Project1-Noise/) + +Usage: +The checkbox labelled 'time' turns animation on and off +Light direction is controlled by "pitch" and "yaw" + +Description and features: +Generates a shifting planetoid using improved Perlin Noise. +Height is determined by multi-octave noise, but clamped to not fall below a certain height. +Color is read from a 2D texture. V is height, U is an additional noise sample. +Blinn-Phong shading on the material, with a multiplier read from a 2D texture. This should only apply on the water / spherical portion +Simple lighting of the sphere. The mountains are not bump mapped. +Aerial perspective / atmosphere: geographic features farther away from the view will be colored by the atmosphere. + +Notes on the code: +The hash table and ease function are from Ken Perlin's implementation. +There are a few vestigial uniforms, such as seed and max octave. My plan was to use min and max octave with UI integration. Alas, the for loop must be constant. diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 592d9f1..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,47 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ 'D:\\nodejs\\node.exe', -1 verbose cli 'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', -1 verbose cli 'start' ] -2 info using npm@3.10.10 -3 info using node@v6.9.4 -4 verbose run-script [ 'prestart', 'start', 'poststart' ] -5 info lifecycle @~prestart: @ -6 silly lifecycle @~prestart: no script for prestart, continuing -7 info lifecycle @~start: @ -8 verbose lifecycle @~start: unsafe-perm in lifecycle true -9 verbose lifecycle @~start: PATH: D:\nodejs\node_modules\npm\bin\node-gyp-bin;D:\Procedural\Project1-Noise\node_modules\.bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\cmd;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\bin;C:\Users\Daniel\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\usr\share\git-tfs;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4;C:\Users\Daniel\AppData\Local\GitHub\lfs-amd64_1.3.1;C:\Users\Daniel\AppData\Local\Apps\2.0\YOA1XVNR.8H2\8AP2TGYV.2O2\gith..tion_317444273a93ac29_0003.0003_665ccbdbd3c2d8d4\NativeBinaries\x86;C:\Users\Daniel\introcs\java\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\nodejs\;D:\MinGW\bin;C:\Users\Daniel\introcs\j3d\bin;C:\Users\Daniel\introcs\bin;C:\Users\Daniel\introcs\java\bin;D:\Qt\5.5\mingw492_32\bin;C:\Users\Daniel\AppData\Local\Microsoft\WindowsApps;C:\Users\Daniel\AppData\Roaming\npm;C:\Program Files (x86)\MSBuild\14.0\bin\;C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64;C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\ -10 verbose lifecycle @~start: CWD: D:\Procedural\Project1-Noise -11 silly lifecycle @~start: Args: [ '/d /s /c', 'webpack-dev-server --hot --inline' ] -12 silly lifecycle @~start: Returned: code: 3221225786 signal: null -13 info lifecycle @~start: Failed to exec start script -14 verbose stack Error: @ start: `webpack-dev-server --hot --inline` -14 verbose stack Exit status 3221225786 -14 verbose stack at EventEmitter. (D:\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at EventEmitter.emit (events.js:191:7) -14 verbose stack at ChildProcess. (D:\nodejs\node_modules\npm\lib\utils\spawn.js:40:14) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at ChildProcess.emit (events.js:191:7) -14 verbose stack at maybeClose (internal/child_process.js:877:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5) -15 verbose pkgid @ -16 verbose cwd D:\Procedural\Project1-Noise -17 error Windows_NT 10.0.14393 -18 error argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start" -19 error node v6.9.4 -20 error npm v3.10.10 -21 error code ELIFECYCLE -22 error @ start: `webpack-dev-server --hot --inline` -22 error Exit status 3221225786 -23 error Failed at the @ start script 'webpack-dev-server --hot --inline'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error webpack-dev-server --hot --inline -23 error You can get information on how to open an issue for this project with: -23 error npm bugs -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ]