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

Submission #2

Open
wants to merge 5 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
596 changes: 309 additions & 287 deletions README.md

Large diffs are not rendered by default.

Binary file added part1/Globe/Globe.sdf
Binary file not shown.
Binary file added part1/Globe/Globe/MoonTexture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 94 additions & 58 deletions part1/Globe/Globe/fs.glsl
Original file line number Diff line number Diff line change
@@ -1,59 +1,95 @@
//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 were 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);

void main(void)
{
vec3 normal = normalize(v_Normal); // surface normal - normalized after rasterization
vec3 eyeToPosition = normalize(v_Position); // normalized eye-to-position vector in camera coordinates

float diffuse = max(dot(u_CameraSpaceDirLight, normal), 0.0);

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

float gammaCorrect = 1/1.8; //gamma correct by 1/1.8

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

gl_FragColor = ((0.6 * diffuse) + (0.4 * specular)) * dayColor;
}

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

return mat3(
tangentEC.x, tangentEC.y, tangentEC.z,
bitangentEC.x, bitangentEC.y, bitangentEC.z,
normalEC.x, normalEC.y, normalEC.z);
//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 were 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);


void main(void)
{
vec3 normal = normalize(v_Normal); // surface normal - normalized after rasterization
vec3 eyeToPosition = normalize(v_Position); // normalized eye-to-position vector in camera coordinates
vec3 eyeToPositionMC = normalize(v_positionMC);
vec4 earthSpec = texture2D(u_EarthSpec, v_Texcoord);



//bump mapping
float center = texture2D(u_Bump, v_Texcoord);
float right = texture2D(u_Bump, vec2(v_Texcoord.s + 1/1000.0, v_Texcoord.t));
float top = texture2D(u_Bump, vec2(v_Texcoord.s, v_Texcoord.t + 1/500.0));

//create normal in tangent space
vec3 tempBumpNormal = normalize(vec3(center - right, center - top, 0.2));
mat3 bumpNormal = (eastNorthUpToEyeCoordinates(v_positionMC, tempBumpNormal));



float diffuse = max(dot(u_CameraSpaceDirLight, vec3(bumpNormal[2].xyz)), 0.0);


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

specular = pow(specular, 20.0) * earthSpec;



float gammaCorrect = 1/2.2; //gamma correct by 1/1.8

vec4 dayColor = ((0.6 * diffuse) + (0.4 * specular)) * texture2D(u_DayDiffuse, v_Texcoord );
vec4 nightColor = pow(texture2D(u_Night, v_Texcoord),gammaCorrect); //apply gamma correction to nighttime texture

//cloud implementation
vec2 cloudTexCoord = v_Texcoord +vec2(u_time, 0.0);
float cloudTransmittance = texture2D(u_CloudTrans,cloudTexCoord);
vec4 cloudColor = mix(texture2D(u_Cloud,cloudTexCoord), vec4(0), 1 - diffuse);

dayColor = mix( dayColor, cloudColor, vec4(1) - cloudTransmittance );

nightColor = mix(0.6* nightColor, vec4(0,0,0,0), vec4(1) - cloudTransmittance );

gl_FragColor = mix( dayColor, nightColor, 1 - diffuse);

float rim = dot(v_Normal, v_Position) + 1.0;
if(rim > 0.0)
gl_FragColor += vec4(rim/4, rim/2, rim/2, 1);



}

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

return mat3(
tangentEC.x, tangentEC.y, tangentEC.z,
bitangentEC.x, bitangentEC.y, bitangentEC.z,
normalEC.x, normalEC.y, normalEC.z);
}
52 changes: 28 additions & 24 deletions part1/Globe/Globe/vs.glsl
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
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;
}
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;

uniform float u_time;
uniform sampler2D u_EarthSpec;

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;
}
Binary file added part2/565GLFrame/565GLFrame.sdf
Binary file not shown.
16 changes: 10 additions & 6 deletions part2/565GLFrame/565GLFrame/565GLFrame.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>mesh=../sponza.obj</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>mesh=../sponza.obj</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>mesh=$(ProjectDir)sponza.obj</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
Loading