Skip to content

Commit

Permalink
Moved resource files into their own dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles authored and Charles committed Jan 11, 2017
1 parent a58f2f1 commit 5c0878a
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 0 deletions.
Binary file renamed Possiblev7.zip → Resources/182.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions Resources/BasicFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#version 330 core

struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};

struct PointLight {
vec3 position;

float constant;
float linear;
float quadratic;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

struct DirLight {
vec3 direction;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

struct SpotLight {
vec3 position;
vec3 direction;
float cutOff;
float outerCutOff;

float constant;
float linear;
float quadratic;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

in vec3 FragPos;
in vec3 Normal;
in vec3 ourColor;
in vec2 TexCoords;

out vec4 color;

uniform vec3 viewPos;
uniform Material material;
uniform DirLight dirLight;
uniform SpotLight spotLight;
uniform float time;
uniform float crazyStrength;

// Texture samplers
uniform sampler2D myTexture;

// Function prototypes
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir);
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
vec3 CalcSpotLight(SpotLight light, vec3 norm, vec3 fragPos, vec3 viewDir);

void main()
{
// Properties
vec3 norm = normalize(Normal);
vec3 viewDir = normalize(viewPos - FragPos);

// Directional lighting (sun)
vec3 result = vec3(texture(myTexture, TexCoords));
result *= 0.35;
result += 0.85f;
result *= ourColor;
result *= CalcDirLight(dirLight, norm, viewDir);
// Flash light
result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
result *= (1 - crazyStrength);
vec3 timeColor = vec3(abs(sin(FragPos.y + (time))*sin(FragPos.x + cos(time))), abs(cos(FragPos.z + time)*cos(FragPos.x + sin(time))),abs(sin(FragPos.z + time)*cos(FragPos.x + time)));
timeColor *= crazyStrength;
result += timeColor;

color = vec4(result, 1.0);
}

// Calculates the color when using a directional light.
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
{
vec3 lightDir = normalize(-light.direction);
// Diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// Specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// Combine results
vec3 ambient = light.ambient;
vec3 diffuse = light.diffuse * diff;
vec3 specular = light.specular * spec;
return (ambient + diffuse + specular);
}

// Calculates the color when using a point light.
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
{
vec3 lightDir = normalize(light.position - fragPos);
// Diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// Specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// Attenuation
float distance = length(light.position - fragPos);
float attenuation = 1.0f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
// Combine results
vec3 ambient = light.ambient;
vec3 diffuse = light.diffuse * diff;
vec3 specular = light.specular * spec;
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
return (ambient + diffuse + specular);
}

vec3 CalcSpotLight(SpotLight light, vec3 norm, vec3 fragPos, vec3 viewDir){
// Spotlight (soft edges)
// Ambient
vec3 ambient = light.ambient;

// Diffuse
vec3 lightDir = normalize(light.position - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = light.diffuse * diff;

// Specular
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = light.specular * spec;

// Spotlight (soft edges)
float theta = dot(lightDir, normalize(-light.direction));
float epsilon = (light.cutOff - light.outerCutOff);
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
diffuse *= intensity;
specular *= intensity;

// Attenuation
float distance = length(light.position - FragPos);
float attenuation = 1.0f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;

return (ambient + diffuse + specular);
}
23 changes: 23 additions & 0 deletions Resources/BasicVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec2 texCoord;

out vec3 ourColor;
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f);
ourColor = color;
FragPos = vec3(model * vec4(position, 1.0f));
Normal = mat3(transpose(inverse(model))) * normal;
TexCoords = texCoord;
}
Binary file added Resources/Cinematic.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Resources/LightFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#version 330 core
out vec4 color;

void main()
{
color = vec4(0.6f); // Set alle 4 vector values to 1.0f
}
11 changes: 11 additions & 0 deletions Resources/LightVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec3 position;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f);
}
Binary file added Resources/Specular.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 Resources/Textures!.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 Resources/ned_86879038.flt
Binary file not shown.
7 changes: 7 additions & 0 deletions Resources/ned_86879038.hdr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ncols 320
nrows 283
xllcorner -122.23111111089
yllcorner 46.157777777631
cellsize 0.00027777777779994
NODATA_value -9999
byteorder LSBFIRST
Binary file added Resources/ned_86879038.prj
Binary file not shown.

0 comments on commit 5c0878a

Please sign in to comment.