PDA

View Full Version : Specular light not directional?



08-09-2002, 01:52 PM
my problem is this, i set up a light, and just goofing around i make it(the light) rotate and translate with the mouse, heres the odd thing, the specularity only moves positionally?
if i change the light direction, the specularity stays put? WTF?
is this supposed to happen? is there a work around other than putting a huge diffuse?

Morglum
08-10-2002, 06:30 AM
that is queer. of course there's a workaround : there must be a problem inside of your code. Could you post part of it ?

08-10-2002, 08:14 AM
most assuredly,

GL Init Code




GLfloat Ambient_Light[] = {0.1f,0.1f,0.1f,1.0f};
GLfloat Diffuse_Light[] = {0.3f,0.3f,0.3f,1.0f};
GLfloat Specular_Light[] = {0.5f,0.5f,0.5f,1.0f};
GLfloat Specular_Reflection[] = {1.0,1.0,1.0,1.0f};
static GLfloat Light_Position[] = {0.0,0.0,1.0,1.0};
static GLfloat Light_Direction[] = {-0.0,0.0,-1.0};

void GL_Init(void)
{
glClearColor(0.5f,0.5f,0.5f,1.0f);
glClearDepth(1.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glFrontFace(GL_CW);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Ambient_Ligh t);

glLightfv(GL_LIGHT0,GL_AMBIENT,Ambient_Light);
glLightfv(GL_LIGHT0,GL_DIFFUSE,Diffuse_Light);
glLightfv(GL_LIGHT0,GL_SPECULAR,Specular_Light);
glLightfv(GL_LIGHT0,GL_POSITION,Light_Position);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,Light_Direct ion);
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,90.0f);
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,128.0f);

glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT);

glMaterialfv(GL_FRONT,GL_DIFFUSE,Specular_Reflecti on);
glMaterialfv(GL_FRONT,GL_AMBIENT,Specular_Reflecti on);
glMaterialfv(GL_FRONT,GL_SPECULAR,Specular_Reflect ion);
glMateriali(GL_FRONT,GL_SHININESS,128);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE) ;
glEnable(GL_LIGHTING);
}



the lighting draw code

the Scroll/angles are float point values alter by the movement of the mouse.





glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glLoadIdentity();

glPushMatrix();
glLoadIdentity();
glTranslatef(XScroll,YScroll,ZScroll);
glRotatef(xangle,1.0f,0.0f,0.0f);
glRotatef(yangle,0.0f,1.0f,0.0f);
glLightfv(GL_LIGHT0,GL_POSITION,Light_Position);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,Light_Direct ion);

glPopMatrix();

glTranslatef(-0.23,0.1,-1.0);
glRotatef(90,0.0,1.0,0.0);

glCallList(board);



the List being drawn, doesn't really alter anything

this enough?

Morglum
08-10-2002, 08:24 AM
???
What's this glPopMatrix doing here ?
It cancels all matrix transformations done above !

Try calling glPopMatrix _after_ the glCallList.

Does it work now ?
If not, try replacing the glCallList by the equivalent opengl code. (ie, the code between glNewList and glEndList).

08-10-2002, 07:20 PM
>Try calling glPopMatrix _after_ the glCallList.

Does it work now ?
<

unfortunatly if i do this the object(board) will also be rotated/translated with the light.

>
If not, try replacing the glCallList by the equivalent opengl code. (ie, the code between glNewList and glEndList).
<

nope... still nothing.

another oddity, if i set GL_LIGHT_MODEL_LOCAL_VIEWER to true as in the code shown the specularity no longer works positionally either?

im totalally at a loss.

Morglum
08-11-2002, 08:38 AM
I've read more carefully your first post. so, the light's position is ok, but you have a problem with the light's direction.

I'd like to know : when you change the initial value of Light_Direction, does it change the specularity ?
Also, could you post me your whole code by e-mail ?

Also, here's an ugly trick that will necessarily work : instead of applying opengl transformations to the light, compute by yourself (using sine and cosine) the transformed light's direction. (But I admit that it isn't a wholly satisfactory answer).

08-11-2002, 11:25 AM
>
I'd like to know : when you change the initial value of Light_Direction, does it change the specularity ?
<

the initial specularity makes no difference.

>
Also, could you post me your whole code by e-mail ?
<

its several thousand lines(lwo loader for the model/file handler/win32 handler/utilities). i'll try and work out a smaller version minus the loader/files/utilities/ maybe win32 handling, shouldn't take to long, though ive been somewhat preoccupied.

>
Also, here's an ugly trick that will necessarily work : instead of applying opengl transformations to the light, compute by yourself (using sine and cosine) the transformed light's direction. (But I admit that it isn't a wholly satisfactory answer).
<

i don't know how much help this wold be if even the inital direction doesn't work.

Morglum
08-12-2002, 04:42 AM
Eureka !!!

Forget all what I've previously said !

It's absolutely normal that the specularity does _not_ depend on the spot's direction.
Specularity = the surface reflecting the light like a mirror.
Go to a mirror in your bathroom. Take a pocket lamp with you. Does the image of the pocket lamp in the mirror depend on its direction ? No ! it depends on
1) position of the pocket lamp
2) position of your eye (or eyes if you're healthy)
3) normal vector of the mirror

Got it ?

08-12-2002, 09:03 AM
aaahhh, yes. i see, in order for the light to be specular it must be reflected directly, therefore it was reflecting directly along the specified normals, since only the light was changing and not the normals the specularity did not move.

thanks a bunch!