2 uniform bool OSGLight0Active;
3 uniform bool OSGLight1Active;
4 uniform bool OSGLight2Active;
10 void pointLight(in int i,
23 VP = vec3(gl_LightSource[i].position) -
25 // Compute distance between surface and light position
28 // Normalize the vector from surface to light position
31 // Compute attenuation
32 attenuation = 1.0 / (gl_LightSource[i].constantAttenuation +
33 gl_LightSource[i].linearAttenuation * d +
34 gl_LightSource[i].quadraticAttenuation * d * d);
35 halfVector = normalize(VP + eye);
36 nDotVP = max(0.0, dot(normal, VP));
37 nDotHV = max(0.0, dot(normal, halfVector));
42 pf = pow(nDotHV, gl_FrontMaterial.shininess);
44 Ambient += gl_LightSource[i].ambient * attenuation;
45 Diffuse += gl_LightSource[i].diffuse * nDotVP * attenuation;
46 Specular += gl_LightSource[i].specular * pf * attenuation;
52 vec3 normal = gl_NormalMatrix * gl_Normal;
53 normal = normalize(normal);
57 void flight(in vec3 normal, in vec4 ecPosition, float alphaFade)
63 ecPosition3 = (vec3 (ecPosition)) / ecPosition.w;
64 eye = vec3 (0.0, 0.0, 1.0);
66 // Clear the light intensity accumulators
69 Specular = vec4 (0.0);
72 pointLight(0, normal, eye, ecPosition3);
75 pointLight(1, normal, eye, ecPosition3);
78 pointLight(2, normal, eye, ecPosition3);
80 color = gl_FrontLightModelProduct.sceneColor +
81 Ambient * gl_FrontMaterial.ambient +
82 Diffuse * gl_FrontMaterial.diffuse;
83 color += Specular * gl_FrontMaterial.specular;
84 color = clamp( color, 0.0, 1.0 );
85 gl_FrontColor = color;
86 gl_FrontColor.a *= alphaFade;
92 vec3 transformedNormal;
93 float alphaFade = 1.0;
95 // Eye-coordinate position of vertex, needed in various calculations
96 vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
98 // Do fixed functionality vertex transform
99 gl_Position = ftransform();
100 transformedNormal = fnormal();
101 flight(transformedNormal, ecPosition, alphaFade);