PDA

View Full Version : lighting back facing triangles _without_ using two sided lighting



Nicolas Lelong
02-05-2003, 07:32 AM
Hi everyone,

I'm having a little problem: I need to display back facing polygons with some basic standard GL lighting.

Easy you'll think, and indeed it is in most cases, but I need to do this on GeForce 2 with VAR enabled. As two sided lighting falls back to software on GF2, it crawls horribly !

Does anyone have a nice idea to invert polygon normals via GL, in this context, without having to touch my geometry ?

Thanks in advance,
Nicolas.

V-man
02-05-2003, 07:16 PM
#1
You could try vertex programs.

It's a matter of negating the normal and deal with the inverse transpose of modelview.

//CODE ADDED
!!ARBvp1.0

ATTRIB iNormal=vertex.normal;

PARAM mvinv[4]={ state.matrix.modelview.invtrans };

TEMP TransNormal, NegNormal;

MOV NegNormal, -iNormal;
DP3 TransNormal.x, mvinv[0], NegNormal;
DP3 TransNormal.y, mvinv[1], NegNormal;
DP3 TransNormal.z, mvinv[2], NegNormal;

///////////////

vp run in software mode (Gf2) so it will cost you.

#2
yup, touch the damned geometry. Go ahead, be a man!

[This message has been edited by V-man (edited 02-05-2003).]

Nicolas Lelong
02-06-2003, 01:57 AM
Re: #1
Humf, it falls back to the same problem: VP are CPU based on GF2 & my geometry is in AGP mem -> damn slooww.

Re: #2
I'd like to be a man, really http://www.opengl.org/discussion_boards/ubb/smile.gif

Arf, it seems that this nasty little special case will generate much more work than I'd like!

fresh
02-06-2003, 09:02 AM
Draw it twice with the backface culling reversed and ztest set to equal.

Nicolas Lelong
02-07-2003, 12:12 AM
Yep, that's what I first thought - and did - but the problem is still there: the normals are still pointing is the 'front face' direction - and as I have to disable the 'two sided lighting' - the faces are not lit correctly (their normals should be negated).

I was hoping that a modelview matrix trick could safe my life, but it seems that I'm bound to play with my geometry instead...

Thanks,
Nicolas

rgpc
02-07-2003, 03:05 AM
I was hoping that a modelview matrix trick could safe my life, but it seems that I'm bound to play with my geometry instead...
[/B]

That shouldn't be a bother, all you need to do is store a reversed set of normals.

Or maybe you can transform the light(s) relative to the object? (ie. Your normals stay pointing the same way but you put the light(s) on the opposite side of the objects origin)