-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a71b7cf
commit 8faf52d
Showing
6 changed files
with
1,782 additions
and
0 deletions.
There are no files selected for viewing
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,21 @@ | ||
#version 330 core | ||
|
||
layout (location = 0) in vec3 position; | ||
layout (location = 1) in vec3 normal; | ||
layout (location = 2) in vec2 texCoords; | ||
|
||
uniform mat4 model; | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
out vec3 FragPos; | ||
out vec3 Normal; | ||
out vec2 TexCoords; | ||
|
||
void main() | ||
{ | ||
gl_Position = projection * view * model * vec4(position, 1.0f); | ||
FragPos = vec3(model * vec4(position, 1.0f)); | ||
Normal = mat3(transpose(inverse(model))) * normal; | ||
TexCoords = texCoords; | ||
} |
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,61 @@ | ||
#version 330 core | ||
|
||
struct Material | ||
{ | ||
sampler2D diffuse; | ||
sampler2D specular; | ||
float shininess; | ||
}; | ||
|
||
struct Light | ||
{ | ||
vec3 position; | ||
//vec3 direction; | ||
|
||
vec3 ambient; | ||
vec3 diffuse; | ||
vec3 specular; | ||
|
||
float constant; | ||
float linear; | ||
float quadratic; | ||
}; | ||
|
||
in vec2 TexCoords; | ||
in vec3 FragPos; | ||
in vec3 Normal; | ||
|
||
out vec4 color; | ||
|
||
uniform vec3 viewPos; | ||
uniform Material material; | ||
uniform Light light; | ||
|
||
void main() | ||
{ | ||
// Ambient | ||
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords)); | ||
|
||
// Diffuse | ||
vec3 norm = normalize(Normal); | ||
vec3 lightDir = normalize(light.position - FragPos); | ||
float diff = max(dot(norm, lightDir), 0.0); | ||
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords)); | ||
|
||
// Specular | ||
vec3 viewDir = normalize(viewPos - FragPos); | ||
vec3 reflectDir = reflect(-lightDir, norm); | ||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); | ||
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords)); | ||
|
||
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; | ||
|
||
vec3 result = ambient + diffuse + specular; | ||
color = vec4(result, 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,49 @@ | ||
#version 330 core | ||
|
||
struct Material | ||
{ | ||
sampler2D diffuse; | ||
sampler2D specular; | ||
float shininess; | ||
}; | ||
|
||
struct Light | ||
{ | ||
//vec3 position; | ||
vec3 direction; | ||
|
||
vec3 ambient; | ||
vec3 diffuse; | ||
vec3 specular; | ||
}; | ||
|
||
in vec2 TexCoords; | ||
in vec3 FragPos; | ||
in vec3 Normal; | ||
|
||
out vec4 color; | ||
|
||
uniform vec3 viewPos; | ||
uniform Material material; | ||
uniform Light light; | ||
|
||
void main() | ||
{ | ||
// Ambient | ||
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords)); | ||
|
||
// Diffuse | ||
vec3 norm = normalize(Normal); | ||
vec3 lightDir = normalize(-light.direction); | ||
float diff = max(dot(norm, lightDir), 0.0); | ||
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords)); | ||
|
||
// Specular | ||
vec3 viewDir = normalize(viewPos - FragPos); | ||
vec3 reflectDir = reflect(-lightDir, norm); | ||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); | ||
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords)); | ||
|
||
vec3 result = ambient + diffuse + specular; | ||
color = vec4(result, 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,68 @@ | ||
#version 330 core | ||
|
||
struct Material | ||
{ | ||
sampler2D diffuse; | ||
sampler2D specular; | ||
float shininess; | ||
}; | ||
|
||
struct Light | ||
{ | ||
vec3 position; | ||
vec3 direction; | ||
float cutOff; | ||
|
||
vec3 ambient; | ||
vec3 diffuse; | ||
vec3 specular; | ||
|
||
float constant; | ||
float linear; | ||
float quadratic; | ||
}; | ||
|
||
in vec2 TexCoords; | ||
in vec3 FragPos; | ||
in vec3 Normal; | ||
|
||
out vec4 color; | ||
|
||
uniform vec3 viewPos; | ||
uniform Material material; | ||
uniform Light light; | ||
|
||
void main() | ||
{ | ||
vec3 lightDir = normalize(light.position - FragPos); | ||
float cosTheta = dot(lightDir, normalize(-light.direction)); | ||
if (cosTheta > light.cutOff) { | ||
// Ambient | ||
vec3 ambient = light.ambient * vec3(texture(material.diffuse, TexCoords)); | ||
|
||
// Diffuse | ||
vec3 norm = normalize(Normal); | ||
float diff = max(dot(norm, lightDir), 0.0); | ||
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuse, TexCoords)); | ||
|
||
// Specular | ||
vec3 viewDir = normalize(viewPos - FragPos); | ||
vec3 reflectDir = reflect(-lightDir, norm); | ||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess); | ||
vec3 specular = light.specular * spec * vec3(texture(material.specular, TexCoords)); | ||
|
||
// 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; | ||
|
||
color = vec4(ambient + diffuse + specular, 1.0f); | ||
} | ||
else { | ||
color = vec4(light.ambient * vec3(texture(material.diffuse, TexCoords)), 1.0f); | ||
} | ||
} |
Oops, something went wrong.