Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 37 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
# [HW1: Noise](https://github.com/CIS700-Procedural-Graphics/Project1-Noise)
![Alt text](/src/misc/header.png?raw=true "")
# Playing with Noise

## Getting Started
A small and rushed noisy animation that plays along the song Light Cycles by Shock One.

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.
This was done as an assignment for a procedural graphics class I took at the University of Pennsylvania.

2. Fork and clone [this repository](https://github.com/CIS700-Procedural-Graphics/Project1-Noise).
## [Try it!](https://mmerchante.github.io/playing-with-noise/)
## [VIDEO](https://www.youtube.com/watch?v=iShzHAF408I)

3. In the root directory of your project, run `npm install`. This will download all of those dependencies.
# How it works

4. Do either of the following (but I highly recommend the first one for reasons I will explain later).
The animation can be broken down in various pieces:

a. Run `npm start` and then go to `localhost:7000` in your web browser
## The sphere

b. Run `npm run build` and then go open `index.html` in your web browser
A 4D perlin noise driven by time and 3D position displaces the sphere along its normal. Its color is defined by a function of its displacement.

You should hopefully see the framework code with a 3D cube at the center of the screen!
## The initial sound disk
![Alt text](/src/misc/disk.png?raw=true "")
The disk's deformation is actually just another perlin noise. It's just a hack to trick the eye thinking it's the actual soundwave.

## Radial lines

## 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.
![Alt text](/src/misc/stripes.png?raw=true "")
Again, a premade mesh made in Maya is colored by its angle, and synchronized to the song.

## 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.
## Particle ocean

### npm install
`npm install` will install all dependencies into a folder called `node_modules`. That's about it.
Using the frequency of the song, a set of particles is displaced. However, because I didn't have any time to batch these particles in threejs, I just merged them in Maya.

### package.json
## Miscellaneous

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
There is an overlay and a background shader that add to the overall composition.

- 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
# UI

- three-orbit-controls: Handles mouse / touchscreen camera controls
There are some controls to tweak the noise, but most of the choreography code overrides it. If you want to play with the noise, you can enable the debug mode and see the raw perlin noise (which is 3D projected into 2D)

- 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
# Notes

- 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.
The particular Perlin implementation is not the most efficient by any chance. It's done in a way that's easy to read. If I have time I'll try to use the usual methods to optimize it.

- 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.
# References

- 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.
Stuff that helped do this!

### webpack.config.js
https://cmaher.github.io/posts/working-with-simplex-noise/

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`.
http://weber.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf

The other sections are just configuration settings for `webpack-dev-server` and setup for loading different types of files.
https://www.gamedev.net/topic/285533-2d-perlin-noise-gradient-noise-range--/

https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/perlin-noise-part-2

https://www.shadertoy.com/view/llBSWc

http://download.autodesk.com/us/maya/2011help/api/contrast_shader_8cpp-example.html

https://github.com/BrianSharpe/GPU-Noise-Lib/blob/master/gpu_noise_lib.glsl
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"gl-matrix": "^2.3.2",
"stats-js": "^1.0.0-alpha1",
"three": "^0.82.1",
"three-orbit-controls": "^82.1.0"
"three-orbit-controls": "^82.1.0",
"three-obj-loader": "^1.0.2"
},
"devDependencies": {
"babel-core": "^6.18.2",
Expand Down
2 changes: 2 additions & 0 deletions src/framework.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

const THREE = require('three');
const OrbitControls = require('three-orbit-controls')(THREE)
const OBJLoader = require('three-obj-loader')(THREE);

import Stats from 'stats-js'
import DAT from 'dat-gui'

Expand Down
Loading