PDA

View Full Version : Model falls 'outside' the light



fokatar
04-15-2009, 02:11 AM
Hi!

I'm fairly new to openGL. For my phd I have to try to put a face of someone else on top of my face in a way it looks 'realistic'. I have a problem with the shading part (at least to start with). At some point in the software the face from the camera is taken and with some points on the face a model is calculated. This model is then drawn with openGL and a texture (of someones face) is applied to the model. So I thought that the shading would also be possible to do with openGL. But when I enable the lighting in openGL and put a light on the right side of the model (together with an ambient light) it does not work as I intended. When I move the head to the back (away from the camera) it seems as if light doesn't reach the model. I looked at the max and min coordinate values of the model and saw that this problem arises when the model is behind the origin (thus z-values are negative). I have made some videos to visualize the problem for you:
the videos are available at http://staff.science.uva.nl/~aazcarat/openGL/
under0continue.avi - video of the problem without stopping
under0exit.avi - video of the problem stopped at the point where the maxZ value of the model is below 0.0
In this directory you can also find the debug output from the software. In this txt file all the openGL calls that are in the software are printed in order of flow:
Debug-under0continue.txt - the debug output gotten with the under0continue.avi file
Debug-under0exit.txt - the debug output gotten with the under0exit.avi file (as soon as the maxX is under 0 the program is stopped (--max-X-Y-Z-> 48.6611,61.7238 -2.97314))

When you see in the output something like this:
glFrustum(0 - GetHalfHeight() * GetWHRatio(), GetHalfHeight() * GetWHRatio(),0 - GetHalfHeight(), GetHalfHeight(), GetFocusLength(), GetDepth() + 50000)
----> -10.6667,10.6667 -8
----> 8,30 50600
This means that 0 - GetHalfHeight() * GetWHRatio() is the first value after the ----->. Thus 0 - GetHalfHeight() * GetWHRatio() is -10.6667 and GetHalfHeight() * GetWHRatio() is 10.6667 etc.

The openGL calls that are of importance (at least thats what I think) are the ones under these lines:
====HERE THE TEXTURE IS UPDATED WITH THE FACE FROM THE IMAGE=====
===============FROM THIS POINT THE PROBLEM ARISES===============
Each frame the model and texture is redrawn. This line
------------------------------------------------
is the point where the face has finished drawing ,thus after these lines the next frame is taken from the webcam and 'everything' is recalculated and redrawn. That is why a lot is done repeatedly.

I hope someone can help me and that I have explained my problem as well as possible. I'm not able to give the code because it is not publicly available (it is not my code, I just have to improve it).

All help is welcome. If I have to explain it in more detail just mention it. Thanks in advance for the help.

Aitor

P.S: I don't know if this problem is in the right forum subgroup. If so, sorry for that.

fokatar
04-15-2009, 02:23 AM
Oh I forgot. The blue lines on the texture are the normals drawn (as you can see the normals all point from the face out).

BigDave
04-15-2009, 05:59 AM
That's quite a complicated explanation for a simple problem! The video was helpful though.

Possibly it could be the light attenuation. When you set GL_POSITION , the fourth value (either 1 or 0) sets the light to be local or infinitely far, thus enabling or disabling attenuation. Try setting it the opposite of what you currently have it set to and see if that solves your problem (ie. if you currently have a light set to (0,0,1,0) set it to (0,0,1,1) or vice versa). That could give you an indication whether this is the problem.

This link should help:
http://www.opengl.org/sdk/docs/man/xhtml/glLight.xml

fokatar
04-15-2009, 07:52 AM
It is not the attenuation I think. When I was searching for a solution I found the page where you linked to. So I looked at my position but the w (4th) value was 0.0 as it is supposed to be(0 is directional light and 1 is point light). I have started to change things in the position of my light again and somehow it works now. At first I had positioned the light at (500,0,1000), I found some other code which had the light at (1,1,0) and it worked (light came from the top right corner). Then I changed the coordinates in the code that worked to (500,0,1000) and I got the same (wrong) effect again. I then changed the position to (500,0,100) and now it seems to work. Maybe the z-value of 1000 is too high (which I doubt).

Thanks for the help BigDave.

fokatar
04-15-2009, 08:00 AM
Don't think the high value is an issue either. If the light is directional the effect is the same if you initialize the light at (500,0,1000) or (0.5,0,1) or even (5,0,10), the direction is the same in all. Tried all these coordinates and the effect is the same (model falls 'outside' the light).

BigDave
04-15-2009, 08:28 AM
Are you normalising your normals? Not doing this could also be responsible for a similar effect.

Try :

glEnable(GL_NORMALIZE);

which will normalise the normals during the render process automatically.

fokatar
04-16-2009, 02:45 AM
I looked into it and tried some different parameters (position of light, disable and enable GL_NORMALIZE etc). When I calculate the normals I already normalize them. Then enabling GL_NORMALIZE or not has no extra effect. Even commenting out the code I use to normalize and enabling and disabling the GL_NORMALIZE has no effect.