tavli

annotate sdr/phong.p.glsl @ 24:0aadb519b5ee

correct highlighting
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 08 Jul 2015 15:11:58 +0300
parents
children
rev   line source
nuclear@15 1 /* vi: set ft=glsl */
nuclear@15 2 uniform sampler2D tex;
nuclear@15 3
nuclear@15 4 varying vec3 vdir, ldir, normal;
nuclear@15 5
nuclear@15 6 #define KD gl_FrontMaterial.diffuse.rgb
nuclear@15 7 #define KS gl_FrontMaterial.specular.rgb
nuclear@15 8 #define SPOW gl_FrontMaterial.shininess
nuclear@15 9
nuclear@15 10 void main()
nuclear@15 11 {
nuclear@15 12 vec4 texel = texture2D(tex, gl_TexCoord[0].st);
nuclear@15 13
nuclear@15 14 vec3 n = normalize(normal);
nuclear@15 15 vec3 v = normalize(vdir);
nuclear@15 16 vec3 l = normalize(ldir);
nuclear@15 17 vec3 h = normalize(l + v);
nuclear@15 18
nuclear@15 19 float ndotl = max(dot(n, l), 0.0);
nuclear@15 20 float ndoth = max(dot(n, h), 0.0);
nuclear@15 21
nuclear@15 22 vec3 albedo = KD * texel.rgb;
nuclear@15 23 vec3 diffuse = albedo * gl_LightSource[0].diffuse.rgb * ndotl;
nuclear@15 24 vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW);
nuclear@15 25
nuclear@15 26 vec3 ambient = gl_LightModel.ambient.rgb * albedo;
nuclear@15 27 gl_FragColor.rgb = ambient + diffuse + specular;
nuclear@15 28 gl_FragColor.a = gl_FrontMaterial.diffuse.a * texel.a;
nuclear@15 29 }