scop/src/shader.fs

34 lines
917 B
Forth
Raw Normal View History

#version 330
2020-12-24 13:41:45 +00:00
uniform float time;
uniform sampler2D ourTexture;
2024-04-25 08:20:20 +00:00
uniform int has_texture;
2020-12-24 13:41:45 +00:00
out vec4 FragColor;
flat in int vID;
2024-04-25 07:01:05 +00:00
in vec2 texCoord;
in vec3 position;
in vec3 normal;
2020-12-24 13:41:45 +00:00
2020-12-24 13:41:45 +00:00
float rand(float n)
{
return fract(sin(n) * 43758.5453123);
}
void main()
{
2020-12-26 05:41:27 +00:00
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + int(time))), rand(float(vID + int(time))));
2024-04-25 08:20:20 +00:00
vec3 n = normalize(vec3(10. * cos(time), 10., 10. * sin(time)) - position);
2024-04-25 07:01:05 +00:00
float phong = 0.2 + 0.8 * max(0., dot(n, normalize(normal)));
2024-04-25 08:20:20 +00:00
float specular = pow(max(dot(reflect(n, normalize(normal)), normalize(vec3(0, 0, -2) - position)), 0.), 10.);
if (has_texture == 1) {
FragColor = vec4(texture(ourTexture, texCoord).rgb * phong + vec3(1.) * specular, 1.);
//FragColor = vec4(texCoord.xyx / 2. * phong + vec3(1.) * specular, 1.);
}
else {
FragColor = vec4(color, 1.);
}
//FragColor = vec4(color * 0.001 + normal, 1.);
}