-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved resource files into their own dir
- Loading branch information
Charles
authored and
Charles
committed
Jan 11, 2017
1 parent
a58f2f1
commit 5c0878a
Showing
11 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.