scop/src/shader.fs

34 lines
917 B
GLSL

#version 330
uniform float time;
uniform sampler2D ourTexture;
uniform int has_texture;
out vec4 FragColor;
flat in int vID;
in vec2 texCoord;
in vec3 position;
in vec3 normal;
float rand(float n)
{
return fract(sin(n) * 43758.5453123);
}
void main()
{
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + int(time))), rand(float(vID + int(time))));
vec3 n = normalize(vec3(10. * cos(time), 10., 10. * sin(time)) - position);
float phong = 0.2 + 0.8 * max(0., dot(n, normalize(normal)));
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.);
}