Now have a material and highlight map.
This commit is contained in:
parent
19a91bab18
commit
fb2c871419
8 changed files with 159 additions and 110 deletions
46
11-lightmaps/shaders/11-frag.glsl
Normal file
46
11-lightmaps/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
11-lightmaps/shaders/11-lightsource.frag.glsl
Normal file
16
11-lightmaps/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
11-lightmaps/shaders/11-vert.glsl
Normal file
20
11-lightmaps/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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue