KlassischeKeplerKriege/data/shader/gameobjects.frag

49 lines
1.4 KiB
GLSL
Raw Normal View History

#version 120
2016-09-29 02:24:14 +00:00
varying vec3 vertex;
varying vec3 normal;
varying vec3 lightDirection;
2016-09-29 02:24:14 +00:00
uniform vec3 lightColor;
uniform vec3 lightPosition;
uniform float materialKind;
uniform vec3 materialColor;
2016-09-29 02:24:14 +00:00
void main()
{
2016-09-29 09:38:26 +00:00
vec3 Eye = normalize(-vertex);
vec3 Reflected = normalize(reflect( -lightPosition, normal));
2016-09-29 02:24:14 +00:00
vec3 IAmbient = vec3(0.05f);
if (materialKind == 6) {
// sun: shines by itself
gl_FragColor = vec4(materialColor, 1.0);
return;
}
2016-09-29 02:24:14 +00:00
2016-09-29 09:38:26 +00:00
// TODO: add noise texture
vec3 IDiffuse = vec3(materialColor) * lightColor * max(dot(normal, lightDirection), 0.0);
// TODO make instensity/exponent as parameter
//vec3 ISpecular = lightColor * 5.0 * pow(max(dot(Reflected, Eye), 0.0), 2.0);
vec3 ISpecular = lightColor * pow(max(dot(Reflected, Eye), 0.0), 2.0);
if (dot(lightDirection, normal) <= 0.0) {
ISpecular = vec3(0.0, 0.0, 0.0);
}
// p: point of the fragment on the surface
//vec3 v_eye = normalize(pos_eye - pos_space); // point from p to eye
//vec3 v_sun = normalize(sun_light_dir); // points from p to the sun
//float specular = spec_int * pow(
// clamp(dot((v_eye + v_sun)/2.0, normal), 0.0, 1.0),
// 2.0*specular_exponent);
2016-09-29 02:24:14 +00:00
2016-09-29 09:38:26 +00:00
//ISpecular = vec3(1.0, 0.0, 0.0) * specular;
2016-09-29 06:28:56 +00:00
2016-09-29 09:38:26 +00:00
//gl_FragColor = vec4(ISpecular, 1.0);
gl_FragColor = vec4((IAmbient + IDiffuse) + ISpecular, 1.0);
2016-09-29 06:28:56 +00:00
//gl_FragColor = vec4(0.5+0.5*normal, 1.0);
2016-09-29 10:28:35 +00:00
}