spotLight() not behaving like i'd expect

I’m experimenting with light sources to see how their attributes affect the light movement and casting on 3D shapes. I set up a spotLight() above, pointing straight down, a large flat box() below, and i increment the spotLight() X value.

  • I expect a circle of light of some size going across the surface of the box().
  • I’m seeing the top surface of the box() lit towards the left while x = 0.0f, darkness as x moves along its axis, and then the top surface of the box() lit towards the right while x = width.
  • Also, it gets brighter the further away i make the y value, which is extra confusing.
// Spotlight X value to be incremented
float x = 0.0f;

void setup()
{
  fullScreen(P3D);
}

void draw()
{
  background(0);
  
  // Pull camera way back so i can see the whole area
  //        eyeX          eyeY      eyeZ          centX          centY      centZ   upX  upY   upZ
  camera( width / 2.0f, -height, height * 2.0f, width / 2.0f, height / 2.0f, 0.0f, 0.0f, 1.0f, 0.0f);
  
  float rgb = 255.0f;
  
  // spotLight Coords
  float y     = -500.0f; // THE FURTHER AWAY, THE BRIGHTER?!?! 0.0f is darker
  float z     = 0.0f;
  float nX    = 0.0f;   
  float nY    = 1.0f;   // This should point the spotLight down, no?
  float nZ    = 0.0f;
  float ang  = PI / 4.0f;  // Angle of cone pointing straight down?
  float conc = 2.0f;        // Anything above 5 makes the light disappear. 
// What does "exponent determining the center bias of the cone " actually mean in terms of what i should see?
  
  // Move spotLight along the x axis
  x += 10.0f;
  
  // wrap spotlight
  if (x > width)
    x = 0.0f;
    
  // spotLight Source position marker to see where the spotLight should be 
  // pointing straight down from, for my own reference
  fill(rgb, rgb, rgb);
  pushMatrix();
    translate( x, y, z);
    circle(0, 0, 100);
    rect(0, 0, 25, height);
  popMatrix();

  // the spotLight that's being a jerk
  spotLight( rgb, rgb, rgb, x, y, z, nX, nY, nZ, ang, conc);
  
  // giant flat box to see where the spotLight focuses its light
  fill(125, 23, 202);
  pushMatrix();
    translate( width / 2.0f, (height / 2.0f) + 150.0f, 0.0f);   
    box(width, 150, height * 2.0f);
  popMatrix();
}

I assume i’m misunderstanding something about the spotLight arguments, most likely the nX, nY, nZ, cone angle, and concentration values.

Any tips?

You need to learn more about computer graphics and how light is calculated and reflected in a 3D digital world. I can’t elaborate too much right now, cuz I’m about to sleep, but trie this: make a wall (or a floor) with some cubes. Like a 10x10 wall made of cubes. Then, point your spotlight against it and you will see what you’re expecting. In other words, you need make a mesh to create the illusion of light reflecting on the surface. If you want to create this effect on a cube surface, you will have to create your own Cube class, where each side is made of small rectangles, making a mesh for each side. The more each side is subdivided, the more realistic will be the effect.

1 Like

Fantastic! This helps me understand. Yeah, that’s what these sketches are: experiments to understand how light works in 3D graphics. (I’m normally an audio person.) So, if i’m understanding you, the issue isn’t with the spotLight, it’s with the giant single surface of the 3D shape. The single surface doesn’t really know how to compute the light hitting it properly.

I updated my sketch to make a floor of cubes and I’m seeing exactly what you explained, and exactly what i expected to see.

for (int i=0; i<width; i+=10)
  {
    for (int j=-height; j<height; j+=10)
    {
      pushMatrix();
        translate( i, (height / 2.0f) + 150.0f, j);
        box(10.0f, 150.0f, 10.0f);
      popMatrix();
    }
  }

Cheers!

2 Likes