Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
388 changes: 41 additions & 347 deletions README.md

Large diffs are not rendered by default.

Binary file added part1/FUJI_cropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added part1/RAINIER_cropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion part1/gl-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
if (typeof(Float32Array) != 'undefined') {
var y = new Float32Array(1);
var i = new Int32Array(y.buffer);

/**
* Fast way to calculate the inverse square root,
* see http://jsperf.com/inverse-square-root/5
Expand Down
92 changes: 92 additions & 0 deletions part1/index_simplex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<html>

<head>
<title>Vertex Wave</title>
<meta charset ="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1"> <!-- Use Chrome Frame in IE -->
</head>

<body>
<div id="message" style="position:absolute;top:100px"></div> <!-- Pixel offset to avoid FPS counter -->
<canvas id="canvas" style="border: none;" width="1024" height="768" tabindex="1"></canvas>

<script id="vs" type="x-shader/x-vertex">
#extension GL_EXT_gpu_shader4 : enable
attribute vec2 position;

uniform mat4 u_modelViewPerspective;
uniform float u_time;
varying vec3 curr_color;

vec3 permute(vec3 x) {
x = ((x*34.0)+1.0)*x;
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

float simplexNoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);

vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);

vec2 i1;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);

vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;

i = i - floor(i * (1.0 / 289.0)) * 289.0;

vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))
+ i.x + vec3(0.0, i1.x, 1.0 ));

vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;

vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;

m *= inversesqrt( a0*a0 + h*h );

vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
void main(void)
{
vec3 low_color = vec3(1.0, 0.2, 0.0);
vec3 high_color = vec3(0.0, 0.8, 1.0);
// float t_contrib = cos(position.y*2.0*3.14159 + u_time);
// float s_contrib = sin(position.x*2.0*3.14159 + u_time);
vec2 simplexVec = vec2(u_time, position);
float s_contrib = simplexNoise(simplexVec);
float t_contrib = simplexNoise(vec2(s_contrib,u_time));
float height = s_contrib*t_contrib;
gl_Position = u_modelViewPerspective * vec4(vec3(position, height), 1.0);
curr_color = mix(low_color, high_color, height);
}

</script>

<script id="fs" type="x-shader/x-fragment">
precision mediump float;
varying vec3 curr_color;

void main(void)
{
//gl_FragColor = vec4(vec3(0.0), 1.0);
gl_FragColor = vec4(curr_color, 1.0);
}
</script>

<script src ="gl-matrix.js" type ="text/javascript"></script>
<script src ="webGLUtility.js" type ="text/javascript"></script>
<script src ="vert_wave.js" type ="text/javascript"></script>
</body>

</html>
Binary file added part1/mt_fuji_area.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added part1/picogen_heightmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion part1/simplex.vert
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ float simplexNoise(vec2 v)
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}
}
67 changes: 67 additions & 0 deletions part1/terrain_render.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<html>

<head>
<title>NaTerrain WebGL Terrain Rendering</title>
<meta charset ="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1"> <!-- Use Chrome Frame in IE -->
</head>

<body style="background-color:#000000">
<div id="message" style="position:absolute;top:100px"></div> <!-- Pixel offset to avoid FPS counter -->
<center>
<canvas id="canvas" style="border: none;" width="1024" height="768" tabindex="1"></canvas>
</center>

<script id="vs" type="x-shader/x-vertex">
attribute vec2 position;

uniform mat4 u_modelViewPerspective;
uniform float u_heightBlend;
uniform sampler2D u_Height;
uniform sampler2D u_Height2;
varying vec3 curr_color;

void main(void)
{
vec3 low_color = vec3(1.0, 0.2, 0.0);
vec3 high_color = vec3(0.0, 0.8, 1.0);
vec2 texCoord = vec2(position.x, position.y);
float height1 = texture2D(u_Height, texCoord).r;
float height2 = texture2D(u_Height2, texCoord).r;
float height = mix(height1, height2, u_heightBlend);
gl_Position = u_modelViewPerspective * vec4(vec3(position, 0.5*height), 1.0);
curr_color = mix(low_color, high_color, height);
}
</script>

<script id="fs" type="x-shader/x-fragment">
precision mediump float;
varying vec3 curr_color;

void main(void)
{
//gl_FragColor = vec4(vec3(0.0), 1.0);
gl_FragColor = vec4(curr_color, 1.0);
}
</script>

<script src ="gl-matrix.js" type ="text/javascript"></script>
<script src ="webGLUtility.js" type ="text/javascript"></script>
<script src ="terrain_render.js" type ="text/javascript"></script>

<script>
function blendToZero(){
blendDir = -1;
}
function blendToOne(){
blendDir = 1;
}
</script>

<center>
<button onclick="blendToZero()">Mt. Fuji</button>
<button onclick="blendToOne()">Mt. Rainier</button>
</center>
</body>

</html>
211 changes: 211 additions & 0 deletions part1/terrain_render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
var blendDir = -1.0;

(function() {
"use strict";
/*global window,document,Float32Array,Uint16Array,mat4,vec3,snoise*/
/*global getShaderSource,createWebGLContext,createProgram*/

var NUM_WIDTH_PTS = 128;
var NUM_HEIGHT_PTS = 128;

var message = document.getElementById("message");
var canvas = document.getElementById("canvas");
var context = createWebGLContext(canvas, message);
if (!context) {
return;
}

///////////////////////////////////////////////////////////////////////////

context.viewport(0, 0, canvas.width, canvas.height);
context.clearColor(0.0, 0.0, 0.0, 1.0);
context.enable(context.DEPTH_TEST);

var persp = mat4.create();
mat4.perspective(45.0, 0.5, 0.1, 100.0, persp);

var eye = [2.0, 1.0, 3.0];
var center = [0.0, 0.0, 0.0];
var up = [0.0, 0.0, 1.0];
var view = mat4.create();
mat4.lookAt(eye, center, up, view);

var positionLocation = 0;
var heightLocation = 1;
var u_modelViewPerspectiveLocation;
var u_heightLocation;
var u_heightLocation2;
var u_heightBlendLocation;

var terrainTex1;
var terrainIm1;
var terrainTex2;
var terrainIm2;

//from https://developer.mozilla.org/en-US/docs/Web/WebGL/Using_textures_in_WebGL
function initTextures() {
terrainTex1 = context.createTexture();
terrainIm1 = new Image();
terrainIm1.onload = function() { handleTextureLoaded(terrainIm1, terrainTex1); };
terrainIm1.src = "FUJI_cropped.png";

terrainTex2 = context.createTexture();
terrainIm2 = new Image();
terrainIm2.onload = function() { handleTextureLoaded(terrainIm2, terrainTex2); };
terrainIm2.src = "RAINIER_cropped.png";
}

function handleTextureLoaded(image, texture) {
context.bindTexture(context.TEXTURE_2D, texture);
context.texImage2D(context.TEXTURE_2D, 0, context.RGBA, context.RGBA, context.UNSIGNED_BYTE, image);
context.texParameteri(context.TEXTURE_2D, context.TEXTURE_MAG_FILTER, context.LINEAR);
context.texParameteri(context.TEXTURE_2D, context.TEXTURE_MIN_FILTER, context.LINEAR_MIPMAP_NEAREST);
context.generateMipmap(context.TEXTURE_2D);
context.bindTexture(context.TEXTURE_2D, null);
}

(function initializeShader() {
initTextures();
var program;
var vs = getShaderSource(document.getElementById("vs"));
var fs = getShaderSource(document.getElementById("fs"));

var program = createProgram(context, vs, fs, message);
context.bindAttribLocation(program, positionLocation, "position");
u_modelViewPerspectiveLocation = context.getUniformLocation(program,"u_modelViewPerspective");
u_heightLocation = context.getUniformLocation(program, "u_Height");
u_heightLocation2 = context.getUniformLocation(program, "u_Height2");
u_heightBlendLocation = context.getUniformLocation(program, "u_heightBlend");

context.useProgram(program);
})();

var heights;
var numberOfIndices;

(function initializeGrid() {
function uploadMesh(positions, heights, indices) {
// Positions
var positionsName = context.createBuffer();
context.bindBuffer(context.ARRAY_BUFFER, positionsName);
context.bufferData(context.ARRAY_BUFFER, positions, context.STATIC_DRAW);
context.vertexAttribPointer(positionLocation, 2, context.FLOAT, false, 0, 0);
context.enableVertexAttribArray(positionLocation);

if (heights)
{
// Heights
var heightsName = context.createBuffer();
context.bindBuffer(context.ARRAY_BUFFER, heightsName);
context.bufferData(context.ARRAY_BUFFER, heights.length * heights.BYTES_PER_ELEMENT, context.STREAM_DRAW);
context.vertexAttribPointer(heightLocation, 1, context.FLOAT, false, 0, 0);
context.enableVertexAttribArray(heightLocation);
}

// Indices
var indicesName = context.createBuffer();
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indicesName);
context.bufferData(context.ELEMENT_ARRAY_BUFFER, indices, context.STATIC_DRAW);
}

var WIDTH_DIVISIONS = NUM_WIDTH_PTS - 1;
var HEIGHT_DIVISIONS = NUM_HEIGHT_PTS - 1;

var numberOfPositions = NUM_WIDTH_PTS * NUM_HEIGHT_PTS;

var positions = new Float32Array(2 * numberOfPositions);
var indices = new Uint16Array(2 * ((NUM_HEIGHT_PTS * (NUM_WIDTH_PTS - 1)) + (NUM_WIDTH_PTS * (NUM_HEIGHT_PTS - 1))));

var positionsIndex = 0;
var indicesIndex = 0;
var length;

for (var j = 0; j < NUM_WIDTH_PTS; ++j)
{
positions[positionsIndex++] = j /(NUM_WIDTH_PTS - 1);
positions[positionsIndex++] = 0.0;

if (j>=1)
{
length = positionsIndex / 2;
indices[indicesIndex++] = length - 2;
indices[indicesIndex++] = length - 1;
}
}

for (var i = 0; i < HEIGHT_DIVISIONS; ++i)
{
var v = (i + 1) / (NUM_HEIGHT_PTS - 1);
positions[positionsIndex++] = 0.0;
positions[positionsIndex++] = v;

length = (positionsIndex / 2);
indices[indicesIndex++] = length - 1;
indices[indicesIndex++] = length - 1 - NUM_WIDTH_PTS;

for (var k = 0; k < WIDTH_DIVISIONS; ++k)
{
positions[positionsIndex++] = (k + 1) / (NUM_WIDTH_PTS - 1);
positions[positionsIndex++] = v;

length = positionsIndex / 2;
var new_pt = length - 1;
indices[indicesIndex++] = new_pt - 1; // Previous side
indices[indicesIndex++] = new_pt;

indices[indicesIndex++] = new_pt - NUM_WIDTH_PTS; // Previous bottom
indices[indicesIndex++] = new_pt;
}
}

uploadMesh(positions, heights, indices);
numberOfIndices = indices.length;
})();

var dt = 0.01;
var angle = 0.0;
var heightBlend = 0.0;

(function animate(){

heightBlend += blendDir*dt;
if(heightBlend < 0.0){
heightBlend = 0.0;
} else if(heightBlend > 1.0){
heightBlend = 1.0;
}
///////////////////////////////////////////////////////////////////////////
// Update
angle = angle + 0.01;

var model = mat4.create();
mat4.identity(model);
mat4.rotate(model, angle, [0, 0, 1]);
mat4.translate(model, [-0.5, -0.5, 0.0]);
var mv = mat4.create();
mat4.multiply(view, model, mv);
var mvp = mat4.create();
mat4.multiply(persp, mv, mvp);

///////////////////////////////////////////////////////////////////////////
// Render
context.clear(context.COLOR_BUFFER_BIT | context.DEPTH_BUFFER_BIT);

context.uniformMatrix4fv(u_modelViewPerspectiveLocation, false, mvp);
context.uniform1f(u_heightBlendLocation, heightBlend);

context.activeTexture(context.TEXTURE0);
context.bindTexture(context.TEXTURE_2D, terrainTex1);
context.uniform1i(u_heightLocation, 0);

context.activeTexture(context.TEXTURE1);
context.bindTexture(context.TEXTURE_2D, terrainTex2);
context.uniform1i(u_heightLocation2, 1);

//context.drawElements(context.LINES, numberOfIndices, context.UNSIGNED_SHORT,0);
context.drawElements(context.LINES, numberOfIndices, context.UNSIGNED_SHORT,0);

window.requestAnimFrame(animate);
})();

}());
Loading