File: PointLight.glsl

package info (click to toggle)
coin2 2.5.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 29,156 kB
  • ctags: 29,453
  • sloc: cpp: 175,383; ansic: 42,198; sh: 9,377; makefile: 7,260; perl: 990; yacc: 181; lex: 114
file content (41 lines) | stat: -rwxr-xr-x 1,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

void PointLight(in int i,
                in vec3 eye,
                in vec3 ecPosition3,
                in vec3 normal,
                inout vec4 ambient,
                inout vec4 diffuse,
                inout vec4 specular)
{
  float nDotVP;
  float nDotHV;
  float pf;  
  float att;
  float d;          
  vec3 VP;
  vec3 halfvec;

  VP = vec3(gl_LightSource[i].position) - ecPosition3;
  d = length(VP);
  
  VP = normalize(VP);
  
  att = 1.0 / (gl_LightSource[i].constantAttenuation +
               gl_LightSource[i].linearAttenuation * d +
               gl_LightSource[i].quadraticAttenuation * d * d);
  
  halfvec = normalize(VP + eye);
  nDotVP = max(0.0, dot(normal, VP));
  nDotHV = max(0.0, dot(normal, halfvec));
  
  float shininess = gl_FrontMaterial.shininess;

  if (nDotVP == 0.0)
    pf = 0.0;
  else 
    pf = pow(nDotHV, shininess);
  
  ambient += gl_LightSource[i].ambient * att;
  diffuse += gl_LightSource[i].diffuse * nDotVP * att;
  specular += gl_LightSource[i].specular * pf * att;
}