directionalLight()
Lights Camera / LightsDescription
Adds a directional light. Comes uniformly from one direction, like sunlight.
Syntax
void directionalLight(float r, float g, float b, float nx, float ny, float nz)
Parameters
| Name | Type | Description |
|---|---|---|
| r | float | red component |
| g | float | green component |
| b | float | blue component |
| nx | float | x direction |
| ny | float | y direction |
| nz | float | z direction |
Returns
voidRelated
Under the Hood
From Processing.h:
void directionalLight(float r, float g, float b, float nx, float ny, float nz);
inline void PGraphics::directionalLight(float r, float g, float b, float nx, float ny, float nz) { if(PApplet::g_papplet) PApplet::g_papplet->directionalLight(r,g,b,nx,ny,nz); }
Under the Hood
From Processing.cpp:
void PApplet::directionalLight(float r, float g, float b, float nx, float ny, float nz) {
if (lightIndex >= 8) return;
GLenum lt = GL_LIGHT0 + lightIndex++;
GLfloat col[] = { lc(r), lc(g), lc(b), 1.0f };
// Negate direction and flip Y to compensate for glScalef(1,-1,1) in modelview
GLfloat pos[] = { -nx, ny, -nz, 0.0f };
GLfloat zero[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glDisable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
// No global ambient for directionalLight alone (matches Java Processing)
GLfloat gAmb[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gAmb);
lightsEnabled = true;
GLfloat spec[] = { pendingSpecR, pendingSpecG, pendingSpecB, 1.0f };
glEnable(lt);
glLightfv(lt, GL_AMBIENT, zero);
glLightfv(lt, GL_DIFFUSE, col);
glLightfv(lt, GL_SPECULAR, spec);
// Set in pure eye space (no world transforms) like Java Processing.
// toward-light in eye space: negate direction, flip Y for our Y-down convention.
glPushMatrix();
glLoadIdentity();
// toward-light = negate direction. Y negated because Processing Y-down maps to eye Y-up
// (glScalef(1,-1,1) in projection flips screen Y, so world +Y = eye -Y)
GLfloat posE[] = { -nx, -ny, -nz, 0.0f };
glLightfv(lt, GL_POSITION, posE);
glPopMatrix();
}