Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified .DS_Store
Binary file not shown.
373 changes: 26 additions & 347 deletions README.md
100644 → 100755

Large diffs are not rendered by default.

119 changes: 0 additions & 119 deletions frag_globe.html

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added globe/assets/moon1024.jpg
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 globe/assets/moonBump1024.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
226 changes: 226 additions & 0 deletions globe/frag_globe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<html>

<head>
<title>Fragment Globe</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">
precision highp float;

uniform mat4 u_Model;
uniform mat4 u_View;
uniform mat4 u_Persp;
uniform mat4 u_InvTrans;

attribute vec3 Position;
attribute vec3 Normal;
attribute vec2 Texcoord;

varying vec3 v_Normal;
varying vec2 v_Texcoord;
varying vec3 v_Position;
varying vec3 v_positionMC;

void main(void)
{
v_Normal = (u_InvTrans*vec4(Normal,0.0)).xyz;
v_Texcoord = Texcoord;
vec4 world = u_Model * vec4(Position, 1.0);
vec4 camera = u_View * world;
v_Position = camera.xyz;
v_positionMC = Position;
gl_Position = u_Persp * camera;
}
</script>

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

//View-Space directional light
//A unit vector
uniform vec3 u_CameraSpaceDirLight;

//Diffuse texture map for the day
uniform sampler2D u_DayDiffuse;
//Ambient texture map for the night side
uniform sampler2D u_Night;
//Color map for the clouds
uniform sampler2D u_Cloud;
//Transparency map for the clouds. Note that light areas are where clouds are NOT
//Dark areas are where clouds are present
uniform sampler2D u_CloudTrans;
//Mask of which areas of the earth have specularity
//Oceans are specular, landmasses are not
uniform sampler2D u_EarthSpec;
//Bump map
uniform sampler2D u_Bump;

uniform float u_time;
uniform mat4 u_InvTrans;

varying vec3 v_Normal; // surface normal in camera coordinates
varying vec2 v_Texcoord;
varying vec3 v_Position; // position in camera coordinates
varying vec3 v_positionMC; // position in model coordinates

mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC);

//simplex Noise reference...http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec2 mod289(vec2 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec3 permute(vec3 x) {
return mod289(((x*34.0)+1.0)*x);
}

float snoise(vec2 v){
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);

// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;

// Permutations
i = mod289(i); // Avoid truncation effects in permutation
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 ;

// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)

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;

// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );

// Compute final noise value at P
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){
// surface normal - normalized after rasterization
vec3 normal = normalize(v_Normal);
// normalized eye-to-position vector in camera coordinates
vec3 eyeToPosition = normalize(v_Position);

float center = texture2D(u_Bump, v_Texcoord).r;
float right = texture2D(u_Bump, v_Texcoord + vec2(1.0/1024.0,0.0)).r; //one texel to the right on x-axis
float up = texture2D(u_Bump, v_Texcoord + vec2(0.0,1.0/512.0)).r; //one texel on the top on y-axis

float earthSpecMask = texture2D(u_EarthSpec, v_Texcoord).r;
vec3 noise = vec3(center - right, center - up, 0.2);
if(earthSpecMask>0.5){
noise.x = .02 * snoise(30.0 * vec2(v_positionMC) - 15.0 * vec2(u_time, u_time))
* snoise(30.0 * vec2(v_positionMC.z - 5.0 * u_time, v_positionMC.y - 5.0 * u_time));
}

// perturbedNormal = normalize(vec3(center - right, center - up, 0.2));
mat3 eyeToTangent = eastNorthUpToEyeCoordinates(v_positionMC, normal);
vec3 perturbedNormal = normalize(eyeToTangent * noise);

float diffuse = clamp(dot(u_CameraSpaceDirLight, normal), 0.0, 1.0);
float diffuse_bump = clamp(dot(u_CameraSpaceDirLight, perturbedNormal), 0.0, 1.0);

vec3 toReflectedLight = reflect(-u_CameraSpaceDirLight, perturbedNormal);
float specular = max(dot(toReflectedLight, -eyeToPosition), 0.0);

if(earthSpecMask>0.5)
specular = pow(specular, 20.0);

float gammaCorrect = 1.0/1.1; //gamma correct by 1/1.2

vec3 dayColor = texture2D(u_DayDiffuse, v_Texcoord).rgb;
vec3 nightColor = texture2D(u_Night, v_Texcoord).rgb;
//apply gamma correction to nighttime texture
nightColor = pow(nightColor,vec3(gammaCorrect));

//clouds
vec2 cloudTexCoord = vec2(v_Texcoord.s - u_time/5.0, v_Texcoord.t);
vec3 cloudColor = texture2D(u_Cloud, cloudTexCoord).rgb;
float cloudTrans = texture2D(u_CloudTrans, cloudTexCoord).r;

vec3 color;

vec3 dayColor_Final = mix(cloudColor, ((0.6 * diffuse_bump) + (0.4 * specular)) * dayColor, cloudTrans);
vec3 nightColor_Final = mix(vec3(0,0,0), nightColor, cloudTrans);

if(diffuse > 0.2)
color = dayColor_Final;
else if(diffuse > 0.0)
color = mix(nightColor_Final, dayColor_Final, diffuse/0.2);
else
color = nightColor_Final;


// Rim Lighting
float rimFactor = dot(v_Normal, v_Position) + 1.0;
vec3 rimColor;
if(rimFactor > 0.0)
rimColor = vec3((rimFactor) / 4.0, (rimFactor) / 2.0, (rimFactor) / 2.0);

gl_FragColor = vec4(color+rimColor, 1.0);
}

mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)
{
// normalized surface tangent in model coordinates
vec3 tangentMC = normalize(vec3(-positionMC.z, positionMC.x, 0.0));
// normalized surface tangent in eye coordiantes
vec3 tangentEC = normalize(mat3(u_InvTrans) * tangentMC);
// normalized surface bitangent in eye coordinates
vec3 bitangentEC = normalize(cross(normalEC, tangentEC));

return mat3(
tangentEC.x, tangentEC.y, tangentEC.z,
bitangentEC.x, bitangentEC.y, bitangentEC.z,
normalEC.x, normalEC.y, normalEC.z);
}
</script>



<script src="js/stats.min.js" type="text/javascript"></script>
<script src="js/lib/gl-matrix.js" type="text/javascript"></script>
<script src="js/webGLUtility.js" type="text/javascript"></script>
<script src="js/frag_globe.js" type="text/javascript"></script>
</body>

</html>
Loading