Implemented basic lighting!
This commit is contained in:
parent
0a001d71bc
commit
5b51a3d571
20 changed files with 8628 additions and 72 deletions
|
|
@ -2,6 +2,37 @@
|
|||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(location = 2) in vec3 Normal;
|
||||
layout(location = 3) in vec3 FragPos;
|
||||
layout(location = 4) in vec2 TexCoords;
|
||||
|
||||
layout (binding = 2) uniform LightUniform {
|
||||
vec3 pos;
|
||||
} lightPos;
|
||||
|
||||
layout (binding = 3) uniform ViewUniform {
|
||||
vec3 pos;
|
||||
} viewPos;
|
||||
|
||||
layout (set = 1, binding = 0) uniform sampler2D textureSampler;
|
||||
layout (set = 1, binding = 1) uniform sampler2D diffuseSampler;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
vec3 lightDiffuse = vec3(0.5, 0.5, 0.5);
|
||||
vec3 lightAmbient = vec3(0.2, 0.2, 0.2);
|
||||
vec3 lightSpecular = vec3(1.0, 1.0, 1.0);
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(lightPos.pos - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = lightDiffuse * diff * vec3(texture(textureSampler, TexCoords));
|
||||
vec3 ambient = lightAmbient * vec3(texture(textureSampler, TexCoords));
|
||||
|
||||
vec3 viewDir = normalize(viewPos.pos - FragPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 2);
|
||||
vec3 specular = lightSpecular * spec * vec3(texture(diffuseSampler, TexCoords));
|
||||
|
||||
vec3 result = (ambient + diffuse + specular);
|
||||
outColor = vec4(result, 1.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 vertPos;
|
||||
layout(location = 1) in vec3 normal;
|
||||
layout(location = 2) in vec2 uv;
|
||||
|
||||
layout (binding = 0) uniform ProjUniform {
|
||||
mat4 proj;
|
||||
|
|
@ -10,8 +12,15 @@ layout (binding = 1) uniform ViewUniform {
|
|||
mat4 view;
|
||||
} view;
|
||||
|
||||
layout(location = 2) out vec3 Normal;
|
||||
layout(location = 3) out vec3 FragPos;
|
||||
layout(location = 4) out vec2 TexCoords;
|
||||
|
||||
void main() {
|
||||
vec4 out_vec = proj.proj * view.view * vec4(vertPos, 1.0);
|
||||
//vec4 out_vec = proj.proj * vec4(vertPos, 1.0);
|
||||
FragPos = vec3(vec4(vertPos, 1.0));
|
||||
Normal = normal;
|
||||
TexCoords = uv;
|
||||
gl_Position = vec4(out_vec.x, out_vec.y, out_vec.z, out_vec.w);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue