mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-23 07:40:14 +00:00
39 lines
904 B
GLSL
39 lines
904 B
GLSL
|
|
#version 330 core
|
||
|
|
|
||
|
|
in vec3 FragPos;
|
||
|
|
in vec3 Normal;
|
||
|
|
in vec2 TexCoord;
|
||
|
|
|
||
|
|
out vec4 FragColor;
|
||
|
|
|
||
|
|
uniform vec3 uLightPos;
|
||
|
|
uniform vec3 uViewPos;
|
||
|
|
uniform vec4 uColor;
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
uniform bool uUseTexture;
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
// Ambient
|
||
|
|
vec3 ambient = 0.3 * vec3(1.0);
|
||
|
|
|
||
|
|
// Diffuse
|
||
|
|
vec3 norm = normalize(Normal);
|
||
|
|
vec3 lightDir = normalize(uLightPos - FragPos);
|
||
|
|
float diff = max(dot(norm, lightDir), 0.0);
|
||
|
|
vec3 diffuse = diff * vec3(1.0);
|
||
|
|
|
||
|
|
// Specular
|
||
|
|
vec3 viewDir = normalize(uViewPos - FragPos);
|
||
|
|
vec3 reflectDir = reflect(-lightDir, norm);
|
||
|
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32.0);
|
||
|
|
vec3 specular = 0.5 * spec * vec3(1.0);
|
||
|
|
|
||
|
|
vec3 result = (ambient + diffuse + specular);
|
||
|
|
|
||
|
|
if (uUseTexture) {
|
||
|
|
FragColor = texture(uTexture, TexCoord) * vec4(result, 1.0);
|
||
|
|
} else {
|
||
|
|
FragColor = uColor * vec4(result, 1.0);
|
||
|
|
}
|
||
|
|
}
|