OpenGL-utility/examples/movement/shaders/fragmentShader.frag

31 lines
674 B
GLSL
Raw Normal View History

2021-01-24 03:31:28 +01:00
#version 330 core
in vec2 oUV;
2021-01-26 15:34:35 +01:00
in vec3 oNormal;
in vec3 oFragPos;
2021-01-24 03:31:28 +01:00
out vec4 FragColor;
uniform sampler2D texture1;
uniform sampler2D texture2;
2021-01-25 20:53:28 +01:00
uniform float ambientStrength;
uniform vec3 ambientColor;
2021-01-26 15:34:35 +01:00
uniform vec3 lightPos;
uniform vec3 lightColor;
2021-01-24 03:31:28 +01:00
void main()
{
2021-01-25 20:53:28 +01:00
vec3 ambient = ambientColor * ambientStrength;
2021-01-26 15:34:35 +01:00
vec3 norm = normalize(oNormal);
vec3 lightDir = normalize(lightPos - oFragPos);
2021-01-26 16:19:58 +01:00
float diff = max(dot(norm, lightDir), 0.0) * 10.0;
diff *= min(1.0 / length(lightPos - oFragPos), 10.0);
2021-01-26 15:34:35 +01:00
vec3 diffuse = diff * lightColor;
vec4 objColor = mix(texture(texture1, oUV), texture(texture2, oUV), 0.2);
2021-01-25 20:53:28 +01:00
2021-01-26 15:34:35 +01:00
FragColor = vec4(ambient + diffuse, 1.0) * objColor;
2021-01-24 03:31:28 +01:00
}