Skip to main content
GameDev.net gamedev.net
🔒 Locked

Normal problem

Started by Duekiller Dec 12, 2005 at 9:31 AM 15 replies 1.4k views
Original Post
Duekiller
Duekiller
I am really stubled here and I was wondering if anyone had a good solution. Alright here is my problem: I have a geometry that takes a while to compute, but once computed I use display lists to rotate and zoom (its a CAD software). The problem that I am having is that I was the normals to always face user, so when I original compute I negate the normal depending on which direction it is facing. Now, here is the issue that I am having. Since all normals face the user when the geometry is computed if you pan 180 degrees everything appears screwed up. My question is, is there a way to change the normals in a display list without having to recompute the scene ?
bluntman
bluntman
You could use a vertex shader. You get to transform the normal however you want in a shader.
What effect is it you are trying to achieve by flipping the normals? Two sided lighting?
mrthompson
mrthompson
Maybe you mean to turn backface culling off?
Duekiller
Duekiller
I am trying to achieve two sided lighting.

Imagine you have a rectangle and you are staring straight down at it, now I want to have the same lighting if you stare at the back face (the light source is the "camera")
levjs
levjs
Well, if you rotate 180 degrees, you would not be looking at a backface. When you look at a cube, the backfaces are the ones that you cannot see unless you are INSIDE of the cube. The back of the cube's backface is the face you would see if the front was removed. So you should only flip normals when you are able to see the faces insid the cube.
Levi
Duekiller
Duekiller
Quote:
Original post by levjs
Well, if you rotate 180 degrees, you would not be looking at a backface. When you look at a cube, the backfaces are the ones that you cannot see unless you are INSIDE of the cube. The back of the cube's backface is the face you would see if the front was removed. So you should only flip normals when you are able to see the faces insid the cube.
Levi


That is the problem I am using a display list to display the results and make them interactive.... Reseting the normals would require me to recompute the geometry, which takes a decent amount of time.
levjs
levjs
Backfaces' normals are the exact same except they are flipped. Couldn't you use this to your advantage. For example, instead of recomputing the whole thing, couldn't you just multiply the vectors by -1 to flip it? That would take much less time.
Levi
Duekiller
Duekiller
Quote:
Original post by levjs
Backfaces' normals are the exact same except they are flipped. Couldn't you use this to your advantage. For example, instead of recomputing the whole thing, couldn't you just multiply the vectors by -1 to flip it? That would take much less time.
Levi


Yes I could, but the problem is How to I get to the normal without recomputing my scene. I set the normal when I compute the geometry and then as soon as I am done it all gets dumped into a display list. My question is how do I change the normals in the display list ?

bluntman
bluntman
Well if you really don't want to use a vertex shader, then you can still recreate your display list without recalculating the geometry (assuming you don't delete it as soon as the list is created). I'm sure there must be a cleverer way of doing it though.
Duekiller
Duekiller
Yeaha that is what I am thinking. I am thinking that there might be a trick to this that I am missing.
Duekiller
Duekiller
Is there any way I can give the back face the same properties as the front face, just with a diffrent normal ?
zedzeek
zedzeek
Quote:
Is there any way I can give the back face the same properties as the front face, just with a diffrent normal ?
yes check the spec for exact details
but supply 1 normal per primitive/vertex (ie the normal way dont flip normsl yourself)
and use GL_FRONT_AND_BACK lighting / materials u might also need to enable something (its been years since ive used gl lighting)
Duekiller
Duekiller
Alright I think I got it working. I give it the regular normal that is prependicular to the screen and then i supply the matterial with GL_LIGHT_TWO_SIDE and it seems to be working. Thanks for all your help I appreciate it.
Kalidor
Kalidor
Quote:
Original post by zedzeek
but supply 1 normal per primitive/vertex (ie the normal way dont flip normsl yourself)
and use GL_FRONT_AND_BACK lighting / materials u might also need to enable something (its been years since ive used gl lighting)
The extra piece zedzeek was talking about is glLightModel* with pname set to GL_LIGHT_MODEL_TWO_SIDE. All this is in the Lighting Chapter of the Red Book by the way.

EDIT: Too slow
levjs
levjs
Ha, I thought about that, but I wasn't sure if you wanted to do it yourself. If you remmember, that's what I perscribed to you with the other problem you were having with the ligting on the back of an object. There the problem was the normals, and I thought it was that, and this time, I thought it was the normals and it wasn't. : ) Just a bad guesser.
Code-R
Code-R
check the two-sided polygons sample in the nvsdk:
http://download.developer.nvidia.com/developer/SDK/Individual_Samples/samples.html

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.