Hi Cedric, I'm glad you think my image has good lighting. But it's nothing facny, just a combination of 3-6 plain old directionalLight() calls.
The direction of the lights is given by slightly randomized vectors to keep things interesting. I usually also have a way to interactively increase or decrease the strength of the light.
You can look at the following sketch for a basic example. Press "l" to reset the lights, "+" and "-" to adjust light strength.
Code:import processing.opengl.*;
PVector obj[],l[];
int col[];
float str;
void setup() {
size(600,600, OPENGL);
initScene();
}
void draw() {
background(0);
noStroke();
translate(width/2,height/2);
rotateX(radians(-30));
rotateY(radians(frameCount)*0.1);
// lights();
for(int i=0; i<l.length; i++)
directionalLight(str,str,str, l[i].x,l[i].y,l[i].z);
for(int i=0; i<obj.length; i++) {
pushMatrix();
fill(col[i]);//min(obj[i].y*10,255));
translate(obj[i].x,0,obj[i].z);
box(obj[i].y,obj[i].y*3,obj[i].y);
popMatrix();
}
}
void initScene() {
obj=new PVector[(int)random(50,100)];
col=new int[obj.length];
for(int i=0; i<obj.length; i++) {
col[i]=color(random(255,200),random(100,255),0);
obj[i]=new PVector(
random(-0.5,0.5)*width,
random(10,50),
random(-0.5,0.5)*width);
}
initLight();
}
void initLight() {
l=new PVector[(int)random(3,7)];
for(int i=0; i<l.length; i++) {
str=random(TWO_PI);
l[i]=new PVector(cos(str),0.3,sin(str));
}
str=random(120,180);
}
void keyPressed() {
if(key=='-') str-=5;
if(key=='+') str+=5;
if(key=='+' || key=='-') {
str=constrain(str, 0,255);
println("Light strength: "+str);
}
if(key=='l') initLight();
if(key==' ') initScene();
}