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

31 lines
680 B
GLSL
Raw Normal View History

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