tavli

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sdr/phong.p.glsl	Sun Jun 28 08:34:24 2015 +0300
     1.3 @@ -0,0 +1,29 @@
     1.4 +/* vi: set ft=glsl */
     1.5 +uniform sampler2D tex;
     1.6 +
     1.7 +varying vec3 vdir, ldir, normal;
     1.8 +
     1.9 +#define KD gl_FrontMaterial.diffuse.rgb
    1.10 +#define KS gl_FrontMaterial.specular.rgb
    1.11 +#define SPOW gl_FrontMaterial.shininess
    1.12 +
    1.13 +void main()
    1.14 +{
    1.15 +	vec4 texel = texture2D(tex, gl_TexCoord[0].st);
    1.16 +
    1.17 +	vec3 n = normalize(normal);
    1.18 +	vec3 v = normalize(vdir);
    1.19 +	vec3 l = normalize(ldir);
    1.20 +	vec3 h = normalize(l + v);
    1.21 +
    1.22 +	float ndotl = max(dot(n, l), 0.0);
    1.23 +	float ndoth = max(dot(n, h), 0.0);
    1.24 +
    1.25 +	vec3 albedo = KD * texel.rgb;
    1.26 +	vec3 diffuse = albedo * gl_LightSource[0].diffuse.rgb * ndotl;
    1.27 +	vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW);
    1.28 +
    1.29 +	vec3 ambient = gl_LightModel.ambient.rgb * albedo;
    1.30 +	gl_FragColor.rgb = ambient + diffuse + specular;
    1.31 +	gl_FragColor.a = gl_FrontMaterial.diffuse.a * texel.a;
    1.32 +}