FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   lights control
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: lights control  (Read 2091 times)
flight404

WWW Email
lights control
« on: Jul 2nd, 2003, 5:11am »

Understanding that the light controls are low priority, any chance someone could help me understand a little about the positioning with g.lightX g.lightY and g.lightZ
 
I am refining a little solar system modeller and I want the sun to be a light source.  But despite my repeated attempts, I cannot seem to put the lights where they need to be.  They always end up 'above' the system and no amount of finagling will make them budge from their 'up' position.  Does the translate matrix stack effect this positioning?
 
www.flight404.com/p5/solarSystem1
(disclaimer:  this example is SUPER hokey)  
 
 
Try pasting the source and modifying the g.lightX,Y,Z for both lights to try to get them to 'be' the sun.  I was not at all successful.
 
 
More ?s
 
1. is it possible to disable or reposition light 0 and 1 without it making the entire scene dark?  I tried to turn them off but this resulted in none of the lights working.
 
2. Ambient and Diffuse seem to do the same thing in this example.  How are they different?  I have never really used any 3D programs (ok, I used Bryce a few times to make water ripple and fractal mountains) so I don't really understand the difference.  I assumed that ambient was infinitely far away, resulting in similar highlights on all objects despite their distance from the light... whereas Diffuse is just a soft light which doesn't cast harsh shadows.
« Last Edit: Jul 2nd, 2003, 5:17am by flight404 »  
arielm

WWW
Re: lights control
« Reply #1 on: Jul 2nd, 2003, 10:31am »

i'm not a professional p5 lighter yet, but in the following example, i try to get the sun as the light source for the other planets:
 
Code:

float elevation, azimuth, twist, distance;
float o;
 
void setup()
{
  size(400, 400);
  background(16);
  noStroke();
 
  // it's possible to play with theses values with loop()
  elevation = radians(15.0);
  azimuth = radians(0.0);
  twist = radians(0.0);
  distance = 1000.0;
 
  o = 0.0;
}
 
void loop()
{
  beginCamera();
  perspective(60.0, (float) width / (float) height, 1.0, 1000.0);
    translate(0.0, 0.0, -distance);
    rotateZ(-twist);
    rotateX(-elevation);
    rotateZ(-azimuth);
  endCamera();
 
  // light stuff here, after the camera stuff...
 
  g.lightX[0] = 0.0;
  g.lightY[0] = 0.0;
  g.lightZ[0] = -distance;
 
  g.lightR[0] = 0.1;  // a very low reddish tint
  g.lightG[0] = 0.0;
  g.lightB[0] = 0.0;
 
  g.lightX[1] = 0.0;
  g.lightY[1] = 0.0;
  g.lightZ[1] = -distance;
 
  g.lightR[1] = 1.0;
  g.lightG[1] = 1.0;
  g.lightB[1] = 0.0;
 
  noLights();  // the sun is not affected by lights!
 
  fill(255, 255, 0);
  sphere(100);  // sun
 
  lights();
 
  rotateY(o);
  translate(300, 0, 0);
  fill(153);
  sphere(50);  // planet
  o += radians(5.0);
}

 
a few remarks, discoveries:
 
- i'm using beginCamera() to be based on my own coordinate system (0, 0, -1000) being the new center of the universe while the eye is at (0, 0, 0) (i think it simplifies stuff, not to have to rely on width / 2 and height / 2 all the time)
 
- i'm not using at all light[2] and light[3] because light[0] is ambient by default, and light[1] is diffuse by default... so i just try to override their original settings...
 
- i think the more lights you have, the more inner calculation are required (afterall, lighting is made with vertex coloring...)
 
- it's possible to turn on and off lights while rendering, so for instance, the sun is always colored...
 
- ambient lights should be given very low values, otherwise they "wash" everything...
 
 
to be further explored...
 

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »