Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Simplified GLSL material
Browse files Browse the repository at this point in the history
  • Loading branch information
tenko committed Oct 26, 2012
1 parent 5641cb9 commit fcfc49e
Showing 1 changed file with 7 additions and 30 deletions.
37 changes: 7 additions & 30 deletions occmodel/occmodelviewer.py
Expand Up @@ -62,26 +62,6 @@ class SolidObj(object):
varying vec3 normal;
varying vec3 vertex;
const vec4 AMBIENT_BLACK = vec4(0.0, 0.0, 0.0, 1.0);
const vec4 DEFAULT_BLACK = vec4(0.0, 0.0, 0.0, 0.0);
bool isLightEnabled(in int i)
{
// A separate variable is used to get
// rid of a linker error.
bool enabled = true;
// If all the colors of the Light are set
// to BLACK then we know we don't need to bother
// doing a lighting calculation on it.
if ((gl_LightSource[i].ambient == AMBIENT_BLACK) &&
(gl_LightSource[i].diffuse == DEFAULT_BLACK) &&
(gl_LightSource[i].specular == DEFAULT_BLACK))
enabled = false;
return(enabled);
}
float calculateAttenuation(in int i, in float dist)
{
return(1.0 / (gl_LightSource[i].constantAttenuation +
Expand Down Expand Up @@ -169,19 +149,16 @@ class SolidObj(object):
void calculateLighting(in vec3 N, in vec3 V, in float shininess,
inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
// Just loop through each light, and if its enabled add
// Just loop through each light, and add
// its contributions to the color of the pixel.
for (int i = 0; i < MAX_LIGHTS - 1; i++)
{
if (isLightEnabled(i))
{
if (gl_LightSource[i].position.w == 0.0)
directionalLight(i, N, shininess, ambient, diffuse, specular);
else if (gl_LightSource[i].spotCutoff == 180.0)
pointLight(i, N, V, shininess, ambient, diffuse, specular);
else
spotLight(i, N, V, shininess, ambient, diffuse, specular);
}
if (gl_LightSource[i].position.w == 0.0)
directionalLight(i, N, shininess, ambient, diffuse, specular);
else if (gl_LightSource[i].spotCutoff == 180.0)
pointLight(i, N, V, shininess, ambient, diffuse, specular);
else
spotLight(i, N, V, shininess, ambient, diffuse, specular);
}
}
Expand Down

0 comments on commit fcfc49e

Please sign in to comment.