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

Project 5 finished Pull request #16

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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
319 changes: 28 additions & 291 deletions README.md

Large diffs are not rendered by default.

Binary file added assets/Skybox.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 assets/backImage.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 assets/downImage.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 assets/frontImage.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 assets/leftImage.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 assets/rightImage.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 assets/sky512.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 assets/skybase.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 assets/test.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 assets/upImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 84 additions & 15 deletions frag_globe.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@
<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>

<p> FPS=</p>
<p id="FPS"> 0</p>

<script id="skyboxvs" type="x-shader/x-vertex">
uniform mat4 u_Model;
uniform mat4 u_View;
uniform mat4 u_Persp;
uniform mat4 u_InvTrans;
attribute vec3 Position;
//attribute vec2 Texcoord;

varying vec3 v_Texcoord;
varying vec3 v_Position;
void main() {
gl_Position = u_Persp * u_View * u_Model * vec4(Position, 1.0);
v_Texcoord = Position;
}
</script>

<script id="skyboxfs" type="x-shader/x-fragment">
precision highp float;
varying vec3 v_Texcoord;
uniform samplerCube u_Skybox;

void main (void) {
gl_FragColor = textureCube(u_Skybox, v_Texcoord);
}
</script>

<script id="vs" type="x-shader/x-vertex">
precision highp float;

Expand Down Expand Up @@ -60,7 +89,11 @@
uniform sampler2D u_EarthSpec;
//Bump map
uniform sampler2D u_Bump;

uniform float texupIntv;
uniform float texrtIntv;

uniform sampler2D u_SkyBox;

uniform float u_time;
uniform mat4 u_InvTrans;

Expand All @@ -73,26 +106,62 @@

void main(void)
{
//vec2 normalTexcoord=vec2(v_Texcoord);
float center=length(texture2D(u_Bump,vec2(v_Texcoord.x,v_Texcoord.y)).rgb);

float right=length(texture2D(u_Bump,vec2(v_Texcoord.x+1.0/1024.0,v_Texcoord.y)).rgb);

float top=length(texture2D(u_Bump,vec2(v_Texcoord.x,v_Texcoord.y+1.0/512.0)).rgb);
// surface normal - normalized after rasterization
vec3 normal = normalize(v_Normal);
// normalized eye-to-position vector in camera coordinates
vec3 bpnormal=normalize(vec3(center - right, center - top, 0.2).xyz);
bpnormal=normalize(eastNorthUpToEyeCoordinates(v_positionMC,normal)*bpnormal);

// normalized eye-to-position vector in camera coordinates
vec3 eyeToPosition = normalize(v_Position);

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

float dotval=dot(u_CameraSpaceDirLight, bpnormal);
float diffuse = clamp(dotval, 0.0, 1.0);
vec3 toReflectedLight = reflect(-u_CameraSpaceDirLight, normal);
float specular = max(dot(toReflectedLight, -eyeToPosition), 0.0);

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;
vec3 nightColor = texture2D(u_Night, v_Texcoord).rgb;
//apply gamma correction to nighttime texture
float specFlag=texture2D(u_EarthSpec,v_Texcoord).r;

float gammaCorrect = 1.0/1.2; //gamma correct by 1/1.2
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;
gl_FragColor = vec4(color, 1.0);

vec3 dayColor = texture2D(u_DayDiffuse, v_Texcoord).rgb;

vec2 v_Texcoord_loc=vec2(v_Texcoord);
v_Texcoord_loc.s+=u_time;
vec3 cldDayColor=texture2D(u_Cloud,v_Texcoord_loc).rgb;
vec3 cldNgtColor=texture2D(u_CloudTrans,v_Texcoord_loc).rgb;

dayColor=mix(cldDayColor,dayColor,1.0-cldDayColor.r);
nightColor=mix(vec3(0.0,0.0,0.0),nightColor,cldNgtColor.r);

vec3 rimClr;
float rim=dot(v_Normal,v_Position)+1.0;
rimClr=vec3(rim/4.0,rim/2.0,rim/2.0);

vec3 color;

//specular map
if(specFlag>0.1)
color = ((0.6 * diffuse) + (0.4 * specular)) * dayColor;
else
color = diffuse*dayColor;

//linear intermedia area
if(dotval<-0.2) color=nightColor;
else if(dotval<0.2) color=mix(color,nightColor,.5-2.5*dotval);

if(rim>0.0) color+=rimClr;

gl_FragColor = vec4(color, 1.0);//vec4((bpnormal+vec3(1.0))/2.0,1.0);//
}

mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)
Expand Down
Loading