tavli
view sdr/phong.p.glsl @ 15:b1a195c3ee16
added shaders
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 28 Jun 2015 08:34:24 +0300 |
parents | |
children |
line source
1 /* vi: set ft=glsl */
2 uniform sampler2D tex;
4 varying vec3 vdir, ldir, normal;
6 #define KD gl_FrontMaterial.diffuse.rgb
7 #define KS gl_FrontMaterial.specular.rgb
8 #define SPOW gl_FrontMaterial.shininess
10 void main()
11 {
12 vec4 texel = texture2D(tex, gl_TexCoord[0].st);
14 vec3 n = normalize(normal);
15 vec3 v = normalize(vdir);
16 vec3 l = normalize(ldir);
17 vec3 h = normalize(l + v);
19 float ndotl = max(dot(n, l), 0.0);
20 float ndoth = max(dot(n, h), 0.0);
22 vec3 albedo = KD * texel.rgb;
23 vec3 diffuse = albedo * gl_LightSource[0].diffuse.rgb * ndotl;
24 vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW);
26 vec3 ambient = gl_LightModel.ambient.rgb * albedo;
27 gl_FragColor.rgb = ambient + diffuse + specular;
28 gl_FragColor.a = gl_FrontMaterial.diffuse.a * texel.a;
29 }