Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WebGLobe submission #17

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b9ab8fc
Sin wave done.
rohith10 Nov 4, 2013
eedb152
Simplex Wave done. High Colour is now Green.
rohith10 Nov 4, 2013
d557fcd
Some reorganization.
rohith10 Nov 4, 2013
e10a6ad
Night Lights, Spec Mapping done.
rohith10 Nov 4, 2013
414d79d
Smooth transition from day to night.
rohith10 Nov 4, 2013
b24c53e
Rim lighting.
rohith10 Nov 5, 2013
81b2226
Some adjustments.
rohith10 Nov 5, 2013
e592b1d
Moving clouds!
rohith10 Nov 6, 2013
fd14532
Bump mapping done.
rohith10 Nov 6, 2013
b6c7ed6
Preliminary POM
rohith10 Nov 7, 2013
61bb589
POM debugged and code complete. Effect not visible.
rohith10 Nov 8, 2013
bdb2a97
Some reorganization.
rohith10 Nov 8, 2013
65f8c96
Heightmap colouring done.
rohith10 Nov 8, 2013
f1301b4
Sawtooth wave.
rohith10 Nov 8, 2013
dbf04a1
Merge branch 'pom'
rohith10 Nov 8, 2013
7c45fce
Created flag wav html and js.
rohith10 Nov 8, 2013
3a96896
Added texture for flag; corrected a couple of minor errors.
rohith10 Nov 8, 2013
5abbc16
Flag texturing complete. Slight glitch to be rectified.
rohith10 Nov 9, 2013
8d09d4c
Merge branch 'flag-texturing'
rohith10 Nov 9, 2013
364621e
Restored lerping between min and max samples; Added files for readme.
rohith10 Nov 9, 2013
66a0967
Update README.md
rohith10 Nov 9, 2013
da22f6c
Implementation diagram.
rohith10 Nov 9, 2013
70477b6
Update README.md
rohith10 Nov 9, 2013
5fb3ba4
Added code to pause rotation of globe; Added POM/BumpMap Comparison i…
rohith10 Nov 9, 2013
ac5a6c1
Update README.md
rohith10 Nov 9, 2013
ef43774
Update README.md
rohith10 Nov 9, 2013
c55c701
Better heightmap shading.
rohith10 Nov 9, 2013
d88fa3b
Back face culling for better visualization.
rohith10 Nov 9, 2013
632d480
New heightmap screenshot.
rohith10 Nov 9, 2013
f140c08
Update README.md
rohith10 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
460 changes: 89 additions & 371 deletions README.md

Large diffs are not rendered by default.

Binary file added part1/flag1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions part1/flag_wave.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<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">
attribute vec2 position;
attribute vec2 Texcoord;

uniform mat4 u_modelViewPerspective;
uniform float u_time;

varying float height;
varying vec2 Texcoord2;

void main(void)
{
height = sin (2.0*3.141596*position.x + u_time) * cos (2.0*3.141596*position.y + u_time);
Texcoord2 = position;
gl_Position = u_modelViewPerspective * vec4(vec3(position, height), 1.0);
}
</script>

<script id="fs" type="x-shader/x-fragment">
precision mediump float;
uniform sampler2D u_FlagSampler;
varying float height;
varying vec2 Texcoord2;

void main(void)
{
// vec3 lowColour = vec3 (1.0, 0.0, 0.0);
// vec3 highColour = vec3 (0.0, 1.0, 0.0);
vec3 fl_Colour = texture2D (u_FlagSampler, Texcoord2).rgb;
gl_FragColor = vec4(fl_Colour, 1.0);
}
</script>

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

</html>
46 changes: 46 additions & 0 deletions part1/my_wave.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<html>

<head>
<title>Sawtooth 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">
attribute vec2 position;

uniform mat4 u_modelViewPerspective;
uniform float u_time;

varying float height;

void main(void)
{
float currentPos = position.y + u_time;
height = currentPos - floor (currentPos);
gl_Position = u_modelViewPerspective * vec4(vec3(position, height), 1.0);
}
</script>

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

varying float height;
void main(void)
{
vec3 lowColour = vec3 (1.0, 0.0, 0.0);
vec3 highColour = vec3 (0.0, 1.0, 0.0);
gl_FragColor = vec4(mix (lowColour, highColour, height), 1.0);
}
</script>

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

</html>
88 changes: 88 additions & 0 deletions part1/simplex_wave.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<html>

<head>
<title>Simplex 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">
attribute vec2 position;

uniform mat4 u_modelViewPerspective;
uniform float u_time;

varying float height;

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)
{
float value1 = simplexNoise (vec2 (u_time*0.5, position));
float value2 = simplexNoise (vec2 (value1, u_time*0.5));
height = value1 * value2;
gl_Position = u_modelViewPerspective * vec4(vec3(position, height), 1.0);
}
</script>

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

varying float height;
void main(void)
{
vec3 lowColour = vec3 (1.0, 0.0, 0.0);
vec3 highColour = vec3 (0.0, 1.0, 0.0);
gl_FragColor = vec4(mix (lowColour, highColour, height+0.5), 1.0);
}
</script>

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

</html>
14 changes: 10 additions & 4 deletions part1/vert_wave.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@
attribute vec2 position;

uniform mat4 u_modelViewPerspective;
uniform float u_time;

varying float height;

void main(void)
{
float height = 0.0;
height = sin (2.0*3.141596*position.x + u_time) * cos (2.0*3.141596*position.y + u_time);
gl_Position = u_modelViewPerspective * vec4(vec3(position, height), 1.0);
}
</script>

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


varying float height;
void main(void)
{
gl_FragColor = vec4(vec3(0.0), 1.0);
vec3 lowColour = vec3 (1.0, 0.0, 0.0);
vec3 highColour = vec3 (0.0, 1.0, 0.0);
gl_FragColor = vec4(mix (lowColour, highColour, height+0.5), 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>
<script src ="wavebase.js" type ="text/javascript"></script>
</body>

</html>
7 changes: 7 additions & 0 deletions part1/vert_wave.js → part1/wavebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

var NUM_WIDTH_PTS = 32;
var NUM_HEIGHT_PTS = 32;

var curTime = 0;

var message = document.getElementById("message");
var canvas = document.getElementById("canvas");
Expand All @@ -31,6 +33,7 @@
var positionLocation = 0;
var heightLocation = 1;
var u_modelViewPerspectiveLocation;
var u_timeLocation;

(function initializeShader() {
var program;
Expand All @@ -40,6 +43,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);
})();
Expand Down Expand Up @@ -137,12 +141,15 @@
mat4.multiply(view, model, mv);
var mvp = mat4.create();
mat4.multiply(persp, mv, mvp);
curTime += 0.01;

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

context.uniformMatrix4fv(u_modelViewPerspectiveLocation, false, mvp);
context.uniform1f (u_timeLocation, curTime);

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

window.requestAnimFrame(animate);
Expand Down
Loading