by Linda Ting (lstting)
References:
Demo available here
Techniques used:
- 3D fractial brownian motion used to generate terrain height and fog/clouds (3D interpolation)
- Perlin noise used to generate temperature and precipitation maps, which were then used to classify 4 biomes
- Light position is modified at each frame to simulate day/night cycles (sinusoids)
- Base terrain is modified using worley noise depending on biome type
- Terrain modification by biome is animated with an easing function and parabolic signal
- Lambertian and Blinn-phong shading
User inputs:
- Temperature slider
- Precipitation slider
- Color picker
=======
Added features include:
- UI component to allow user to modify the color of the geometry being rendered
- Vertex shader that deforms the geometry over time
- Fragment shader that utilizes Fractal Brownian Motion and a cosine color palette
Demo available here.
- Check that the tools and build configuration we will be using for the class works.
- Start learning Typescript and WebGL2
- Practice implementing noise
(source: Ken Perlin)
Rather than cloning the homework repository, please fork the code into your own repository using the Fork
button in the upper-right hand corner of the Github UI. This will enable you to have your own personal repository copy of the code, and let you make a live demo (described later in this document).
-
Install Node.js. 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 dat.GUI, and glMatrix. -
Using a command terminal, run
npm install
in the root directory of your project. This will download all of those dependencies. -
Do either of the following (but we highly recommend the first one for reasons we will explain later).
a. Run
npm start
and then go tolocalhost:5660
in your web browserb. Run
npm run build
and then go opendist/index.html
in your web browser
One of the most important dependencies of our projects is Webpack. Webpack is a module bundler which allows us to write code in separate files and use import
s and export
s to load classes and functions for other files. It also allows us to preprocess code before compiling to a single file. We will be using Typescript for this course which is Javascript augmented with type annotations. Webpack will convert Typescript files to Javascript files on compilation and in doing so will also check for proper type-safety and usage. Read more about Javascript modules in the resources section below.
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.ts
. Here, you can make any changes you want, import functions from other files, etc. The reason that we 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.
We would suggest editing your project with Visual Studio Code https://code.visualstudio.com/. Microsoft develops it and Microsoft also develops Typescript so all of the features work nicely together. Sublime Text and installing the Typescript plugins should probably work as well.
- Take some time to go through the existing codebase so you can get an understanding of syntax and how the code is architected. Much of the code is designed to mirror the class structures used in CIS 460's OpenGL assignments, so it should hopefully be somewhat familiar.
- Take a look at the resources linked in the section below. Definitely read about Javascript modules and Typescript. The other links provide documentation for classes used in the code.
- Add a
Cube
class that inherits fromDrawable
and at the very least implement a constructor and itscreate
function. Then, add aCube
instance to the scene to be rendered. - Read the documentation for dat.GUI below. Update the existing GUI in
main.ts
with a parameter to alter the color passed tou_Color
in the Lambert shader. - Write a custom fragment shader that implements FBM, Worley Noise, or Perlin Noise based on 3D inputs (as opposed to the 2D inputs in the slides). This noise must be used to modify your fragment color. If your custom shader is particularly interesting, you'll earn some bonus points.
- Write a custom vertex shader that uses a trigonometric function (e.g.
sin
,tan
) to non-uniformly modify your cube's vertex positions over time. This will necessitate instantiating an incrementing variable in your Typescript code that you pass to your shader every tick. Refer to the base code's methods of passing variables to shaders if you are unsure how to do so. - Feel free to update any of the files when writing your code. The implementation of the
OpenGLRenderer
is currently very simple.
When you push changes to the master
branch of your repository on Github, a Github workflow will run automatically which builds your code and pushes the build to a new branch gh-pages
. The configuration file which handles this is located at .github/workflows/build-and-deploy.yml
. If you want to modify this, you can read more about workflows here.
Once your built code is pushed to gh-pages
, Github can automatically publish a live site. Configure that by:
-
Open the Settings tab of your repository in Github.
-
Scroll down to the Pages tab of the Settings (in the table on the left) and choose which branch to make the source for the deployed project. This should be the
gh-pages
branch which is automatically created after the first successful build of themaster
branch. -
Done! Now, any new commits on the
master
branch will be built and pushed togh-pages
. The project should be visible at http://username.github.io/repo-name.
To check if everything is on the right track:
-
Make sure the
gh-pages
branch of your repo has a files calledindex.html
,bundle.js
, andbundle.js.map
-
In the settings tab of the repo, under Pages, make sure it says your site is published at some url.
- Create a pull request to this repository with your completed code.
- Update README.md to contain a solid description of your project with a screenshot of some visuals, and a link to your live demo.
- Submit the link to your pull request on Canvas, and add a comment to your submission with a hyperlink to your live demo.
- Include a link to your live site.
- Javascript modules https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
- Typescript https://www.typescriptlang.org/docs/home.html
- dat.gui https://workshop.chromeexperiments.com/examples/gui/
- glMatrix http://glmatrix.net/docs/
- WebGL