Advertisement
Caiwan

phong-multi.frag

Feb 25th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. varying vec4 diffuse, ambientGlobal, ambient;
  2. varying vec3 normal, lightDir, halfVector;
  3. varying float dist;
  4.  
  5. uniform sampler2D tex0;
  6.  
  7. vec4 calcPointLight(){
  8.     float d = length(lightDir);
  9.     float att = 1.0 / ( gl_LightSource[0].constantAttenuation + (gl_LightSource[0].linearAttenuation*d) + (gl_LightSource[0].quadraticAttenuation*d*d) );
  10.            
  11.     vec4 color  = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient)  +(gl_LightSource[0].ambient * gl_FrontMaterial.ambient * att);
  12.     vec3 N = normalize(normal);
  13.     vec3 L = normalize(lightDir);
  14.     float lambertTerm = dot(N,L);
  15.    
  16.     if(lambertTerm > 0.0)
  17.     {
  18.         color += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * lambertTerm * att;                 
  19.         vec3 E = normalize(halfVector);
  20.         vec3 R = reflect(-L, N);
  21.         float specular = pow( max(dot(R, E), 0.0), gl_FrontMaterial.shininess );
  22.         color += gl_LightSource[0].specular * gl_FrontMaterial.specular * specular * att;  
  23.     }
  24.    
  25.     return color;
  26. }
  27.  
  28. void main()
  29. {
  30.     vec4 phong = calcPointLight();
  31.  
  32.     gl_FragData[0] = phong * texture2D(tex0, gl_TexCoord[0].st);  // ha ki kellene kapcsolni a texturat, a motor lecsereli azt egy ures feher texturara.
  33.     gl_FragData[1] = vec4(normal,1.0); //ezt nem igy kellene
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement