Setup for day 18.
This commit is contained in:
parent
032f10ef44
commit
993f148710
87 changed files with 14992 additions and 0 deletions
43
18-depth-testing/shaders/08-frag.glsl
Normal file
43
18-depth-testing/shaders/08-frag.glsl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
uniform Light light;
|
||||
|
||||
uniform Material material;
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 ambient = light.ambient * material.ambient;
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(light.position - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light.diffuse * (diff * material.diffuse);
|
||||
|
||||
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 * (material.specular * spec);
|
||||
|
||||
vec3 result = ambient + diffuse + specular;
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
16
18-depth-testing/shaders/08-lightsource.frag.glsl
Normal file
16
18-depth-testing/shaders/08-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
uniform Light light;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(light.diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
17
18-depth-testing/shaders/08-vert.glsl
Normal file
17
18-depth-testing/shaders/08-vert.glsl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
}
|
||||
46
18-depth-testing/shaders/11-frag.glsl
Normal file
46
18-depth-testing/shaders/11-frag.glsl
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Light light;
|
||||
uniform Material material;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(light.position - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
|
||||
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 * spec_tex;
|
||||
|
||||
vec3 result = ambient + diffuse + specular;
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
16
18-depth-testing/shaders/11-lightsource.frag.glsl
Normal file
16
18-depth-testing/shaders/11-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
uniform Light light;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(light.diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/11-vert.glsl
Normal file
20
18-depth-testing/shaders/11-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
67
18-depth-testing/shaders/12-frag.glsl
Normal file
67
18-depth-testing/shaders/12-frag.glsl
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
struct Light {
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cutOff;
|
||||
float outerCutOff;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Light light;
|
||||
uniform Material material;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightDir = normalize(light.position - FragPos);
|
||||
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
|
||||
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 * spec_tex;
|
||||
|
||||
// splotlight
|
||||
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;
|
||||
|
||||
// determine attenuation based on light distance
|
||||
float distance = length(light.position - FragPos);
|
||||
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
vec3 result = ambient + diffuse + specular;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
16
18-depth-testing/shaders/12-lightsource.frag.glsl
Normal file
16
18-depth-testing/shaders/12-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
struct Light {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
uniform Light light;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(light.diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/12-vert.glsl
Normal file
20
18-depth-testing/shaders/12-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
150
18-depth-testing/shaders/13-frag.glsl
Normal file
150
18-depth-testing/shaders/13-frag.glsl
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Material material;
|
||||
|
||||
struct DirLight {
|
||||
vec3 direction;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight {
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cutOff;
|
||||
float outerCutOff;
|
||||
};
|
||||
|
||||
|
||||
#define NR_POINT_LIGHTS 4
|
||||
uniform int pointLightCount;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
uniform DirLight dirLight;
|
||||
uniform SpotLight spotLight;
|
||||
|
||||
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
|
||||
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);
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
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;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
vec3 result = CalcDirLight(dirLight, norm, viewDir);
|
||||
|
||||
for(int i = 0; i < pointLightCount; i++) {
|
||||
result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
9
18-depth-testing/shaders/13-lightsource.frag.glsl
Normal file
9
18-depth-testing/shaders/13-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/13-vert.glsl
Normal file
20
18-depth-testing/shaders/13-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
150
18-depth-testing/shaders/14-frag.glsl
Normal file
150
18-depth-testing/shaders/14-frag.glsl
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Material material;
|
||||
|
||||
struct DirLight {
|
||||
vec3 direction;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight {
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cutOff;
|
||||
float outerCutOff;
|
||||
};
|
||||
|
||||
|
||||
#define NR_POINT_LIGHTS 4
|
||||
uniform int pointLightCount;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
uniform DirLight dirLight;
|
||||
uniform SpotLight spotLight;
|
||||
|
||||
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
|
||||
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);
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
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;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
vec3 result = CalcDirLight(dirLight, norm, viewDir);
|
||||
|
||||
for(int i = 0; i < pointLightCount; i++) {
|
||||
result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
9
18-depth-testing/shaders/14-lightsource.frag.glsl
Normal file
9
18-depth-testing/shaders/14-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/14-vert.glsl
Normal file
20
18-depth-testing/shaders/14-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
162
18-depth-testing/shaders/16-frag.glsl
Normal file
162
18-depth-testing/shaders/16-frag.glsl
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Material material;
|
||||
|
||||
struct DirLight {
|
||||
vec3 direction;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight {
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cut_off;
|
||||
float outer_cut_off;
|
||||
};
|
||||
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
uniform int pointLightCount = 0;
|
||||
uniform PointLight pointLights[MAX_LIGHTS];
|
||||
|
||||
uniform int dirLightCount = 0;
|
||||
uniform DirLight dirLights[MAX_LIGHTS];
|
||||
|
||||
uniform int spotLightCount = 0;
|
||||
uniform SpotLight spotLights[MAX_LIGHTS];
|
||||
|
||||
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
|
||||
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);
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
float theta = dot(lightDir, normalize(-light.direction));
|
||||
float epsilon = light.cut_off - light.outer_cut_off;
|
||||
float intensity = clamp((theta - light.outer_cut_off) / epsilon, 0.0, 1.0);
|
||||
diffuse *= intensity;
|
||||
specular *= intensity;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
// kick it off with the first dirlight
|
||||
vec3 result = CalcDirLight(dirLights[0], norm, viewDir);
|
||||
|
||||
// then augment with more (off by one)
|
||||
for(int i = 1; i < dirLightCount; i++) {
|
||||
result += CalcDirLight(dirLights[i], norm, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < pointLightCount; i++) {
|
||||
result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < spotLightCount; i++) {
|
||||
result += CalcSpotLight(spotLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
9
18-depth-testing/shaders/16-lightsource.frag.glsl
Normal file
9
18-depth-testing/shaders/16-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/16-vert.glsl
Normal file
20
18-depth-testing/shaders/16-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
162
18-depth-testing/shaders/17-frag.glsl
Normal file
162
18-depth-testing/shaders/17-frag.glsl
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Material material;
|
||||
|
||||
struct DirLight {
|
||||
vec3 direction;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight {
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cut_off;
|
||||
float outer_cut_off;
|
||||
};
|
||||
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
uniform int pointLightCount = 0;
|
||||
uniform PointLight pointLights[MAX_LIGHTS];
|
||||
|
||||
uniform int dirLightCount = 0;
|
||||
uniform DirLight dirLights[MAX_LIGHTS];
|
||||
|
||||
uniform int spotLightCount = 0;
|
||||
uniform SpotLight spotLights[MAX_LIGHTS];
|
||||
|
||||
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
|
||||
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);
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
float theta = dot(lightDir, normalize(-light.direction));
|
||||
float epsilon = light.cut_off - light.outer_cut_off;
|
||||
float intensity = clamp((theta - light.outer_cut_off) / epsilon, 0.0, 1.0);
|
||||
diffuse *= intensity;
|
||||
specular *= intensity;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
// kick it off with the first dirlight
|
||||
vec3 result = CalcDirLight(dirLights[0], norm, viewDir);
|
||||
|
||||
// then augment with more (off by one)
|
||||
for(int i = 1; i < dirLightCount; i++) {
|
||||
result += CalcDirLight(dirLights[i], norm, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < pointLightCount; i++) {
|
||||
result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < spotLightCount; i++) {
|
||||
result += CalcSpotLight(spotLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
9
18-depth-testing/shaders/17-lightsource.frag.glsl
Normal file
9
18-depth-testing/shaders/17-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/17-vert.glsl
Normal file
20
18-depth-testing/shaders/17-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
162
18-depth-testing/shaders/18-frag.glsl
Normal file
162
18-depth-testing/shaders/18-frag.glsl
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
sampler2D diffuse;
|
||||
sampler2D specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 FragPos;
|
||||
in vec3 Normal;
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform Material material;
|
||||
|
||||
struct DirLight {
|
||||
vec3 direction;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
};
|
||||
|
||||
struct PointLight {
|
||||
vec3 position;
|
||||
vec3 ambient;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight {
|
||||
vec3 direction;
|
||||
vec3 position;
|
||||
vec3 diffuse;
|
||||
vec3 specular;
|
||||
vec3 ambient;
|
||||
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
float cut_off;
|
||||
float outer_cut_off;
|
||||
};
|
||||
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
uniform int pointLightCount = 0;
|
||||
uniform PointLight pointLights[MAX_LIGHTS];
|
||||
|
||||
uniform int dirLightCount = 0;
|
||||
uniform DirLight dirLights[MAX_LIGHTS];
|
||||
|
||||
uniform int spotLightCount = 0;
|
||||
uniform SpotLight spotLights[MAX_LIGHTS];
|
||||
|
||||
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
|
||||
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);
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
||||
{
|
||||
vec3 mat_tex = vec3(texture(material.diffuse, TexCoords));
|
||||
vec3 spec_tex = vec3(texture(material.specular, TexCoords));
|
||||
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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec3 ambient = light.ambient * mat_tex;
|
||||
vec3 diffuse = light.diffuse * diff * mat_tex;
|
||||
vec3 specular = light.specular * spec * spec_tex;
|
||||
|
||||
float theta = dot(lightDir, normalize(-light.direction));
|
||||
float epsilon = light.cut_off - light.outer_cut_off;
|
||||
float intensity = clamp((theta - light.outer_cut_off) / epsilon, 0.0, 1.0);
|
||||
diffuse *= intensity;
|
||||
specular *= intensity;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
// kick it off with the first dirlight
|
||||
vec3 result = CalcDirLight(dirLights[0], norm, viewDir);
|
||||
|
||||
// then augment with more (off by one)
|
||||
for(int i = 1; i < dirLightCount; i++) {
|
||||
result += CalcDirLight(dirLights[i], norm, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < pointLightCount; i++) {
|
||||
result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < spotLightCount; i++) {
|
||||
result += CalcSpotLight(spotLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
||||
9
18-depth-testing/shaders/18-lightsource.frag.glsl
Normal file
9
18-depth-testing/shaders/18-lightsource.frag.glsl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 diffuse;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(diffuse, 1.0); // set all 4 vector values to 1.0
|
||||
}
|
||||
20
18-depth-testing/shaders/18-vert.glsl
Normal file
20
18-depth-testing/shaders/18-vert.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec2 TexCoords;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
FragPos = vec3(model * vec4(aPos, 1.0));
|
||||
Normal = mat3(transpose(inverse(model))) * aNormal;
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
8
18-depth-testing/shaders/3.3.shader.fs
Normal file
8
18-depth-testing/shaders/3.3.shader.fs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
in vec3 ourColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(ourColor, 1.0);
|
||||
}
|
||||
11
18-depth-testing/shaders/3.3.shader.vs
Normal file
11
18-depth-testing/shaders/3.3.shader.vs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos; // the position variable has attribute position 0
|
||||
layout (location = 1) in vec3 aColor;
|
||||
|
||||
out vec3 ourColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0); // see how we directly give a vec3 to vec4's constructor
|
||||
ourColor = aColor;
|
||||
}
|
||||
11
18-depth-testing/shaders/4.2.texture.fs
Normal file
11
18-depth-testing/shaders/4.2.texture.fs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec2 TexCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, TexCoord);
|
||||
}
|
||||
15
18-depth-testing/shaders/4.2.texture.vs
Normal file
15
18-depth-testing/shaders/4.2.texture.vs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoord;
|
||||
|
||||
out vec2 TexCoord;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0f);
|
||||
TexCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue