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
  •  
  •  
  •  
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
CIS565: Project 5: Advanced GLSL
-------------------------------------------------------------------------------
Fall 2012
-------------------------------------------------------------------------------
--------------------------------------------------------------
My Notes:

Blog can be found at http://glslvsfs.blogspot.com/


Part 1:
Implemented all the basic stuff and added a revolving moon to as the extra feature. The rim doesn't look too bright because I just intentionally reduced it. Created a hack for the moon, but it works :)

Part 2:
Implemented regular grid, poisson sphere and poisson sphere in the world.
I was finding differences in values between world coordinates and projected screen coordinates. So another hack for it to work ;). The change in camera angle changes AO a lot in the world view, it maybe due to the way I have implemented it.

Part 3:
Implemented pulsing on the Stanford Dragon.
Implemented skinning. Not working very great as I had expected, but a basic version. The screenshot shows an extreme version of skinning (which no one will ever do). It has 3 joints and the image just rotates it in 3 different directions.



-----------------
Due Monday 11/19/2012
-------------------------------------------------------------------------------

Expand Down
Binary file added part1/Globe/Globe.sdf
Binary file not shown.
108 changes: 78 additions & 30 deletions part1/Globe/Globe/Globe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ static GLuint cloud_tex;
static GLuint cloudtrans_tex;
static GLuint earthspec_tex;
static GLuint disp_tex;
static GLuint moon_tex;

static const int LONGITUDE_DIVISIONS = 75;
static const int LATITUDE_DIVISIONS = 75;
static const int NUM_LONGITUDE_PTS = LONGITUDE_DIVISIONS + 1;
static const int NUM_LATITUDE_PTS = LATITUDE_DIVISIONS + 1;
static const float RADIUS = 1;
static const float RADIUS_MOON = 0.21;

//r theta phi
vec3 computeSpherical(vec2 uv, float radius) {
Expand Down Expand Up @@ -69,47 +71,86 @@ vec3 computeNormal(vec3 spherical) {
return computePosition(new_spherical);
}

void appendPoint(mesh_t * mesh, vec2 uv, float radius) {
void appendPoint(mesh_t * mesh, vec2 uv, float radius, vec3 offset) {
vec3 spherical = computeSpherical(uv, radius);
vec3 position = computePosition(spherical);
vec3 normal = computeNormal(spherical);
mesh->vertices.push_back(position);
mesh->vertices.push_back(position+offset);
mesh->uvs.push_back(uv);
mesh->normals.push_back(normal);
}

//Trig Time
void initSphere() {

mesh_t sphere;
//Check assumptions
assert(LATITUDE_DIVISIONS >= 2);
assert(LONGITUDE_DIVISIONS >= 3);
//drop starting row. Notice num_pts = num_dvisions + 1
for (int i = 0; i < NUM_LONGITUDE_PTS; i ++) {
vec2 uv(i / (float)(NUM_LONGITUDE_PTS - 1),0);
appendPoint(&sphere, uv, RADIUS);
{
vec3 offset = vec3(0,0,0);
//Check assumptions
assert(LATITUDE_DIVISIONS >= 2);
assert(LONGITUDE_DIVISIONS >= 3);
//drop starting row. Notice num_pts = num_dvisions + 1
for (int i = 0; i < NUM_LONGITUDE_PTS; i ++) {
vec2 uv(i / (float)(NUM_LONGITUDE_PTS - 1),0);
appendPoint(&sphere, uv, RADIUS, offset);
}

for (int j = 0; j < LATITUDE_DIVISIONS; j++) {
float v = (j + 1)/((float)NUM_LATITUDE_PTS-1);
//Set up first point
vec2 first_uv(0.0f,v);
appendPoint(&sphere, first_uv,RADIUS, offset);
//Iterate over divisions
for (int i = 0; i < LONGITUDE_DIVISIONS; i++) {
//Setup new point
vec2 new_uv((i+1)/((float)NUM_LONGITUDE_PTS - 1),v);
appendPoint(&sphere,new_uv, RADIUS, offset);
unsigned short length = (unsigned short)sphere.vertices.size();
unsigned short upper_right = length - 1;
unsigned short lower_right = upper_right - NUM_LONGITUDE_PTS;
unsigned short lower_left = lower_right - 1;
unsigned short upper_left = lower_left + NUM_LONGITUDE_PTS;
unsigned short added [] = {upper_left, lower_right, upper_right,
upper_left, lower_left, lower_right};
for (int i = 0; i < 6; ++i) { sphere.indices.push_back(added[i]); }
}
}
}

//mesh_t sphere1;
{
vec3 offset = vec3(0,1.35,-0.2);
//Check assumptions
assert(LATITUDE_DIVISIONS >= 2);
assert(LONGITUDE_DIVISIONS >= 3);
//drop starting row. Notice num_pts = num_dvisions + 1
for (int i = 0; i < NUM_LONGITUDE_PTS; i ++) {
vec2 uv(i / (float)(NUM_LONGITUDE_PTS - 1),0);
appendPoint(&sphere, uv, RADIUS_MOON, offset);
}

for (int j = 0; j < LATITUDE_DIVISIONS; j++) {
float v = (j + 1)/((float)NUM_LATITUDE_PTS-1);
//Set up first point
vec2 first_uv(0.0f,v);
appendPoint(&sphere, first_uv,RADIUS);
//Iterate over divisions
for (int i = 0; i < LONGITUDE_DIVISIONS; i++) {
//Setup new point
vec2 new_uv((i+1)/((float)NUM_LONGITUDE_PTS - 1),v);
appendPoint(&sphere,new_uv, RADIUS);
unsigned short length = (unsigned short)sphere.vertices.size();
unsigned short upper_right = length - 1;
unsigned short lower_right = upper_right - NUM_LONGITUDE_PTS;
unsigned short lower_left = lower_right - 1;
unsigned short upper_left = lower_left + NUM_LONGITUDE_PTS;
unsigned short added [] = {upper_left, lower_right, upper_right,
upper_left, lower_left, lower_right};
for (int i = 0; i < 6; ++i) { sphere.indices.push_back(added[i]); }
for (int j = 0; j < LATITUDE_DIVISIONS; j++) {
float v = (j + 1)/((float)NUM_LATITUDE_PTS-1);
//Set up first point
vec2 first_uv(0.0f,v);
appendPoint(&sphere, first_uv,RADIUS_MOON, offset);
//Iterate over divisions
for (int i = 0; i < LONGITUDE_DIVISIONS; i++) {
//Setup new point
vec2 new_uv((i+1)/((float)NUM_LONGITUDE_PTS - 1),v);
appendPoint(&sphere,new_uv, RADIUS_MOON, offset);
unsigned short length = (unsigned short)sphere.vertices.size();
unsigned short upper_right = length - 1;
unsigned short lower_right = upper_right - NUM_LONGITUDE_PTS;
unsigned short lower_left = lower_right - 1;
unsigned short upper_left = lower_left + NUM_LONGITUDE_PTS;
unsigned short added [] = {upper_left, lower_right, upper_right,
upper_left, lower_left, lower_right};
for (int i = 0; i < 6; ++i) { sphere.indices.push_back(added[i]); }
}
}
}

device_sphere = uploadMesh(sphere);
}

Expand Down Expand Up @@ -232,7 +273,7 @@ void rotate(float dx, float dy) {


void initView() {
dist = 4.0f;
dist = 6.0f;
rx = -140.0f;
ry = 0.0f;
}
Expand All @@ -251,7 +292,7 @@ float time = 0.0;

void display(void)
{
time += 0.0001f;
time += 0.2*PI/180.0;

// clear the screen
glClearColor(0.0f,0.0f,0.0f,1.0f);
Expand All @@ -274,6 +315,8 @@ 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);
vec3 worldLightDir = normalize(worlddirlight);
glUniform3fv(glGetUniformLocation(current_prog,"u_WorldSpaceDirLight"),1, &worldLightDir[0]);

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

Expand All @@ -294,7 +337,9 @@ void initGlobeShader() {
cloud_tex = (unsigned int)SOIL_load_OGL_texture("earthcloudmap.jpg",0,0,0);
cloudtrans_tex = (unsigned int)SOIL_load_OGL_texture("earthcloudmaptrans.jpg",0,0,0);
earthspec_tex = (unsigned int) SOIL_load_OGL_texture("earthspec1k.jpg",0,0,0);
disp_tex = (unsigned int) SOIL_load_OGL_texture("earthbump1k.jpg",0,0,0);
disp_tex = (unsigned int) SOIL_load_OGL_texture("earthbump1k.jpg",0,0,0);
moon_tex = (unsigned int)SOIL_load_OGL_texture("moonmap4k.jpg",0,0,0);

glBindTexture(GL_TEXTURE_2D, cloudtrans_tex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D, 0);
Expand Down Expand Up @@ -325,6 +370,9 @@ void setGlobeShader() {
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, disp_tex);
glUniform1i(glGetUniformLocation(current_prog, "u_Bump"),5);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, moon_tex);
glUniform1i(glGetUniformLocation(current_prog, "u_Moon"),6);

}

Expand Down
2 changes: 1 addition & 1 deletion part1/Globe/Globe/Globe.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void setGlobeShader();
glm::vec3 computeSpherical(glm::vec2 uv, float radius);
glm::vec3 computePosition(glm::vec3 spherical) ;
glm::vec3 computeNormal(glm::vec3 spherical);
void appendPoint(mesh_t * mesh, glm::vec2 uv, float radius);
void appendPoint(mesh_t * mesh, glm::vec2 uv, float radius, glm::vec3 offset);
void initSphere();
device_mesh_t uploadMesh(const mesh_t & mesh);

Expand Down
72 changes: 67 additions & 5 deletions part1/Globe/Globe/fs.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//View-Space directional light
//A unit vector
uniform vec3 u_CameraSpaceDirLight;
uniform vec3 u_WorldSpaceDirLight;
uniform mat4 u_Model;
uniform mat4 u_View;
uniform mat4 u_Persp;

//Diffuse texture map for the day
uniform sampler2D u_DayDiffuse;
Expand All @@ -16,6 +20,8 @@ uniform sampler2D u_CloudTrans;
uniform sampler2D u_EarthSpec;
//Bump map
uniform sampler2D u_Bump;
//Moon map
uniform sampler2D u_Moon;

uniform float u_time;
uniform mat4 u_InvTrans;
Expand All @@ -24,6 +30,7 @@ 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
varying vec3 v_positionWorld; // position in model coordinates

mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC);

Expand All @@ -32,18 +39,73 @@ 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);
float dotProd = dot(u_CameraSpaceDirLight, normal);

vec4 center = texture2D(u_Bump, v_Texcoord);
vec4 right = texture2D(u_Bump, vec2(v_Texcoord.x+1.0/1000.0, v_Texcoord.y));
vec4 top = texture2D(u_Bump, vec2(v_Texcoord.x, v_Texcoord.y+1.0/500.0));
vec3 newNormal = normalize(vec3(center.x - right.x, center.y - top.y, 0.2));
mat3 matrix = eastNorthUpToEyeCoordinates(v_positionMC, normal);
newNormal = matrix*newNormal;
newNormal = normalize(newNormal);

vec3 toReflectedLight = reflect(-u_CameraSpaceDirLight, normal);
float newdotProd = dot(u_CameraSpaceDirLight, newNormal);
float diffuse = max(newdotProd, 0.0);

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

float gammaCorrect = 1/1.8; //gamma correct by 1/1.8
float gammaCorrect = 1.0/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
vec4 ocean = texture2D(u_EarthSpec, v_Texcoord);

vec4 cloudColor = texture2D(u_Cloud, vec2(v_Texcoord.s+0.02*u_time, v_Texcoord.t));
vec4 cloudTransp = texture2D(u_CloudTrans, vec2(v_Texcoord.s+0.02*u_time, v_Texcoord.t));

vec4 finalDayColor = mix(cloudColor, ((0.6 * diffuse) + (0.4 * specular)*ocean) * dayColor, cloudTransp);
vec4 nightColor = mix(0.0, pow(texture2D(u_Night, v_Texcoord),gammaCorrect), cloudTransp); //apply gamma correction to nighttime texture

// Rim lighting
float rimFactor = dot(v_Normal, v_Position)+0.6;
float rim = 0.6;
vec4 newColor = mix(nightColor, finalDayColor, clamp(2.0*(dotProd+0.25),0.0,1.0));

vec4 shadowColor = vec4(1);
bool inShadow = false;
//if (v_positionMC.y < 1.1)
//{
// // Shadow
// // Imagine that the clouds are at a height of say 0.2 above the ground
//
// float cloudDistFromGround = 0.01;
// vec3 cloudHitPoint = v_Position + u_WorldSpaceDirLight * cloudDistFromGround;

// // Transform this point to screen
// vec4 cloudScreen = u_Persp * (u_View* (u_Model * vec4(cloudHitPoint, 1.0)));
// vec2 cloudScreenPoint = cloudScreen.xy/cloudScreen.w;
// cloudScreenPoint = cloudScreenPoint*0.5 + 0.5;

// vec4 cloudShadow = texture2D(u_Cloud, cloudScreenPoint);
// vec4 cloudShadowTransp = texture2D(u_CloudTrans, cloudScreenPoint);

// if (cloudShadowTransp.x <0.8 || cloudShadowTransp.y <0.8)
// {
// inShadow = true;
// shadowColor = vec4(1.0-cloudShadowTransp);
// }
//}

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

// Mixing color and rim factor to get the final color of the fragment
if (v_positionMC.y > 1.1)
gl_FragColor = texture2D(u_Moon, v_Texcoord);
else
{
vec4 finalColor = mix(newColor, vec4(rim/4.0, rim/2.0, rim/2.0, 1.0), clamp(2.0*(rimFactor+0.25),0.0,1.0));
gl_FragColor = mix(vec4(0.0,0.0,0.0,finalColor.w), finalColor, shadowColor);
}
}

mat3 eastNorthUpToEyeCoordinates(vec3 positionMC, vec3 normalEC)
Expand Down
Binary file added part1/Globe/Globe/moonmap4k.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions part1/Globe/Globe/vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ uniform mat4 u_Model;
uniform mat4 u_View;
uniform mat4 u_Persp;
uniform mat4 u_InvTrans;
uniform float u_time;

attribute vec3 Position;
attribute vec3 Normal;
Expand All @@ -11,14 +12,24 @@ varying vec3 v_Normal;
varying vec2 v_Texcoord;
varying vec3 v_Position;
varying vec3 v_positionMC;
varying vec3 v_positionWorld;

void main(void)
{
vec3 pos = Position;

if (Position.y > 1.1)
{
pos.x -= 1.7*sin(u_time);
pos.z += 1.7*cos(u_time);
//Position.z += cos(u_time);
}
v_Normal = (u_InvTrans*vec4(Normal,0.0)).xyz;
v_Texcoord = Texcoord;
vec4 world = u_Model * vec4(Position, 1.0);
vec4 world = u_Model * vec4(pos, 1.0);
vec4 camera = u_View * world;
v_Position = camera.xyz;
v_positionMC = Position;
v_positionMC = pos;
v_positionWorld = world.xyz;
gl_Position = u_Persp * camera;
}
Binary file added part2/565GLFrame/565GLFrame.sdf
Binary file not shown.
2 changes: 2 additions & 0 deletions part2/565GLFrame/565GLFrame/565GLFrame.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
<ClInclude Include="Utility.h" />
</ItemGroup>
<ItemGroup>
<None Include="blur.frag" />
<None Include="blur.vert" />
<None Include="pass.frag" />
<None Include="pass.vert" />
<None Include="random.png" />
Expand Down
6 changes: 6 additions & 0 deletions part2/565GLFrame/565GLFrame/565GLFrame.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<None Include="random.png">
<Filter>Resources</Filter>
</None>
<None Include="blur.frag">
<Filter>Source Files</Filter>
</None>
<None Include="blur.vert">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">
Expand Down
5 changes: 5 additions & 0 deletions part2/565GLFrame/565GLFrame/565GLFrame.vcxproj.tease.nvuser
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ProjectSettingsModel DefinitionId="a218e900-1199-4ab1-a767-7976786f04d4" DisplayName="Nexus Project User Settings" xmlns="clr-namespace:Ark.PropertyModel;assembly=Ark">
<SettingsPointModel DefinitionId="3eb7ba04-016d-475e-b0ff-daa5f0e59a08" DisplayName="Launch">
<Property Name="Arguments" Value="mesh=../sponza.obj" />
</SettingsPointModel>
</ProjectSettingsModel>
4 changes: 4 additions & 0 deletions part2/565GLFrame/565GLFrame/565GLFrame.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<LocalDebuggerCommandArguments>mesh=../sponza.obj</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>mesh=../sponza.obj</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
Loading