diff --git a/README.md b/README.md index 2d26873..69e31dd 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,6 @@ CIS565: Project 5: WebGL ------------------------------------------------------------------------------- Fall 2014 ------------------------------------------------------------------------------- -Due Monday 11/03/2014 -------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- -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: @@ -34,100 +21,39 @@ bump mapping, specular masking, and adding a cloud layer to give your globe a uniquie feel. ------------------------------------------------------------------------------- -CONTENTS: +PART 1 IMPLEMENTATIONS: Vertex Shader ------------------------------------------------------------------------------- -The Project5 root directory contains the following subdirectories: - -* js/ contains the javascript files, including external libraries, necessary. -* assets/ contains the textures that will be used in the second half of the - assignment. -* resources/ contains the screenshots found in this readme file. +**Video Demo** +http://youtu.be/GwDTq3_JsGA -------------------------------------------------------------------------------- -PART 1 REQUIREMENTS: -------------------------------------------------------------------------------- +* A sin-wave based vertex shader: +![sin-wave vertex shader](result_img/1A.JPG) -In Part 1, you are given code for: +![bump vertex shader](result_img/sinwave.gif) -* Drawing a VBO through WebGL -* Javascript code for interfacing with WebGL -* Functions for generating simplex noise +* Bump vertex shader: -You are required to implement the following: +Reference: http://www.benjoffe.com/code/tools/functions3d/examples +![bump vertex shader](result_img/1B_Bump.JPG) -* A sin-wave based vertex shader: +![bump vertex shader](result_img/bump.gif) -![Example sin wave grid](resources/sinWaveGrid.png) +* Beautiful wave: -* One interesting vertex shader of your choice +Reference: http://commons.wikimedia.org/wiki/File:3d-function-continuous.svg +![wave vertex shader](result_img/1B_Wave.JPG) +![w](result_img/beautifulwave.gif) ------------------------------------------------------------------------------- -PART 1 WALKTHROUGH: +PART 2 IMPLEMENTATIONS: Fragment Globe ------------------------------------------------------------------------------- -**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`. - - * Using dat.gui, you will add color pickers to modify the max and min colors - via GUI. You will do this by adding the proper uniforms to the fragment - shader, and using the addColor function from dat.GUI. - -* 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()`. - -**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: +**Gh-pages** + +http://radiumyang.github.io/Project5-WebGL/ -* 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: +**Feature List** * Bump mapped terrain * Rim lighting to simulate atmosphere @@ -135,228 +61,42 @@ You are required to implement: * Specular mapping * Moving clouds -You are also required to pick one open-ended effect to implement: - -* Procedural water rendering and animation using noise +Extra: * 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! +Final Result with all features merged: -![Day/Night without specular mapping](resources/globe_nospecmap.png) +![Completed globe, day side](result_img/2_height_merged2.JPG) -Figure 4. Globe with night lights and day/night blending at dusk/dawn. +### STEP 1: Bumping Map -**Specular Map** +![Completed globe, twilight](result_img/bumping map.JPG) -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. +### STEP 2: NightColor + Rim + Specular Color -![Day/Night with specular mapping](resources/globe_specmap.png) +![Completed globe, night side](result_img/2_night_spec.JPG) -Figure 5. Globe with specular map. Compare to Figure 4. Here, the specular -component is not used when shading the land. +### STEP 3: Add Animated Cloud -**Clouds** +![cloud](result_img/good_basic_globe.JPG) -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. +### STEP 4: Add Depth Mapping -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. +Depth Mapping Only: -Animate the clouds by offseting the `s` component of `v_Texcoord` by `u_time` -when reading `u_Cloud` and `u_CloudTrans`. +![depth](result_img/2_height2.JPG) -![Day with clouds](resources/globe_daycloud.png) +merged with other shading: -Figure 6. Clouds with day time shading. +![depth2](result_img/2_height_merged2.JPG) -![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/rim_effects/index.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. In this homework, we do not expect crazy performance evaluation in terms of optimizations. However, it would be good to take performance benchmarks at every step in this assignment to see how complicated fragment shaders affect the overall speed. You can do this by using stats.js. -------------------------------------------------------------------------------- -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 Harmony, - harmoli+cis565@seas.upenn.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. - ---- -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 - -* 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. diff --git a/assets/earthheight1024.png b/assets/earthheight1024.png new file mode 100644 index 0000000..0500bc8 Binary files /dev/null and b/assets/earthheight1024.png differ diff --git a/frag_globe.html b/frag_globe.html index e074492..6a36380 100644 --- a/frag_globe.html +++ b/frag_globe.html @@ -61,6 +61,9 @@ //Bump map uniform sampler2D u_Bump; + //height map + uniform sampler2D u_Height; + uniform float u_time; uniform mat4 u_InvTrans; @@ -77,8 +80,42 @@ vec3 normal = normalize(v_Normal); // normalized eye-to-position vector in camera coordinates vec3 eyeToPosition = normalize(v_Position); + + //rim Lighting + float NdotP = dot(normal, v_Position) + 1.2; + vec3 rimColor = vec3(0,0,0); + if (NdotP > 0.01) + rimColor = vec3(NdotP/4.0, NdotP/2.0, NdotP/2.0); + + // bump mapping + float center = texture2D(u_Bump,v_Texcoord).x; + float right = texture2D(u_Bump,v_Texcoord + vec2(1.0/1024.0,0)).x; + float top = texture2D(u_Bump,v_Texcoord + vec2(0,1.0/512.0)).x; + vec3 bNormal = normalize(vec3(center-right, center-top, 0.2)); + vec3 pToEye = eastNorthUpToEyeCoordinates(v_positionMC, normal) * bNormal; + normal = normalize(pToEye); + + //height mapping + float hcenter = texture2D(u_Height,v_Texcoord).x; + float hright = texture2D(u_Height,v_Texcoord + vec2(1.0/1024.0,0)).x; + float htop = texture2D(u_Height,v_Texcoord + vec2(0,1.0/512.0)).x; + vec3 hNormal = normalize(vec3(center-right, center-top, 0.2)); + vec3 hpToEye = eastNorthUpToEyeCoordinates(v_positionMC, normal) * hNormal; + hNormal = normalize(hpToEye); + float height = texture2D(u_Height, v_Texcoord).r; + + + float hdiffuse = dot(u_CameraSpaceDirLight, hNormal); + + vec3 heightColor; + if(height < 0.5) + heightColor = 0.5 * hdiffuse + mix(vec3(0, 0, 1), vec3(0, 1, 0), height); + else + heightColor = 0.5 * hdiffuse + mix(vec3(0, 1, 0), vec3(1, 0, 0), height); + float diffuse = clamp(dot(u_CameraSpaceDirLight, normal), 0.0, 1.0); + float diffuse_noclamp = dot(u_CameraSpaceDirLight, normal); // use it to detect if it is night or daytime vec3 toReflectedLight = reflect(-u_CameraSpaceDirLight, normal); float specular = max(dot(toReflectedLight, -eyeToPosition), 0.0); @@ -87,12 +124,36 @@ float gammaCorrect = 1.0/1.2; //gamma correct by 1/1.2 vec3 dayColor = texture2D(u_DayDiffuse, v_Texcoord).rgb; - vec3 nightColor = texture2D(u_Night, v_Texcoord).rgb; + vec3 nightColor = texture2D(u_Night, v_Texcoord).rgb; + vec3 specColor = texture2D(u_EarthSpec, v_Texcoord).rgb; // black:land, white:sea + + // cloud animation + vec2 v_moveCoord = v_Texcoord - vec2(u_time, 0.0); + + vec3 cloudColor = texture2D(u_Cloud, v_moveCoord).rgb; + vec3 cloudTransColor = texture2D(u_CloudTrans, v_moveCoord).rgb; + + if(specColor.x > 0.0) //white, is sea + { + specColor = specColor * specular; + }else // is land + { + specColor = vec3(0,0,0); + } //apply gamma correction to nighttime texture nightColor = pow(nightColor,vec3(gammaCorrect)); + nightColor = mix(nightColor, (vec3(1,1,1) - cloudTransColor), 0.4); + + vec3 color = vec3(0,0,0); + vec3 colortmp = ((0.6 * diffuse) + (0.4 * specColor)) * dayColor; + colortmp = mix(colortmp, cloudColor * cloudTransColor, 0.3); + color = mix(nightColor, colortmp, (1.0 + diffuse_noclamp)/2.0); - vec3 color = ((0.6 * diffuse) + (0.4 * specular)) * dayColor; + float fac = 0.3; + if (height<0.5) fac = 0.15; + color += rimColor + heightColor * fac; gl_FragColor = vec4(color, 1.0); + // gl_FragColor = vec4(heightColor, 1.0); } mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC) diff --git a/js/frag_globe.js b/js/frag_globe.js index f37830d..c015158 100644 --- a/js/frag_globe.js +++ b/js/frag_globe.js @@ -56,6 +56,8 @@ var u_BumpLocation; var u_timeLocation; + var u_HeightLocation; + (function initializeShader() { var vs = getShaderSource(document.getElementById("vs")); var fs = getShaderSource(document.getElementById("fs")); @@ -77,6 +79,8 @@ u_timeLocation = gl.getUniformLocation(program,"u_time"); u_CameraSpaceDirLightLocation = gl.getUniformLocation(program,"u_CameraSpaceDirLight"); + u_HeightLocation = gl.getUniformLocation(program, "u_Height"); + gl.useProgram(program); })(); @@ -86,6 +90,7 @@ var transTex = gl.createTexture(); var lightTex = gl.createTexture(); var specTex = gl.createTexture(); + var heightTex = gl.createTexture(); function initLoadedTexture(texture){ gl.bindTexture(gl.TEXTURE_2D, texture); @@ -288,7 +293,14 @@ gl.uniform1i(u_EarthSpecLocation, 5); gl.drawElements(gl.TRIANGLES, numberOfIndices, gl.UNSIGNED_SHORT,0); + gl.activeTexture(gl.TEXTURE6); + gl.bindTexture(gl.TEXTURE_2D, heightTex); + gl.uniform1i(u_HeightLocation, 6); + time += 0.001; + + gl.uniform1f(u_timeLocation, time); + window.requestAnimFrame(animate); } @@ -300,7 +312,7 @@ initLoadedTexture(texture); // Animate once textures load. - if (++textureCount === 6) { + if (++textureCount === 7) { animate(); } } @@ -313,4 +325,6 @@ initializeTexture(transTex, "assets/earthtrans1024.png"); initializeTexture(lightTex, "assets/earthlight1024.png"); initializeTexture(specTex, "assets/earthspec1024.png"); + + initializeTexture(heightTex, "assets/earthheight1024.png") }()); diff --git a/result_img/1A.JPG b/result_img/1A.JPG new file mode 100644 index 0000000..277ee6d Binary files /dev/null and b/result_img/1A.JPG differ diff --git a/result_img/1B_Bump.JPG b/result_img/1B_Bump.JPG new file mode 100644 index 0000000..16abdc7 Binary files /dev/null and b/result_img/1B_Bump.JPG differ diff --git a/result_img/1B_Wave.JPG b/result_img/1B_Wave.JPG new file mode 100644 index 0000000..4fffdff Binary files /dev/null and b/result_img/1B_Wave.JPG differ diff --git a/result_img/2_bug.JPG b/result_img/2_bug.JPG new file mode 100644 index 0000000..8ca4c74 Binary files /dev/null and b/result_img/2_bug.JPG differ diff --git a/result_img/2_bug2.JPG b/result_img/2_bug2.JPG new file mode 100644 index 0000000..eac1bd8 Binary files /dev/null and b/result_img/2_bug2.JPG differ diff --git a/result_img/2_bug3.JPG b/result_img/2_bug3.JPG new file mode 100644 index 0000000..7b16652 Binary files /dev/null and b/result_img/2_bug3.JPG differ diff --git a/result_img/2_bug4.JPG b/result_img/2_bug4.JPG new file mode 100644 index 0000000..846e0b3 Binary files /dev/null and b/result_img/2_bug4.JPG differ diff --git a/result_img/2_height.JPG b/result_img/2_height.JPG new file mode 100644 index 0000000..272e91c Binary files /dev/null and b/result_img/2_height.JPG differ diff --git a/result_img/2_height2.JPG b/result_img/2_height2.JPG new file mode 100644 index 0000000..3df9006 Binary files /dev/null and b/result_img/2_height2.JPG differ diff --git a/result_img/2_height_merged.JPG b/result_img/2_height_merged.JPG new file mode 100644 index 0000000..fcfa23d Binary files /dev/null and b/result_img/2_height_merged.JPG differ diff --git a/result_img/2_height_merged2.JPG b/result_img/2_height_merged2.JPG new file mode 100644 index 0000000..6eaafde Binary files /dev/null and b/result_img/2_height_merged2.JPG differ diff --git a/result_img/2_night_spec.JPG b/result_img/2_night_spec.JPG new file mode 100644 index 0000000..3826568 Binary files /dev/null and b/result_img/2_night_spec.JPG differ diff --git a/result_img/2_rim.JPG b/result_img/2_rim.JPG new file mode 100644 index 0000000..b5c0734 Binary files /dev/null and b/result_img/2_rim.JPG differ diff --git a/result_img/beautifulwave.gif b/result_img/beautifulwave.gif new file mode 100644 index 0000000..4f3203d Binary files /dev/null and b/result_img/beautifulwave.gif differ diff --git a/result_img/bump.gif b/result_img/bump.gif new file mode 100644 index 0000000..939267a Binary files /dev/null and b/result_img/bump.gif differ diff --git a/result_img/bumping map.JPG b/result_img/bumping map.JPG new file mode 100644 index 0000000..a7dc5d8 Binary files /dev/null and b/result_img/bumping map.JPG differ diff --git a/result_img/good_basic_globe.JPG b/result_img/good_basic_globe.JPG new file mode 100644 index 0000000..2c5a807 Binary files /dev/null and b/result_img/good_basic_globe.JPG differ diff --git a/result_img/sinwave.gif b/result_img/sinwave.gif new file mode 100644 index 0000000..d3a7ec6 Binary files /dev/null and b/result_img/sinwave.gif differ diff --git a/result_img/vertex_waves_radium.wmv b/result_img/vertex_waves_radium.wmv new file mode 100644 index 0000000..927dbf7 Binary files /dev/null and b/result_img/vertex_waves_radium.wmv differ diff --git a/vert_wave.html b/vert_wave.html index 5c7495b..9c7bb37 100644 --- a/vert_wave.html +++ b/vert_wave.html @@ -17,26 +17,46 @@ attribute vec2 position; uniform mat4 u_modelViewPerspective; + + ////ra + uniform float u_time; + varying vec4 myColor; + + uniform vec4 u_color_high; + uniform vec4 u_color_low; + void main(void) { // NOTE : according to the WebGL standard, 0.0f is not accepted - float height = 0.0; + // float height = 0.0; + 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; + myColor = mix(u_color_low, u_color_high, height); + // NOTE : gl_Position is always a vec4 gl_Position = u_modelViewPerspective * vec4(vec3(position, height), 1.0); + + } @@ -46,6 +66,21 @@ var heightLocation = 1; var u_modelViewPerspectiveLocation; var u_color; + var u_color_low = [0.8,0.0,0.4,1.0]; + var u_color_high = [0.2,0.6,1.0,1.0]; + var u_time; + + var timeLocation; + var colorLowLocation; + var colorHighLocation; + + var Colors = { + minColor : [255, 0, 0], + maxColor : [0, 255, 0] + }; + + var time = 0; + var deltaT = 0.05; var heights; var numberOfIndices; @@ -70,6 +105,9 @@ // Add GUI component var gui = new dat.GUI(); + gui.addColor(Colors, 'minColor'); + gui.addColor(Colors, 'maxColor'); + init(); animate(); @@ -99,6 +137,8 @@ function animate(){ + time += deltaT; + // Update var model = mat4.create(); mat4.identity(model); @@ -112,6 +152,12 @@ context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT); context.uniformMatrix4fv(u_modelViewPerspectiveLocation, false, mvp); + + context.uniform1f(timeLocation,time); + context.uniform4f(colorLowLocation, Colors.minColor[0]/255.0, Colors.minColor[1]/255.0, Colors.minColor[2]/255.0, 1.0); + context.uniform4f(colorHighLocation, Colors.maxColor[0]/255.0, Colors.maxColor[1]/255.0, Colors.maxColor[2]/255.0, 1.0); + + context.drawElements(context.LINES, numberOfIndices, context.UNSIGNED_SHORT,0); window.requestAnimFrame(animate); @@ -127,6 +173,10 @@ u_modelViewPerspectiveLocation = context.getUniformLocation(program,"u_modelViewPerspective"); u_colorLocation = context.getUniformLocation(program, "u_color"); + timeLocation = context.getUniformLocation(program,"u_time"); + colorLowLocation = context.getUniformLocation(program, "u_color_low"); + colorHighLocation = context.getUniformLocation(program, "u_color_high"); + context.useProgram(program); } diff --git a/vert_wave_customA.html b/vert_wave_customA.html new file mode 100644 index 0000000..65e59f3 --- /dev/null +++ b/vert_wave_customA.html @@ -0,0 +1,265 @@ + + + +Vertex Wave + + + + + +
+ + + + + + + + + + + + + + diff --git a/vert_wave_customBump.html b/vert_wave_customBump.html new file mode 100644 index 0000000..af8b647 --- /dev/null +++ b/vert_wave_customBump.html @@ -0,0 +1,262 @@ + + + +Vertex Wave + + + + + +
+ + + + + + + + + + + + + +