Moving on to cubemaps.
This commit is contained in:
parent
9c75238461
commit
87c513b9f0
113 changed files with 15511 additions and 0 deletions
43
24-cubemaps/shaders/08-frag.glsl
Normal file
43
24-cubemaps/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
24-cubemaps/shaders/08-lightsource.frag.glsl
Normal file
16
24-cubemaps/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
24-cubemaps/shaders/08-vert.glsl
Normal file
17
24-cubemaps/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
24-cubemaps/shaders/11-frag.glsl
Normal file
46
24-cubemaps/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
24-cubemaps/shaders/11-lightsource.frag.glsl
Normal file
16
24-cubemaps/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
24-cubemaps/shaders/11-vert.glsl
Normal file
20
24-cubemaps/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
24-cubemaps/shaders/12-frag.glsl
Normal file
67
24-cubemaps/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
24-cubemaps/shaders/12-lightsource.frag.glsl
Normal file
16
24-cubemaps/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
24-cubemaps/shaders/12-vert.glsl
Normal file
20
24-cubemaps/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
24-cubemaps/shaders/13-frag.glsl
Normal file
150
24-cubemaps/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
24-cubemaps/shaders/13-lightsource.frag.glsl
Normal file
9
24-cubemaps/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
24-cubemaps/shaders/13-vert.glsl
Normal file
20
24-cubemaps/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
24-cubemaps/shaders/14-frag.glsl
Normal file
150
24-cubemaps/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
24-cubemaps/shaders/14-lightsource.frag.glsl
Normal file
9
24-cubemaps/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
24-cubemaps/shaders/14-vert.glsl
Normal file
20
24-cubemaps/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
24-cubemaps/shaders/16-frag.glsl
Normal file
162
24-cubemaps/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
24-cubemaps/shaders/16-lightsource.frag.glsl
Normal file
9
24-cubemaps/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
24-cubemaps/shaders/16-vert.glsl
Normal file
20
24-cubemaps/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
24-cubemaps/shaders/17-frag.glsl
Normal file
162
24-cubemaps/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
24-cubemaps/shaders/17-lightsource.frag.glsl
Normal file
9
24-cubemaps/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
24-cubemaps/shaders/17-vert.glsl
Normal file
20
24-cubemaps/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;
|
||||
}
|
||||
176
24-cubemaps/shaders/18-frag.glsl
Normal file
176
24-cubemaps/shaders/18-frag.glsl
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
#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];
|
||||
|
||||
|
||||
float near = 0.1;
|
||||
float far = 100.0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
float LinearizeDepth(float depth)
|
||||
{
|
||||
float ndc = depth * 2.0 - 1.0;
|
||||
return (2.0 * near * far) / (far + near - ndc * (far - near));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
// float depth = LinearizeDepth(gl_FragCoord.z) / far;
|
||||
// FragColor = vec4(vec3(depth), 1.0);
|
||||
}
|
||||
9
24-cubemaps/shaders/18-lightsource.frag.glsl
Normal file
9
24-cubemaps/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
|
||||
}
|
||||
6
24-cubemaps/shaders/18-outline.glsl
Normal file
6
24-cubemaps/shaders/18-outline.glsl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
void main() {
|
||||
FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
20
24-cubemaps/shaders/18-vert.glsl
Normal file
20
24-cubemaps/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;
|
||||
}
|
||||
168
24-cubemaps/shaders/19-frag.glsl
Normal file
168
24-cubemaps/shaders/19-frag.glsl
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
#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];
|
||||
|
||||
|
||||
float near = 0.1;
|
||||
float far = 100.0;
|
||||
|
||||
vec4 CalcDirLight(vec4 mat_tex, vec4 spec_tex, 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);
|
||||
|
||||
vec4 ambient = vec4(light.ambient, 1.0) * mat_tex;
|
||||
vec4 diffuse = vec4(light.diffuse, 1.0) * diff * mat_tex;
|
||||
vec4 specular = vec4(light.specular, 1.0) * spec * spec_tex;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec4 CalcPointLight(vec4 mat_tex, vec4 spec_tex, 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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec4 ambient = vec4(light.ambient, 1.0) * mat_tex;
|
||||
vec4 diffuse = vec4(light.diffuse, 1.0) * diff * mat_tex;
|
||||
vec4 specular = vec4(light.specular, 1.0) * spec * spec_tex;
|
||||
|
||||
ambient *= attenuation;
|
||||
diffuse *= attenuation;
|
||||
specular *= attenuation;
|
||||
|
||||
return ambient + diffuse + specular;
|
||||
}
|
||||
|
||||
vec4 CalcSpotLight(vec4 mat_tex, vec4 spec_tex, SpotLight 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.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||
|
||||
vec4 ambient = vec4(light.ambient, 1.0) * mat_tex;
|
||||
vec4 diffuse = vec4(light.diffuse, 1.0) * diff * mat_tex;
|
||||
vec4 specular = vec4(light.specular, 1.0) * 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;
|
||||
}
|
||||
|
||||
float LinearizeDepth(float depth)
|
||||
{
|
||||
float ndc = depth * 2.0 - 1.0;
|
||||
return (2.0 * near * far) / (far + near - ndc * (far - near));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 mat_tex = texture(material.diffuse, TexCoords);
|
||||
vec4 spec_tex = texture(material.specular, TexCoords);
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 viewDir = normalize(viewPos - FragPos);
|
||||
|
||||
// kick it off with the first dirlight
|
||||
vec4 result = CalcDirLight(mat_tex, spec_tex, dirLights[0], norm, viewDir);
|
||||
|
||||
// then augment with more (off by one)
|
||||
for(int i = 1; i < dirLightCount; i++) {
|
||||
result += CalcDirLight(mat_tex, spec_tex, dirLights[i], norm, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < pointLightCount; i++) {
|
||||
result += CalcPointLight(mat_tex, spec_tex, pointLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
for(int i = 0; i < spotLightCount; i++) {
|
||||
result += CalcSpotLight(mat_tex, spec_tex, spotLights[i], norm, FragPos, viewDir);
|
||||
}
|
||||
|
||||
FragColor = result;
|
||||
}
|
||||
9
24-cubemaps/shaders/19-lightsource.frag.glsl
Normal file
9
24-cubemaps/shaders/19-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
24-cubemaps/shaders/19-vert.glsl
Normal file
20
24-cubemaps/shaders/19-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;
|
||||
}
|
||||
11
24-cubemaps/shaders/21-framebuffers.frag.glsl
Normal file
11
24-cubemaps/shaders/21-framebuffers.frag.glsl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, TexCoords);
|
||||
}
|
||||
20
24-cubemaps/shaders/21-framebuffers.vert.glsl
Normal file
20
24-cubemaps/shaders/21-framebuffers.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;
|
||||
}
|
||||
38
24-cubemaps/shaders/21-screen-kernel.frag.glsl
Normal file
38
24-cubemaps/shaders/21-screen-kernel.frag.glsl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D screenTexture;
|
||||
|
||||
const float offset = 1.0 / 300.0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 offsets[9] = vec2[](
|
||||
vec2(-offset, offset), // top-left
|
||||
vec2( 0.0f, offset), // top-center
|
||||
vec2( offset, offset), // top-right
|
||||
vec2(-offset, 0.0f), // center-left
|
||||
vec2( 0.0f, 0.0f), // center-center
|
||||
vec2( offset, 0.0f), // center-right
|
||||
vec2(-offset, -offset), // bottom-left
|
||||
vec2( 0.0f, -offset), // bottom-center
|
||||
vec2( offset, -offset) // bottom-right
|
||||
);
|
||||
|
||||
float kernel[9] = float[](
|
||||
1.0 / 16, 2.0 / 16, 1.0 / 16,
|
||||
2.0 / 16, 4.0 / 16, 2.0 / 16,
|
||||
1.0 / 16, 2.0 / 16, 1.0 / 16
|
||||
);
|
||||
|
||||
vec3 col = vec3(0.0);
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
vec3 sampleTex = vec3(texture(screenTexture, TexCoords.st + offsets[i]));
|
||||
col += sampleTex * kernel[i];
|
||||
}
|
||||
|
||||
FragColor = vec4(col, 1.0);
|
||||
}
|
||||
11
24-cubemaps/shaders/21-screen.frag.glsl
Normal file
11
24-cubemaps/shaders/21-screen.frag.glsl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D screenTexture;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(screenTexture, TexCoords);
|
||||
}
|
||||
11
24-cubemaps/shaders/21-screen.vert.glsl
Normal file
11
24-cubemaps/shaders/21-screen.vert.glsl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec2 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
out vec2 TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
|
||||
TexCoords = aTexCoords;
|
||||
}
|
||||
8
24-cubemaps/shaders/3.3.shader.fs
Normal file
8
24-cubemaps/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
24-cubemaps/shaders/3.3.shader.vs
Normal file
11
24-cubemaps/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
24-cubemaps/shaders/4.2.texture.fs
Normal file
11
24-cubemaps/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
24-cubemaps/shaders/4.2.texture.vs
Normal file
15
24-cubemaps/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