diff --git a/README.md b/README.md index 06fcfd4..31babd2 100644 --- a/README.md +++ b/README.md @@ -1,373 +1,54 @@ -------------------------------------------------------------------------------- -CIS565: Project 5: WebGL +------------------------------------------------------------------------------- +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** +Demo: -* 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: +http://takfuruya.github.io/Project5-WebGL/index.html -![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: +Part 1 - ```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; - ``` +![1](resources/1.png) +![2](resources/2.png) +![3](resources/3.png) - * 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`. +Part 2 -* 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: -------------------------------------------------------------------------------- +Night-time lights on the dark side of the globe -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. +![4](resources/4.png) +![5](resources/5.png) +![6](resources/6.png) -![Initial globe](resources/globe_initial.png) +Specular mapping -Figure 3. Initial globe with diffuse and specular lighting. +![7](resources/7.png) +![8](resources/8.png) -**Night Lights** +Moving clouds -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. +![9](resources/9.png) +![10](resources/10.png) +![11](resources/11.png) +![12](resources/12.png) +![13](resources/13.png) +![14](resources/14.png) -The base code shows an example of how to gamma correct the nighttime texture: +Bump mapped terrain -```glsl -float gammaCorrect = 1/1.2; -vec4 nightColor = pow(texture2D(u_Night, v_Texcoord), vec4(gammaCorrect)); -``` +![15](resources/15.png) +![16](resources/16.png) -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 - -`.github.io/` - -to see your beautiful globe from anywhere. - -------------------------------------------------------------------------------- -README -------------------------------------------------------------------------------- -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, - liamboone@gmail.com, 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. +Rim lighting to simulate atmosphere +![17](resources/17.png) ---- -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 +Shade based on altitude using the height map -* 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. +![18](resources/18.png) \ No newline at end of file diff --git a/part1/custom.html b/part1/custom.html new file mode 100644 index 0000000..4f0849d --- /dev/null +++ b/part1/custom.html @@ -0,0 +1,49 @@ + + + +Vertex Wave + + + + + +
+ + + + + + + + + + + + diff --git a/part1/simplex.html b/part1/simplex.html new file mode 100644 index 0000000..75a7814 --- /dev/null +++ b/part1/simplex.html @@ -0,0 +1,89 @@ + + + +Vertex Wave + + + + + +
+ + + + + + + + + + + + diff --git a/part1/vert_wave.html b/part1/vert_wave.html index 57107ca..f919d0a 100644 --- a/part1/vert_wave.html +++ b/part1/vert_wave.html @@ -12,22 +12,28 @@ diff --git a/part1/vert_wave.js b/part1/vert_wave.js index b90b9cf..94728a6 100644 --- a/part1/vert_wave.js +++ b/part1/vert_wave.js @@ -31,7 +31,8 @@ var positionLocation = 0; var heightLocation = 1; var u_modelViewPerspectiveLocation; - + var u_timeLocation; + (function initializeShader() { var program; var vs = getShaderSource(document.getElementById("vs")); @@ -40,6 +41,7 @@ var program = createProgram(context, vs, fs, message); context.bindAttribLocation(program, positionLocation, "position"); u_modelViewPerspectiveLocation = context.getUniformLocation(program,"u_modelViewPerspective"); + u_timeLocation = context.getUniformLocation(program, "u_time"); context.useProgram(program); })(); @@ -125,7 +127,9 @@ uploadMesh(positions, heights, indices); numberOfIndices = indices.length; })(); - + + var time = 0; + (function animate(){ /////////////////////////////////////////////////////////////////////////// // Update @@ -137,12 +141,14 @@ mat4.multiply(view, model, mv); var mvp = mat4.create(); mat4.multiply(persp, mv, mvp); - + time += 0.01; + /////////////////////////////////////////////////////////////////////////// // Render context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT); context.uniformMatrix4fv(u_modelViewPerspectiveLocation, false, mvp); + context.uniform1f(u_timeLocation, time); context.drawElements(context.LINES, numberOfIndices, context.UNSIGNED_SHORT,0); window.requestAnimFrame(animate); diff --git a/part2/frag_globe.html b/part2/frag_globe.html index 6aa5609..2ffc40e 100644 --- a/part2/frag_globe.html +++ b/part2/frag_globe.html @@ -21,7 +21,9 @@ attribute vec3 Position; attribute vec3 Normal; attribute vec2 Texcoord; - + attribute vec3 skyboxPosition; + attribute vec2 skyboxTexCoord; + varying vec3 v_Normal; varying vec2 v_Texcoord; varying vec3 v_Position; @@ -78,20 +80,47 @@ // normalized eye-to-position vector in camera coordinates vec3 eyeToPosition = normalize(v_Position); - float diffuse = clamp(dot(u_CameraSpaceDirLight, normal), 0.0, 1.0); - - vec3 toReflectedLight = reflect(-u_CameraSpaceDirLight, normal); + float bumpCenter = texture2D(u_Bump, v_Texcoord).r; + float bumpRight = texture2D(u_Bump, v_Texcoord+vec2(1.0/1024.0, 0.0)).r; + float bumpTop = texture2D(u_Bump, v_Texcoord+vec2(0.0, 1.0/512.0)).r; + vec3 perturbedNormal = normalize(vec3(bumpCenter - bumpRight, bumpCenter - bumpTop, 0.2)); + vec3 newNormal = eastNorthUpToEyeCoordinates(v_positionMC, normal) * perturbedNormal; + newNormal = normalize(newNormal); + + float diffuse = clamp(dot(u_CameraSpaceDirLight, newNormal), 0.0, 1.0); + + vec3 toReflectedLight = reflect(-u_CameraSpaceDirLight, newNormal); float specular = max(dot(toReflectedLight, -eyeToPosition), 0.0); specular = pow(specular, 20.0); float gammaCorrect = 1.0/1.2; //gamma correct by 1/1.2 vec3 dayColor = texture2D(u_DayDiffuse, v_Texcoord).rgb; + dayColor = mix(dayColor, vec3(1.0), bumpCenter); vec3 nightColor = texture2D(u_Night, v_Texcoord).rgb; //apply gamma correction to nighttime texture nightColor = pow(nightColor,vec3(gammaCorrect)); - - vec3 color = ((0.6 * diffuse) + (0.4 * specular)) * dayColor; + + bool isLand = texture2D(u_EarthSpec, v_Texcoord).r < 0.5; + if (isLand) specular = 0.0; + + vec2 cloudOffset = vec2(u_time/30.0, 0.0); + vec3 cloudColor = texture2D(u_Cloud, v_Texcoord+cloudOffset).rgb; + float cloudTrans = 1.0-texture2D(u_CloudTrans, v_Texcoord+cloudOffset).r; + + vec3 color = ((0.6 * diffuse) + (0.4 * specular)) * dayColor; + color = mix(color, cloudColor, clamp(cloudTrans-0.4, 0.0, 1.0)); + + float dayNightThresh = 0.2; + if (diffuse < dayNightThresh) + { + nightColor = mix(nightColor, vec3(0.0), cloudTrans); + color = mix(nightColor, color, diffuse/dayNightThresh); + } + + float rim = dot(normal, eyeToPosition) + 1.0; + if (rim > 0.0) color = mix(color, vec3(rim/2.0, rim, rim)*0.6, clamp(rim-0.5, 0.0, 1.0)); + gl_FragColor = vec4(color, 1.0); } diff --git a/part2/frag_globe.js b/part2/frag_globe.js index 1d8a877..c264d45 100644 --- a/part2/frag_globe.js +++ b/part2/frag_globe.js @@ -55,6 +55,8 @@ var u_EarthSpecLocation; var u_BumpLocation; var u_timeLocation; + var skyboxPositionLocation; + var skyboxTexCoordLocation; (function initializeShader() { var vs = getShaderSource(document.getElementById("vs")); @@ -76,7 +78,9 @@ u_BumpLocation = gl.getUniformLocation(program,"u_Bump"); u_timeLocation = gl.getUniformLocation(program,"u_time"); u_CameraSpaceDirLightLocation = gl.getUniformLocation(program,"u_CameraSpaceDirLight"); - + skyboxPositionLocation = gl.getAttribLocation(program, "skyboxPosition"); + skyboxTexCoordLocation = gl.getAttribLocation(program, "skyboxTexCoord"); + gl.useProgram(program); })(); @@ -86,6 +90,12 @@ var transTex = gl.createTexture(); var lightTex = gl.createTexture(); var specTex = gl.createTexture(); + var skyboxFrontTex = gl.createTexture(); + var skyboxBackTex = gl.createTexture(); + var skyboxRightTex = gl.createTexture(); + var skyboxLeftTex = gl.createTexture(); + var skyboxUpTex = gl.createTexture(); + var skyboxDownTex = gl.createTexture(); function initLoadedTexture(texture){ gl.bindTexture(gl.TEXTURE_2D, texture); @@ -174,7 +184,132 @@ uploadMesh(positions, texCoords, indices); numberOfIndices = indicesIndex; })(); - + + (function initializeSkybox() { + /* + // 8 corners in a cube. + var numberOfPositions = 8; + var d = 2; + + var positions = new Float32Array([ + d, d, d, d, d, -d, d, -d, -d, // right + d, d, d, d, -d, -d, d, -d, d, + -d, d, d, d, d, d, d, -d, d, // front + -d, d, d, d, -d, d, -d, -d, d, + -d, d, -d, -d, d, d, -d, -d, d, // left + -d, d, -d, -d, -d, d, -d, -d, -d, + d, d, -d, -d, d, -d, -d, -d, -d, // back + d, d, -d, -d, -d, -d, d, -d, -d, + d, d, d, -d, d, d, -d, d, -d, // top + d, d, d, -d, d, -d, d, d, -d, + d, -d, d, -d, -d, -d, -d, -d, d, // bottom + d, -d, d, d, -d, -d, -d, -d, -d + ]); + var texCoords = new Float32Array([ + 1, 1, + ]); + var indices = new Uint16Array(3 * 2 * 6); + + // ------------- + var cubeVerticesBuffer; + var cubeVerticesTextureCoordBuffer; + var cubeVerticesIndexBuffer; + + cubeVerticesBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, cubeVerticesBuffer); + var vertices = [ + // Front face + -1.0, -1.0, 1.0, + 1.0, -1.0, 1.0, + 1.0, 1.0, 1.0, + -1.0, 1.0, 1.0, + + // Back face + -1.0, -1.0, -1.0, + -1.0, 1.0, -1.0, + 1.0, 1.0, -1.0, + 1.0, -1.0, -1.0, + + // Top face + -1.0, 1.0, -1.0, + -1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, + 1.0, 1.0, -1.0, + + // Bottom face + -1.0, -1.0, -1.0, + 1.0, -1.0, -1.0, + 1.0, -1.0, 1.0, + -1.0, -1.0, 1.0, + + // Right face + 1.0, -1.0, -1.0, + 1.0, 1.0, -1.0, + 1.0, 1.0, 1.0, + 1.0, -1.0, 1.0, + + // Left face + -1.0, -1.0, -1.0, + -1.0, -1.0, 1.0, + -1.0, 1.0, 1.0, + -1.0, 1.0, -1.0 + ]; + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); + gl.vertexAttribPointer(skyboxPositionLocation, 3, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(skyboxPositionLocation); + + cubeVerticesTextureCoordBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, cubeVerticesTextureCoordBuffer); + var textureCoordinates = [ + // Front + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + // Back + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + // Top + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + // Bottom + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + // Right + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0, + // Left + 0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + 0.0, 1.0 + ]; + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(textureCoordinates), gl.STATIC_DRAW); + gl.vertexAttribPointer(skyboxTexCoordLocation, 2, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(skyboxTexCoordLocation); + + cubeVerticesIndexBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, cubeVerticesIndexBuffer); + var cubeVertexIndices = [ + 0, 1, 2, 0, 2, 3, // front + 4, 5, 6, 4, 6, 7, // back + 8, 9, 10, 8, 10, 11, // top + 12, 13, 14, 12, 14, 15, // bottom + 16, 17, 18, 16, 18, 19, // right + 20, 21, 22, 20, 22, 23 // left + ]; + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(cubeVertexIndices), gl.STATIC_DRAW); +*/ + })(); + var time = 0; var mouseLeftDown = false; var mouseRightDown = false; @@ -286,6 +421,10 @@ gl.activeTexture(gl.TEXTURE5); gl.bindTexture(gl.TEXTURE_2D, specTex); gl.uniform1i(u_EarthSpecLocation, 5); + gl.uniform1f(u_timeLocation, time); + //gl.activeTexture(gl.TEXTURE6); + //gl.bindTexture(gl.TEXTURE_2D, skyboxTex); + //gl.uniform1i(u_skyboxTex, 6); gl.drawElements(gl.TRIANGLES, numberOfIndices, gl.UNSIGNED_SHORT,0); time += 0.001; @@ -313,4 +452,10 @@ initializeTexture(transTex, "earthtrans1024.png"); initializeTexture(lightTex, "earthlight1024.png"); initializeTexture(specTex, "earthspec1024.png"); + initializeTexture(skyboxFrontTex, "skybox_front.png"); + initializeTexture(skyboxBackTex, "skybox_back.png"); + initializeTexture(skyboxRightTex, "skybox_right.png"); + initializeTexture(skyboxLeftTex, "skybox_left.png"); + initializeTexture(skyboxUpTex, "skybox_up.png"); + initializeTexture(skyboxDownTex, "skybox_down.png"); }()); diff --git a/part2/skybox source.txt b/part2/skybox source.txt new file mode 100644 index 0000000..e79b745 --- /dev/null +++ b/part2/skybox source.txt @@ -0,0 +1 @@ +http://forum.unity3d.com/threads/99258-Space-Skybox \ No newline at end of file diff --git a/part2/skybox_back.png b/part2/skybox_back.png new file mode 100644 index 0000000..c4990f0 Binary files /dev/null and b/part2/skybox_back.png differ diff --git a/part2/skybox_down.png b/part2/skybox_down.png new file mode 100644 index 0000000..00d615a Binary files /dev/null and b/part2/skybox_down.png differ diff --git a/part2/skybox_front.png b/part2/skybox_front.png new file mode 100644 index 0000000..fbdd113 Binary files /dev/null and b/part2/skybox_front.png differ diff --git a/part2/skybox_left.png b/part2/skybox_left.png new file mode 100644 index 0000000..7a68363 Binary files /dev/null and b/part2/skybox_left.png differ diff --git a/part2/skybox_right.png b/part2/skybox_right.png new file mode 100644 index 0000000..e9c34ea Binary files /dev/null and b/part2/skybox_right.png differ diff --git a/part2/skybox_up.png b/part2/skybox_up.png new file mode 100644 index 0000000..0752c6a Binary files /dev/null and b/part2/skybox_up.png differ diff --git a/resources/1.png b/resources/1.png new file mode 100644 index 0000000..2a9f10e Binary files /dev/null and b/resources/1.png differ diff --git a/resources/10.png b/resources/10.png new file mode 100644 index 0000000..db8a7c7 Binary files /dev/null and b/resources/10.png differ diff --git a/resources/11.png b/resources/11.png new file mode 100644 index 0000000..2e17018 Binary files /dev/null and b/resources/11.png differ diff --git a/resources/12.png b/resources/12.png new file mode 100644 index 0000000..2b6f661 Binary files /dev/null and b/resources/12.png differ diff --git a/resources/13.png b/resources/13.png new file mode 100644 index 0000000..33fc8f9 Binary files /dev/null and b/resources/13.png differ diff --git a/resources/14.png b/resources/14.png new file mode 100644 index 0000000..bd3289b Binary files /dev/null and b/resources/14.png differ diff --git a/resources/15.png b/resources/15.png new file mode 100644 index 0000000..3d7a240 Binary files /dev/null and b/resources/15.png differ diff --git a/resources/16.png b/resources/16.png new file mode 100644 index 0000000..08ac89d Binary files /dev/null and b/resources/16.png differ diff --git a/resources/17.png b/resources/17.png new file mode 100644 index 0000000..5195edd Binary files /dev/null and b/resources/17.png differ diff --git a/resources/18.png b/resources/18.png new file mode 100644 index 0000000..2fa1f4c Binary files /dev/null and b/resources/18.png differ diff --git a/resources/2.png b/resources/2.png new file mode 100644 index 0000000..e7a60af Binary files /dev/null and b/resources/2.png differ diff --git a/resources/3.png b/resources/3.png new file mode 100644 index 0000000..a8357f9 Binary files /dev/null and b/resources/3.png differ diff --git a/resources/4.png b/resources/4.png new file mode 100644 index 0000000..0207fbc Binary files /dev/null and b/resources/4.png differ diff --git a/resources/5.png b/resources/5.png new file mode 100644 index 0000000..19b8a4b Binary files /dev/null and b/resources/5.png differ diff --git a/resources/6.png b/resources/6.png new file mode 100644 index 0000000..66d3b8d Binary files /dev/null and b/resources/6.png differ diff --git a/resources/7.png b/resources/7.png new file mode 100644 index 0000000..6fbc079 Binary files /dev/null and b/resources/7.png differ diff --git a/resources/8.png b/resources/8.png new file mode 100644 index 0000000..f6cf8aa Binary files /dev/null and b/resources/8.png differ diff --git a/resources/9.png b/resources/9.png new file mode 100644 index 0000000..723ff5c Binary files /dev/null and b/resources/9.png differ diff --git a/resources/emptyGrid.png b/resources/emptyGrid.png deleted file mode 100644 index 2ee870f..0000000 Binary files a/resources/emptyGrid.png and /dev/null differ diff --git a/resources/globe_bumpmap.png b/resources/globe_bumpmap.png deleted file mode 100644 index fa91a9f..0000000 Binary files a/resources/globe_bumpmap.png and /dev/null differ diff --git a/resources/globe_day.png b/resources/globe_day.png deleted file mode 100644 index e3cbf1f..0000000 Binary files a/resources/globe_day.png and /dev/null differ diff --git a/resources/globe_daycloud.png b/resources/globe_daycloud.png deleted file mode 100644 index ff00096..0000000 Binary files a/resources/globe_daycloud.png and /dev/null differ diff --git a/resources/globe_initial.png b/resources/globe_initial.png deleted file mode 100644 index 1e3bde5..0000000 Binary files a/resources/globe_initial.png and /dev/null differ diff --git a/resources/globe_night.png b/resources/globe_night.png deleted file mode 100644 index 6401768..0000000 Binary files a/resources/globe_night.png and /dev/null differ diff --git a/resources/globe_nightcloud.png b/resources/globe_nightcloud.png deleted file mode 100644 index 781aec0..0000000 Binary files a/resources/globe_nightcloud.png and /dev/null differ diff --git a/resources/globe_nospecmap.png b/resources/globe_nospecmap.png deleted file mode 100644 index c370735..0000000 Binary files a/resources/globe_nospecmap.png and /dev/null differ diff --git a/resources/globe_specmap.png b/resources/globe_specmap.png deleted file mode 100644 index 7ff01a5..0000000 Binary files a/resources/globe_specmap.png and /dev/null differ diff --git a/resources/globe_twilight.png b/resources/globe_twilight.png deleted file mode 100644 index ac5ea5c..0000000 Binary files a/resources/globe_twilight.png and /dev/null differ diff --git a/resources/oceanWave.png b/resources/oceanWave.png deleted file mode 100644 index 73b65d5..0000000 Binary files a/resources/oceanWave.png and /dev/null differ diff --git a/resources/sinWaveGrid.png b/resources/sinWaveGrid.png deleted file mode 100644 index 733f8d8..0000000 Binary files a/resources/sinWaveGrid.png and /dev/null differ