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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*.a

# Visual Studio Stuff
*.opensdf
*.sdf
*.suo
*.pdb
*ipch/
Expand Down
Binary file added GlobeRender.wmv
Binary file not shown.
285 changes: 30 additions & 255 deletions README.md

Large diffs are not rendered by default.

Binary file added SSAO.wmv
Binary file not shown.
Binary file added VertexShading.wmv
Binary file not shown.
13 changes: 13 additions & 0 deletions part1/Globe/Globe/Globe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ static const int NUM_LONGITUDE_PTS = LONGITUDE_DIVISIONS + 1;
static const int NUM_LATITUDE_PTS = LATITUDE_DIVISIONS + 1;
static const float RADIUS = 1;

enum RenderType {
TEXTURE,
ALTITUDE
};
int renderType = TEXTURE;

//r theta phi
vec3 computeSpherical(vec2 uv, float radius) {
vec3 out;
Expand Down Expand Up @@ -274,6 +280,7 @@ void display(void)
glUniformMatrix4fv(glGetUniformLocation(current_prog,"u_Persp"),1,GL_FALSE,&persp[0][0]);
glUniformMatrix4fv(glGetUniformLocation(current_prog,"u_InvTrans") ,1,GL_FALSE,&inverse_transposed[0][0]);
glUniform1f(glGetUniformLocation(current_prog,"u_time"), time);
glUniform1i(glGetUniformLocation(current_prog,"u_renderType"), renderType);

glDrawElements(GL_TRIANGLES, current_mesh.num_indices, GL_UNSIGNED_SHORT,0);

Expand Down Expand Up @@ -336,6 +343,12 @@ void keyboard(unsigned char key, int x, int y) {
case '-':
slowDownRotation();
break;
case '1':
renderType = TEXTURE;
break;
case '2':
renderType = ALTITUDE;
break;
}
}

Expand Down
62 changes: 57 additions & 5 deletions part1/Globe/Globe/fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ uniform sampler2D u_CloudTrans;
uniform sampler2D u_EarthSpec;
//Bump map
uniform sampler2D u_Bump;
vec2 u_bumpStep = vec2(1.0/1000, 1.0/500);

uniform float u_time;
uniform mat4 u_InvTrans;
uniform int u_renderType;
// make sure that these numbers are matched to enum in Globe.cpp
const int TEXTURE = 0;
const int ALTITUDE = 1;

varying vec3 v_Normal; // surface normal in camera coordinates
varying vec2 v_Texcoord;
Expand All @@ -29,21 +34,68 @@ mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC);

void main(void)
{
vec3 normal = normalize(v_Normal); // surface normal - normalized after rasterization
float top_bump = texture2D(u_Bump, vec2(v_Texcoord.s, v_Texcoord.t + u_bumpStep.t)).r;
float right_bump = texture2D(u_Bump, vec2(v_Texcoord.s + u_bumpStep.s, v_Texcoord.t)).r;
float center_bump = texture2D(u_Bump, v_Texcoord).r;
vec3 bumpNormalMC = normalize(vec3(center_bump - right_bump, center_bump - top_bump, 0.2));

if (u_renderType == ALTITUDE) {
const vec3 orange = vec3(1.0, 0.565, 0.0);
const vec3 red = vec3(1.0, 0.0, 0.0);
const vec3 green = vec3(0.0, 1.0, 0.0);
const vec3 blue = vec3(0.0, 0.0, 1.0);
if (center_bump < 0.0001) {
gl_FragColor = vec4(blue, 1.0);
} else if (center_bump > 0.99) {
gl_FragColor = vec4(red, 1.0);
} else if (center_bump >= 0.5) {
gl_FragColor = mix(vec4(orange, 1.0), vec4(red, 1.0), (1.0/-log(2*(center_bump-0.5))));
} else {
gl_FragColor = mix(vec4(green, 1.0), vec4(orange, 1.0), 1.0/-log(2*center_bump));
}
return;
}

vec3 normal = normalize(eastNorthUpToEyeCoordinates(v_positionMC, v_Normal) * bumpNormalMC);
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);

vec4 dayColor = texture2D(u_DayDiffuse, v_Texcoord);

float gammaCorrect = 1/1.8; //gamma correct by 1/1.8
//apply gamma correction to nighttime texture
float gammaCorrect = 1/1.8;
vec4 nightColor = texture2D(u_Night, v_Texcoord);
nightColor.r = pow(nightColor.r, gammaCorrect);
nightColor.g = pow(nightColor.g, gammaCorrect);
nightColor.b = pow(nightColor.b, gammaCorrect);

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

vec4 dayColor_cloud_blends = mix(texture2D(u_Cloud, v_Texcoord),
((0.6 * diffuse) + (0.4 * specular * earthSpec)) * dayColor,
texture2D(u_CloudTrans, v_Texcoord));
vec4 nightColor_cloud_blends = mix(vec4(0.0, 0.0, 0.0, 1.0),
nightColor,
texture2D(u_CloudTrans, v_Texcoord));

float light_normal_dot = max(dot(u_CameraSpaceDirLight, normalize(v_Normal)), 0.0);
if (light_normal_dot > 0.1) {
gl_FragColor = dayColor_cloud_blends;
} else if (light_normal_dot > 0.0) {
gl_FragColor = mix(nightColor_cloud_blends, dayColor_cloud_blends, 10.0*light_normal_dot);
} else {
gl_FragColor = nightColor_cloud_blends;
}

gl_FragColor = ((0.6 * diffuse) + (0.4 * specular)) * dayColor;
float rimFactor = dot(v_Normal, v_Position) + 1.0;
if (rimFactor > 0.0) {
gl_FragColor = clamp(gl_FragColor + vec4(rimFactor/4, rimFactor/2, rimFactor/2, 1), 0.0, 1.0);
}
}

mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)
Expand Down
35 changes: 33 additions & 2 deletions part2/565GLFrame/565GLFrame/ssao.frag
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,45 @@ float gatherOcclusion( vec3 pt_normal,
vec3 pt_position,
vec3 occluder_normal,
vec3 occluder_position) {
return -1.0f;///IMPLEMENT THIS
const vec3 position_diff = occluder_position - pt_position;
const float dist = length(position_diff);

// factor1: distance
float occlusion = 1.0 / (1.0 + dist);

// factor2: co-planar
occlusion *= 1 - abs(dot(normalize(pt_normal), normalize(occluder_normal)));

// factor3: incident angle
occlusion *= max(0.0, dot(normalize(pt_normal), normalize(position_diff)));

return occlusion;
}

const float REGULAR_SAMPLE_STEP = 0.012f;
#define SAMPLE_RECT_WIDTH 4 // even, indicates 4x4 samples
float occlusionWithRegularSamples(vec2 texcoord,
vec3 position,
vec3 normal) {
return -1.0f; //IMPLEMENT THIS
float occlusion = 0.0;
const vec2 upperLeft
= texcoord + vec2(-(SAMPLE_RECT_WIDTH-1)*0.5*REGULAR_SAMPLE_STEP,
(SAMPLE_RECT_WIDTH-1)*0.5*REGULAR_SAMPLE_STEP);
vec2 offset, sample_texcoord;
for (int y = 0; y < SAMPLE_RECT_WIDTH; y++) {
offset.y = -REGULAR_SAMPLE_STEP * y;
for (int x = 0; x < SAMPLE_RECT_WIDTH; x++) {
offset.x = REGULAR_SAMPLE_STEP * x;
sample_texcoord = upperLeft + offset;

occlusion += gatherOcclusion(normal,
position,
sampleNrm(sample_texcoord),
samplePos(sample_texcoord));
} // for x
} // for y

return occlusion / (SAMPLE_RECT_WIDTH*SAMPLE_RECT_WIDTH);
}


Expand Down
26 changes: 26 additions & 0 deletions part3/565GLFrame/565GLFrame.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SOIL", "SOIL\SOIL.vcxproj", "{25544C77-3B78-405F-A15D-1231D05969F3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "565GLFrame", "565GLFrame\565GLFrame.vcxproj", "{BE7096A9-AE60-4A3E-95B1-ACBFF084E9C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{25544C77-3B78-405F-A15D-1231D05969F3}.Debug|Win32.ActiveCfg = Debug|Win32
{25544C77-3B78-405F-A15D-1231D05969F3}.Debug|Win32.Build.0 = Debug|Win32
{25544C77-3B78-405F-A15D-1231D05969F3}.Release|Win32.ActiveCfg = Release|Win32
{25544C77-3B78-405F-A15D-1231D05969F3}.Release|Win32.Build.0 = Release|Win32
{BE7096A9-AE60-4A3E-95B1-ACBFF084E9C3}.Debug|Win32.ActiveCfg = Debug|Win32
{BE7096A9-AE60-4A3E-95B1-ACBFF084E9C3}.Debug|Win32.Build.0 = Debug|Win32
{BE7096A9-AE60-4A3E-95B1-ACBFF084E9C3}.Release|Win32.ActiveCfg = Release|Win32
{BE7096A9-AE60-4A3E-95B1-ACBFF084E9C3}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
59 changes: 59 additions & 0 deletions part3/565GLFrame/565GLFrame/565GLFrame.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="GLSL">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
<Filter Include="Resources">
<UniqueIdentifier>{6f59ee02-fbfd-456b-aaac-7b7db5e1b49a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Utility.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Utility.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="pass.frag">
<Filter>GLSL</Filter>
</None>
<None Include="pass.vert">
<Filter>GLSL</Filter>
</None>
<None Include="ssao.frag">
<Filter>GLSL</Filter>
</None>
<None Include="ssao.vert">
<Filter>GLSL</Filter>
</None>
<None Include="city.txt">
<Filter>Resources</Filter>
</None>
<None Include="random_normal.png">
<Filter>Resources</Filter>
</None>
<None Include="random_scalar.jpg">
<Filter>Resources</Filter>
</None>
</ItemGroup>
</Project>
Loading