Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nathan's awesome pull request #20

Open
wants to merge 108 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
ff5294b
Now we have a nice, pleasant wave! But it doesn't animate yet.
Nov 3, 2013
214a186
Got some motion going! Now I just have to color it to be able to make
Nov 3, 2013
d666939
We haz color!
Nov 3, 2013
b613f9f
Got simplex noise to work!
Nov 3, 2013
bbb1739
Got the night color working
Nov 3, 2013
3e5c3b3
Added some day/night blending. Doesn't work well though
Nov 3, 2013
77d69fd
Got a nice, smooth, day/night transition going
Nov 3, 2013
b7c0f39
Got a NIGHT_EPSILON that actually looks good...
Nov 3, 2013
40440a9
Now we added specular map to the globe.
Nov 4, 2013
f9a1b7e
Static clouds working. They don't scroll yet, and we also haven't
Nov 4, 2013
a86a516
Black clouds working.
Nov 4, 2013
66b4f66
Added diffuse shading on the clouds
Nov 4, 2013
8c811cd
Merge remote-tracking branch 'upstream/master'
Nov 4, 2013
9de8d9e
Normal map almost works. I don't think we should be applying the normal
Nov 5, 2013
1b44465
Now the clouds aren't affected by the bump-mapping.
Nov 5, 2013
65eac0d
Added rim lighting.
Nov 5, 2013
73a3e66
Added heightmap. Last commit before I try to do terrain rendering.
Nov 7, 2013
d0a88fc
Added terrain renderer.
Nov 7, 2013
eb7e375
Code for texture... I think works?
Nov 7, 2013
bf616b0
Now we've put in the basic parts to get the texture and bind the
Nov 7, 2013
329c76b
Well... we have a flat plane. No cool results yet.
Nov 7, 2013
cdc3eb4
I don't think we are reading the texture in properly...
Nov 7, 2013
c26fdb2
Changed texture size to a power of 2
Nov 7, 2013
b5a4a00
Back at square one. Now using Mozilla's tutorial to inject textures
Nov 7, 2013
dc8b2c0
Proof that positions are between 0 and 1.
Nov 7, 2013
c4d1960
TEH HEIGHT FIELD IS WORKING ZOMG
Nov 7, 2013
9ac000d
Got height field to rotate!
Nov 7, 2013
8537a7f
Got Mt. Fuji Working!
Nov 7, 2013
9d9f700
Reinier working... and now it looks like real terrain!
Nov 7, 2013
0d4de70
Got a properly-scaled Mt. Fuji working
Nov 7, 2013
d093af5
Now we can toggle the rotation direction...
Nov 7, 2013
18b4eeb
All the parts are in place for loading two height fields. Now I just
Nov 7, 2013
694a80b
Toggling between the two textures as height maps works!
Nov 7, 2013
d65412d
Halfway blend between the two height fields is working....
Nov 7, 2013
8279942
Renamed "rotateDir" to "blendDir". Also, added clamping to heightBlend.
Nov 7, 2013
8899b93
Added and centered the "Mt. Fuji" and "Mt. Rainier" buttons.
Nov 7, 2013
3411900
Code is down but there iz no blending
Nov 7, 2013
59e17b6
Blending between fragments works! WOO HOO!!!
Nov 7, 2013
55bcb11
Dark background a-go-go!
Nov 7, 2013
5e9495d
Got rid of unnecessary uniform.
Nov 7, 2013
76f73dd
I think my GET request actualy worked!
Nov 8, 2013
507dd8c
I think that the GET request succeeded?
Nov 8, 2013
9afd82f
We get a response back but there's nothing in it...
Nov 8, 2013
00d2d26
ZOMG WE HAZ THE LATITUDE IN THE CONSOLE
Nov 8, 2013
55acc64
JSON working in my javascript file!!! YAY
Nov 8, 2013
3816038
Added a part3 to add the orbiting ISS visualization.
Nov 8, 2013
8e65eeb
We haz a new initializeSphere() function that makes the globe smaller...
Nov 8, 2013
a574f15
Allright, now we put the vertex attributes for sphere2 in a different
Nov 8, 2013
c26cc3b
Allright! We were able to initialize a separate shader for the other
Nov 8, 2013
fea6e92
Named programs as globe_program and iss_program
Nov 8, 2013
ce3da3e
We wre able to recenter the small globe which represents the ISS. Now we
Nov 8, 2013
6015b84
Moved initializeSphere into the animation loop... not the best idea,
Nov 8, 2013
e33512b
We haz two models! YAY!
Nov 8, 2013
7bf90f1
Got the "ISS" to orbit at a reasonable "altitude"
Nov 8, 2013
73cd8ae
Now we finally got the ISS coordinates out of the JSON function
Nov 8, 2013
ce18eaa
Now I got spherical coordinates working properly.
Nov 9, 2013
2019839
We are at (0,0) latitude and longitude! YAY!
Nov 9, 2013
73313d7
I think I got the coordinates to work correctly in Degrees North and
Nov 9, 2013
31db09a
Iss location is now plugged in!
Nov 9, 2013
8df372d
Now we update once every five seconds! YAYNESS!
Nov 9, 2013
e4ab952
Got mah square working!
Nov 9, 2013
9e71d20
Scaled the square to a more reasonable size.
Nov 9, 2013
9db20ab
Got the patch to face the camera...
Nov 9, 2013
802b25a
Recentered the square so the rotation bug is slightly more palatable
Nov 9, 2013
31fddeb
Ready to plug in the ISS shader (which just draws a transparent texture)
Nov 9, 2013
342472a
ISS working with a separate fragment shader. YAY!!!
Nov 9, 2013
bcb7249
ISS LOGO IS WORKING!!! WOO HOO!!!
Nov 9, 2013
0bab738
ISS transparency, WORKING!
Nov 9, 2013
b52257d
Got the day/night on the globe to reflect the Earth's real day/night
Nov 9, 2013
27ef446
Incorporated minutes and seconds into the day/night calculation.
Nov 9, 2013
0330330
We have drawn our single line!
Nov 9, 2013
83e572c
ISS is just over south america
Nov 9, 2013
c66dcf4
Got num verts working correctly again!
Nov 9, 2013
ce33a9f
Added law for number of vertices for trail
Nov 9, 2013
e91933a
Allright, I think that the array for trail drawing is ready
Nov 9, 2013
41d7899
Trail draws! YAY!
Nov 9, 2013
a1f8513
Fixed the depth-ordering problem by drawing the ISS logo AFTER drawing
Nov 9, 2013
6b0380b
Last commit before performance testing.
Nov 9, 2013
1e48903
Fixed globe in part 2
Nov 9, 2013
542a1f8
Now we got rid of unnecessary shader initialization
Nov 9, 2013
27d117c
Well, now we initialize the shader 3 more intelligently
Nov 9, 2013
6e955b3
NOW it's much faster because we don't initialize the stupid shaders each
Nov 9, 2013
6f543e5
Last commit before gh-pages.
Nov 9, 2013
66a60a4
Updated README for the first time
Nov 9, 2013
a994e4e
Updated heading
Nov 9, 2013
839f2ce
Updated title again
Nov 9, 2013
09466ac
Added links and bullets to README
Nov 9, 2013
21fd836
Fixed bullets and links
Nov 9, 2013
7e336f1
Added our first screenshot
Nov 9, 2013
9403c0c
Added more links, plus some glsl
Nov 9, 2013
a39c528
Edited GLSL part
Nov 9, 2013
57fff09
Added glsl
Nov 9, 2013
a461c04
Got rid of the color adding thing
Nov 9, 2013
ae72821
Added links to the other wave demos
Nov 9, 2013
89ffe6e
Updated frag globe to be centered, plus back bg
Nov 9, 2013
1014264
Added the day/night calculation to readme
Nov 9, 2013
9ef927e
Added performance analysis.
Nov 9, 2013
efc5d75
Adjusted spacing around performance analysis
Nov 9, 2013
360fd14
Added link to video of the ISS tracker
Nov 9, 2013
fe142c4
Got rid of those pesky periods
Nov 9, 2013
6796c74
Fixed links to demos (hopefully)
Nov 9, 2013
6f03c35
Added better disclaimer
Nov 9, 2013
6b468dc
fixed more broken URLs
Nov 9, 2013
16f19a0
Update README.md
Nov 9, 2013
e47efe1
Update README.md
Nov 9, 2013
dc7bbde
Update README.md
Nov 9, 2013
beb1bad
Update README.md
Nov 9, 2013
1578222
Update README.md
Nov 9, 2013
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
Prev Previous commit
Next Next commit
Updated README for the first time
  • Loading branch information
Nathan Marshak committed Nov 9, 2013

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 66a60a4098f28fb1959b8a66e77d981f6bef8909
374 changes: 6 additions & 368 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,373 +1,11 @@
-------------------------------------------------------------------------------
CIS565: Project 5: WebGL
-------------------------------------------------------------------------------
Fall 2013
-------------------------------------------------------------------------------
Due Friday 11/08/2013
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
NOTE:
-------------------------------------------------------------------------------
This project requires any graphics card with support for a modern OpenGL
pipeline. Any AMD, NVIDIA, or Intel card from the past few years should work
fine, and every machine in the SIG Lab and Moore 100 is capable of running
this project.

This project also requires a WebGL capable browser. The project is known to
have issues with Chrome on windows, but Firefox seems to run it fine.

-------------------------------------------------------------------------------
INTRODUCTION:
-------------------------------------------------------------------------------
In this project, you will get introduced to the world of GLSL in two parts:
vertex shading and fragment shading. The first part of this project is the
Image Processor, and the second part of this project is a Wave Vertex Shader.

In the first part of this project, you will implement a GLSL vertex shader as
part of a WebGL demo. You will create a dynamic wave animation using code that
runs entirely on the GPU.

In the second part of this project, you will implement a GLSL fragment shader
to render an interactive globe in WebGL. This will include texture blending,
bump mapping, specular masking, and adding a cloud layer to give your globe a
uniquie feel.

-------------------------------------------------------------------------------
CONTENTS:
-------------------------------------------------------------------------------
The Project4 root directory contains the following subdirectories:

* part1/ contains the base code for the Wave Vertex Shader.
* part2/ contains the base code for the Globe Fragment Shader.
* resources/ contains the screenshots found in this readme file.

-------------------------------------------------------------------------------
PART 1 REQUIREMENTS:
-------------------------------------------------------------------------------

In Part 1, you are given code for:

* Drawing a VBO through WebGL
* Javascript code for interfacing with WebGL
* Functions for generating simplex noise

You are required to implement the following:

* A sin-wave based vertex shader:

![Example sin wave grid](resources/sinWaveGrid.png)

* A simplex noise based vertex shader:

![Example simplex noise wave grid](resources/oceanWave.png)

* One interesting vertex shader of your choice

-------------------------------------------------------------------------------
PART 1 WALKTHROUGH:
-------------------------------------------------------------------------------
**Sin Wave**

* For this assignment, you will need the latest version of Firefox.
* Begin by opening index.html. You should see a flat grid of black and white
lines on the xy plane:

![Example boring grid](resources/emptyGrid.png)

* In this assignment, you will animate the grid in a wave-like pattern using a
vertex shader, and determine each vertex’s color based on its height, as seen
in the example in the requirements.
* The vertex and fragment shader are located in script tags in `index.html`.
* The JavaScript code that needs to be modified is located in `index.js`.
* Required shader code modifications:
* Add a float uniform named u_time.
* Modify the vertex’s height using the following code:

```glsl
float s_contrib = sin(position.x*2.0*3.14159 + u_time);
float t_contrib = cos(position.y*2.0*3.14159 + u_time);
float height = s_contrib*t_contrib;
```

* Use the GLSL mix function to blend together two colors of your choice based
on the vertex’s height. The lowest possible height should be assigned one
color (for example, `vec3(1.0, 0.2, 0.0)`) and the maximum height should be
another (`vec3(0.0, 0.8, 1.0)`). Use a varying variable to pass the color to
the fragment shader, where you will assign it `gl_FragColor`.

* Required JavaScript code modifications:
* A floating-point time value should be increased every animation step.
Hint: the delta should be less than one.
* To pass the time to the vertex shader as a uniform, first query the location
of `u_time` using `context.getUniformLocation` in `initializeShader()`.
Then, the uniform’s value can be set by calling `context.uniform1f` in
`animate()`.

**Simplex Wave**

* Now that you have the sin wave working, create a new copy of `index.html`.
Call it `index_simplex.html`, or something similar.
* Open up `simplex.vert`, which contains a compact GLSL simplex noise
implementation, in a text editor. Copy and paste the functions included
inside into your `index_simplex.html`'s vertex shader.
* Try changing s_contrib and t_contrib to use simplex noise instead of sin/cos
functions with the following code:

```glsl
vec2 simplexVec = vec2(u_time, position);
float s_contrib = snoise(simplexVec);
float t_contrib = snoise(vec2(s_contrib,u_time));
```

**Wave Of Your Choice**

* Create another copy of `index.html`. Call it `index_custom.html`, or
something similar.
* Implement your own interesting vertex shader! In your README.md with your
submission, describe your custom vertex shader, what it does, and how it
works.

-------------------------------------------------------------------------------
PART 2 REQUIREMENTS:
-------------------------------------------------------------------------------
In Part 2, you are given code for:

* Reading and loading textures
* Rendering a sphere with textures mapped on
* Basic passthrough fragment and vertex shaders
* A basic globe with Earth terrain color mapping
* Gamma correcting textures
* javascript to interact with the mouse
* left-click and drag moves the camera around
* right-click and drag moves the camera in and out

You are required to implement:

* Bump mapped terrain
* Rim lighting to simulate atmosphere
* Night-time lights on the dark side of the globe
* Specular mapping
* Moving clouds

You are also required to pick one open-ended effect to implement:

* Procedural water rendering and animation using noise
* Shade based on altitude using the height map
* Cloud shadows via ray-tracing through the cloud map in the fragment shader
* Orbiting Moon with texture mapping and shadow casting onto Earth
* Draw a skybox around the entire scene for the stars.
* Your choice! Email Liam and Patrick to get approval first

Finally in addition to your readme, you must also set up a gh-pages branch
(explained below) to expose your beautiful WebGL globe to the world.

Some examples of what your completed globe renderer will look like:

![Completed globe, day side](resources/globe_day.png)

Figure 0. Completed globe renderer, daylight side.

![Completed globe, twilight](resources/globe_twilight.png)

Figure 1. Completed globe renderer, twilight border.

![Completed globe, night side](resources/globe_night.png)

Figure 2. Completed globe renderer, night side.

-------------------------------------------------------------------------------
PART 2 WALKTHROUGH:
-------------------------------------------------------------------------------

Open part2/frag_globe.html in Firefox to run it. You’ll see a globe
with Phong lighting like the one in Figure 3. All changes you need to make
will be in the fragment shader portion of this file.

![Initial globe](resources/globe_initial.png)

Figure 3. Initial globe with diffuse and specular lighting.

**Night Lights**

The backside of the globe not facing the sun is completely black in the
initial globe. Use the `diffuse` lighting component to detect if a fragment
is on this side of the globe, and, if so, shade it with the color from the
night light texture, `u_Night`. Do not abruptly switch from day to night;
instead use the `GLSL mix` function to smoothly transition from day to night
over a reasonable period. The resulting globe will look like Figure 4.
Consider brightening the night lights by multiplying the value by two.

The base code shows an example of how to gamma correct the nighttime texture:

```glsl
float gammaCorrect = 1/1.2;
vec4 nightColor = pow(texture2D(u_Night, v_Texcoord), vec4(gammaCorrect));
```

Feel free to play with gamma correcting the night and day textures if you
wish. Find values that you think look nice!

![Day/Night without specular mapping](resources/globe_nospecmap.png)

Figure 4. Globe with night lights and day/night blending at dusk/dawn.

**Specular Map**

Our day/night color still shows specular highlights on landmasses, which
should only be diffuse lit. Only the ocean should receive specular highlights.
Use `u_EarthSpec` to determine if a fragment is on ocean or land, and only
include the specular component if it is in ocean.

![Day/Night with specular mapping](resources/globe_specmap.png)

Figure 5. Globe with specular map. Compare to Figure 4. Here, the specular
component is not used when shading the land.

**Clouds**

In day time, clouds should be diffuse lit. Use `u_Cloud` to determine the
cloud color, and `u_CloudTrans` and `mix` to determine how much a daytime
fragment is affected by the day diffuse map or cloud color. See Figure 6.

In night time, clouds should obscure city lights. Use `u_CloudTrans` and `mix`
to blend between the city lights and solid black. See Figure 7.

Animate the clouds by offseting the `s` component of `v_Texcoord` by `u_time`
when reading `u_Cloud` and `u_CloudTrans`.

![Day with clouds](resources/globe_daycloud.png)

Figure 6. Clouds with day time shading.

![Night with clouds](resources/globe_nightcloud.png)

Figure 7. Clouds observing city nights on the dark side of the globe.

**Bump Mapping**

Add the appearance of mountains by perturbing the normal used for diffuse
lighting the ground (not the clouds) by using the bump map texture, `u_Bump`.
This texture is 1024x512, and is zero when the fragment is at sea-level, and
one when the fragment is on the highest mountain. Read three texels from this
texture: once using `v_Texcoord`; once one texel to the right; and once one
texel above. Create a perturbed normal in tangent space:

`normalize(vec3(center - right, center - top, 0.2))`

Use `eastNorthUpToEyeCoordinates` to transform this normal to eye coordinates,
normalize it, then use it for diffuse lighting the ground instead of the
original normal.

![Globe with bump mapping](resources/globe_bumpmap.png)

Figure 8. Bump mapping brings attention to mountains.

**Rim Lighting**

Rim lighting is a simple post-processed lighting effect we can apply to make
the globe look as if it has an atmospheric layer catching light from the sun.
Implementing rim lighting is simple; we being by finding the dot product of
`v_Normal` and `v_Position`, and add 1 to the dot product. We call this value
our rim factor. If the rim factor is greater than 0, then we add a blue color
based on the rim factor to the current fragment color. You might use a color
something like `vec4(rim/4, rim/2, rim/2, 1)`. If our rim factor is not greater
than 0, then we leave the fragment color as is. Figures 0,1 and 2 show our
finished globe with rim lighting.

For more information on rim lighting,
read http://www.fundza.com/rman_shaders/surface/fake_rim/fake_rim1.html.

-------------------------------------------------------------------------------
GH-PAGES
-------------------------------------------------------------------------------
Since this assignment is in WebGL you will make your project easily viewable by
taking advantage of GitHub's project pages feature.

Once you are done you will need to create a new branch named gh-pages:

`git branch gh-pages`

Switch to your new branch:

`git checkout gh-pages`

Create an index.html file that is either your renamed frag_globe.html or
contains a link to it, commit, and then push as usual. Now you can go to

`<user_name>.github.io/<project_name>`

to see your beautiful globe from anywhere.
Nathan's Terrain Renderer Plus ISS Orbit Visualizer
DISCLAIMER 1: Right now this project is ONLY compatible with Firefox! Fixes for Chrome coming soon!
DISCLAIMER 2: You might have to wait a little bit for texture data to load, since the globe and terrain renderers use high-res textures!

-------------------------------------------------------------------------------
README
TERRAIN RENDERER
-------------------------------------------------------------------------------
All students must replace or augment the contents of this Readme.md in a clear
manner with the following:

* A brief description of the project and the specific features you implemented.
* At least one screenshot of your project running.
* A 30 second or longer video of your project running. To create the video you
can use http://www.microsoft.com/expression/products/Encoder4_Overview.aspx
* A performance evaluation (described in detail below).

-------------------------------------------------------------------------------
PERFORMANCE EVALUATION
-------------------------------------------------------------------------------
The performance evaluation is where you will investigate how to make your
program more efficient using the skills you've learned in class. You must have
performed at least one experiment on your code to investigate the positive or
negative effects on performance.

We encourage you to get creative with your tweaks. Consider places in your code
that could be considered bottlenecks and try to improve them.

Each student should provide no more than a one page summary of their
optimizations along with tables and or graphs to visually explain any
performance differences.

-------------------------------------------------------------------------------
THIRD PARTY CODE POLICY
-------------------------------------------------------------------------------
* Use of any third-party code must be approved by asking on the Google groups.
If it is approved, all students are welcome to use it. Generally, we approve
use of third-party code that is not a core part of the project. For example,
for the ray tracer, we would approve using a third-party library for loading
models, but would not approve copying and pasting a CUDA function for doing
refraction.
* Third-party code must be credited in README.md.
* Using third-party code without its approval, including using another
student's code, is an academic integrity violation, and will result in you
receiving an F for the semester.

-------------------------------------------------------------------------------
SELF-GRADING
-------------------------------------------------------------------------------
* On the submission date, email your grade, on a scale of 0 to 100, to Liam,
[email protected], with a one paragraph explanation. Be concise and
realistic. Recall that we reserve 30 points as a sanity check to adjust your
grade. Your actual grade will be (0.7 * your grade) + (0.3 * our grade). We
hope to only use this in extreme cases when your grade does not realistically
reflect your work - it is either too high or too low. In most cases, we plan
to give you the exact grade you suggest.
* Projects are not weighted evenly, e.g., Project 0 doesn't count as much as
the path tracer. We will determine the weighting at the end of the semester
based on the size of each project.


---
SUBMISSION
---
As with the previous project, you should fork this project and work inside of
your fork. Upon completion, commit your finished project back to your fork, and
make a pull request to the master repository. You should include a README.md
file in the root directory detailing the following
The first part of this project is a WebGL terrain renderer, which can be accessed at the following URL: http://nmarshak1337.github.io/Project5-WebGL/part1/terrain_render.html.

* A brief description of the project and specific features you implemented
* At least one screenshot of your project running.
* A link to a video of your project running.
* Instructions for building and running your project if they differ from the
base code.
* A performance writeup as detailed above.
* A list of all third-party code used.
* This Readme file edited as described above in the README section.
The terrain renderer uses height field (DEM) data from NASA ASTER (Mt. Fuji) and the USGS (Mt. Rainier). I used a forum post by TrickyVein (http://forums.nexusmods.com/index.php?/topic/517230-tutorial-converting-a-dem-to-a-heightmap/) to convert DEM data to a heightmap. I also wrote my own tutorial (http://lightspeedbanana.blogspot.com/2013/11/getting-nasa-height-field-data.html) on how to get data from the USGS.