41 lines
1.1 KiB
GLSL
41 lines
1.1 KiB
GLSL
#version 460 core
|
|
|
|
in vec2 pass_textureCoords;
|
|
in vec3 surfaceNormal;
|
|
in vec3 worldPos;
|
|
|
|
uniform sampler2D diffuseSampler;
|
|
uniform float opacity;
|
|
uniform float shininess;
|
|
|
|
uniform vec3 lightPosition;
|
|
uniform vec3 lightColor;
|
|
uniform vec3 cameraPosition;
|
|
|
|
uniform vec3 highlightColor;
|
|
uniform float highlightIntensity;
|
|
|
|
out vec4 fragColor;
|
|
|
|
|
|
void main() {
|
|
vec3 normal = normalize(surfaceNormal);
|
|
vec3 lightDir = normalize(lightPosition - worldPos);
|
|
vec3 camDir = normalize(cameraPosition - worldPos);
|
|
vec3 reflectDir = reflect(-lightDir, normal);
|
|
|
|
vec3 ambient = 0.1 * lightColor;
|
|
|
|
float diff = max(dot(normal, lightDir) , 0.0f);
|
|
vec3 diffuse = diff * lightColor;
|
|
|
|
float spec = pow(max(dot(camDir, reflectDir), 0.0), max(shininess, 1.0f));
|
|
vec3 specular = 0.5 * spec * lightColor;
|
|
|
|
vec4 texColor = texture(diffuseSampler, pass_textureCoords);
|
|
fragColor = vec4((ambient + diffuse + specular) * texColor.rgb, texColor.a * opacity);
|
|
|
|
float intensity = clamp(highlightIntensity, 0.0, 1.0);
|
|
|
|
fragColor.rgb += highlightColor * intensity;
|
|
} |