We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › texture and directionalLight
Page Index Toggle Pages: 1
texture and directionalLight (Read 596 times)
texture and directionalLight
Sep 20th, 2005, 9:39am
 
Hi,

Should a texture disable the directionalLight?

In the example below mousePressed renders a texture onto a cube. Normally the cube respond to the light by having darker and lighter sides, with a texture attached it does not.

Code:
PImage eBgi;
float fRtX, fRtY;
void setup() {
fRtX = 0;
fRtY = 0;
size(300,300,P3D);
noStroke();
eBgi = new PImage(width,height);
for (int i=0;i<eBgi.pixels.length;i++) eBgi.pixels[i] = i<eBgi.pixels.length/2?color(51,102,126):color(102,126,51);
}
void draw() {
fRtX += 0.0001*(mouseY-height/2);
fRtY -= 0.0001*(mouseX-width/2);
background(0);
directionalLight(51, 102, 126, 0, 0, -1);
translate(width/2, height/2, 100);
rotateX(fRtX);
rotateY(fRtY);
textureMode(IMAGE);
int iSze = 90;
int iPsx = -iSze/2;
int iPsy = -iSze/2;
int iPsz = -iSze/2;
for (int i=0;i<8;i++) {
rotateX((i+0)%3*PI*.5);
rotateY((i+1)%3*PI*.5);
rotateZ((i+3)%3*PI*.5);
beginShape();
if (mousePressed) {
texture(eBgi);
vertex(iPsx, iPsy, iPsz, 0, 0);
vertex(iPsx+iSze, iPsy, iPsz, eBgi.width,0);
vertex(iPsx+iSze, iPsy+iSze, iPsz,eBgi.width,eBgi.height);
vertex(iPsx, iPsy+iSze,iPsz, 0, eBgi.height);
} else {
vertex(iPsx, iPsy, iPsz);
vertex(iPsx+iSze, iPsy, iPsz);
vertex(iPsx+iSze, iPsy+iSze, iPsz);
vertex(iPsx, iPsy+iSze,iPsz);
}
endShape();
}
}


gr...

...Ron
Re: texture and directionalLight
Reply #1 - Sep 20th, 2005, 12:42pm
 
My understanding is that when the lights go on, the texture goes out.

I think that it's probably due to the lights using the texture map to do the light rendering.
Re: texture and directionalLight
Reply #2 - Sep 20th, 2005, 2:41pm
 
I don't think that is entirely the case. I've tried other lights of course and both spotLight  an pointLight do work with a texture (although not exactly in the way you'd expect).
Re: texture and directionalLight
Reply #3 - Mar 6th, 2007, 12:48pm
 
To get lighting to work with textures you have to set the normal (http://processing.org/reference/normal_.html).

i.e.
normal(iPsx, iPsy, iPsz);  
vertex(iPsx, iPsy, iPsz, 0, 0);  
normal(iPsx+iSze, iPsy, iPsz);  
vertex(iPsx+iSze, iPsy, iPsz, eBgi.width,0);  
normal(iPsx+iSze, iPsy+iSze, iPsz);  
vertex(iPsx+iSze, iPsy+iSze, iPsz,eBgi.width,eBgi.height);  
normal(iPsx, iPsy+iSze,iPsz);
vertex(iPsx, iPsy+iSze,iPsz, 0, eBgi.height);
Page Index Toggle Pages: 1