diff --git a/README.md b/README.md
index 06fcfd4..2b4497d 100644
--- a/README.md
+++ b/README.md
@@ -3,371 +3,78 @@ CIS565: Project 5: WebGL
-------------------------------------------------------------------------------
Fall 2013
-------------------------------------------------------------------------------
-Due Friday 11/08/2013
+Yingting Xiao
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-NOTE:
+PART 1 FEATURES:
-------------------------------------------------------------------------------
-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.
+Sine wave:
--------------------------------------------------------------------------------
-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:
-
-
-
-* A simplex noise based vertex shader:
-
-
-
-* One interesting vertex shader of your choice
+[](http://yingtingxiao.github.io/Project5-WebGL/vert_wave.html)
--------------------------------------------------------------------------------
-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:
-
-
-
-* 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
+Simplex wave 1D:
-You are required to implement:
+[](http://yingtingxiao.github.io/Project5-WebGL/vert_wave_simplex.html)
-* 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:
+Simplex wave 2D:
-* 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
+[](http://yingtingxiao.github.io/Project5-WebGL/vert_wave_custom.html)
-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.
+Instead of passing vec2(0.1*u_time, position) to simplexNoise, I pass vec2(position.x+0.25*u_time, position.y+0.25*u_time) to it. As a result, I get a nice 2D simplex wave.
-Some examples of what your completed globe renderer will look like:
+---
-
+Perlin wave 2D:
-Figure 0. Completed globe renderer, daylight side.
+[](http://yingtingxiao.github.io/Project5-WebGL/vert_wave_perlin.html)
-
+I followed the instructions on http://freespace.virgin.net/hugo.elias/models/m_perlin.htm to write my 2D perlin noise generator.
-Figure 1. Completed globe renderer, twilight border.
+Since WebGL doesn't support bitwise operations (used in the perlin noise tutorial for generating random numbers) or GLSL noise functions, I use this function to generate a pseudo-random number between 0 and 1 (credit: http://stackoverflow.com/questions/4200224/random-noise-functions-for-glsl/4275343#4275343):
-
+float noise(float x, float y) {
+ return fract(sin(dot(vec2(x,y) ,vec2(12.9898,78.233))) * 43758.5453);
+}
-Figure 2. Completed globe renderer, night side.
+It works perfectly well! For getting the perlin noise at a specific position I simply call perlin on vec2(position.x+0.25*u_time, position.y).
-------------------------------------------------------------------------------
-PART 2 WALKTHROUGH:
+PART 2 FEATURES:
-------------------------------------------------------------------------------
-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.
-
-
-
-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!
-
-
-
-Figure 4. Globe with night lights and day/night blending at dusk/dawn.
-
-**Specular Map**
+All required features:
-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.
-
-
-
-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`.
-
-
-
-Figure 6. Clouds with day time shading.
-
-
-
-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.
-
-
-
-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.
+[](http://yingtingxiao.github.io/Project5-WebGL/frag_globe.html)
+---
-For more information on rim lighting,
-read http://www.fundza.com/rman_shaders/surface/fake_rim/fake_rim1.html.
+Additional feature:
--------------------------------------------------------------------------------
-GH-PAGES
--------------------------------------------------------------------------------
-Since this assignment is in WebGL you will make your project easily viewable by
-taking advantage of GitHub's project pages feature.
+Procedural water rendering and animation using noise:
-Once you are done you will need to create a new branch named gh-pages:
+Version 1:
-`git branch gh-pages`
+[](http://yingtingxiao.github.io/Project5-WebGL/frag_globe_perlin.html)
-Switch to your new branch:
+I turn off clouds in order to show the animation of water more clearly. In this version I use perlin noise as a bump map. I use the perlin noise values of a pixel's right and top points on the globe to compute the normal.
-`git checkout gh-pages`
+Version 2:
-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
+[](http://yingtingxiao.github.io/Project5-WebGL/frag_globe_perlin_vert.html)
-`
diff --git a/part2/frag_globe.js b/part2/frag_globe.js index 1d8a877..d821266 100644 --- a/part2/frag_globe.js +++ b/part2/frag_globe.js @@ -3,6 +3,12 @@ /*global window,document,Float32Array,Uint16Array,mat4,vec3,snoise*/ /*global getShaderSource,createWebGLContext,createProgram*/ + var stats = new Stats(); + stats.setMode(1); + stats.domElement.style.position = 'absolute'; + stats.domElement.style.top = '10px'; + document.body.appendChild( stats.domElement ); + function sphericalToCartesian( r, a, e ) { var x = r * Math.cos(e) * Math.cos(a); var y = r * Math.sin(e); @@ -31,7 +37,7 @@ mat4.perspective(45.0, canvas.width/canvas.height, 0.1, 100.0, persp); var radius = 5.0; - var azimuth = Math.PI; + var azimuth = Math.PI/2; var elevation = 0.0001; var eye = sphericalToCartesian(radius, azimuth, elevation); @@ -237,7 +243,6 @@ function animate() { /////////////////////////////////////////////////////////////////////////// // Update - var model = mat4.create(); mat4.identity(model); mat4.rotate(model, 23.4/180*Math.PI, [0.0, 0.0, 1.0]); @@ -286,10 +291,14 @@ gl.activeTexture(gl.TEXTURE5); gl.bindTexture(gl.TEXTURE_2D, specTex); gl.uniform1i(u_EarthSpecLocation, 5); + + gl.uniform1f(u_timeLocation, time); + gl.drawElements(gl.TRIANGLES, numberOfIndices, gl.UNSIGNED_SHORT,0); time += 0.001; window.requestAnimFrame(animate); + stats.update(); } var textureCount = 0; diff --git a/part2/frag_globe_perlin.html b/part2/frag_globe_perlin.html new file mode 100644 index 0000000..0b421c9 --- /dev/null +++ b/part2/frag_globe_perlin.html @@ -0,0 +1,217 @@ + + +
+
+ + + + +
+ +