View Full Version : Single sided lighting problem
01-16-2004, 08:25 AM
Perhaps I misunderstood this, but I am trying to get single sided lighting working correctly.
Basically, 3 options, (lighting)shade front only, shade back only, or shade both.
2 approaches, both failed(only 1 sided is shaded, but same side for both, front, back selection.
Using glColorMaterial, and color tracking,
using GL_FRONT for the material func,
I set glFrontFace(GL_CCW) for front face
Set two sided model, 0
2) Same for BACK, except set glFrontFace(GL_CW)
set two sided model, 1.0.
1. for FRONT, call material func w/ GL_FRONT
2. for BACK, call material func w/ GL_BACK
for both set two sided light model to
3. BOTH, call material GL_FRONT_AND_BACK
light model 1.0
Only two sided work okay. Am I missing something. Thanks.
P.S. glInterleavedArray + glDrawArrays for rendering.
01-16-2004, 03:34 PM
The implication with face culling OR two sided lighting etc is that your data is well behaved. If your sides don't mean anything, in other words, if your face winding is a mess then you need to turn on two sided lighting which gives you reverse normals on back faces.
Let's be clear, there are several elements here and you need to separate them conceptually & test in isolation to avoid confusion. What may seen naively to be implicitly linked concepts infact may not be except through simple mechanisms and your own code. Face winding and normals and two sided lighting are related concept but perhaps not as automatically as you assume.
Important points (some redundance and repetition, sorry):
1) You generate the normals used by the equations, if your data is bad your normals will be bad. If your winding flips then so will your normals (if your sums are correct).
2) If your winding is correct but your normals don't match the winding things will get very confusing. Normals should match face winding, OpenGL implicitly flips winding on tmesh primitives so know what you are doing with edge verts and winding order w.r.t. OpenGL primitives when computing normals.
3) If your normals are OK but your winding is a mess then you can simply turn off face culling and all will probably be good for most purposes. If your normals are a mess and your winding is OK, you need to fix your normal calculations.
4) Turn face culling on and just draw the object to see if it looks OK, then you decide what you need to draw. What you need is driven by the data winding.
5) Do you need to draw two sides to complete the object's single skin? Then you will probably need two sided lighting to support the normal flipping if your normals match face winding.
6) Material setting for both sides won't hurt you, just set both to be getting along with.
7) With front and back materials the same two sided lighting will only have one effect, flipping the normals based on face winding.
7) Drawing the model with CW culling then CCW culling and reversing normals between passes is the same as two sided lighting for the most part.
9) Two sided lighting tends to be slow unless you have high end hardware (this is a changing situation so measure it).
01-18-2004, 09:12 AM
Thanks. Here is the deal.
1) Normals are fine. Tested them to make sure, besides everything is lit correctly, if I use two sided lighting. Single sided lighting, only one side is lit, the other is always not lit, no matter the settings.
2) Vertex ordering, ie ccw, or cw is consistent across a model. Checked this also.
3) I understand culling. In fact, if enable culling, and change the face order , from ccw, cw, and back and so on, then the appropriate side is culled.
4) My problem is, I wish to use single sided lighting, faster in all instances, though the difference is less in faster cards. The problem is, that certain models are wound ccw, others are wound cw(ie the whole mode).
With closed models this is a problem w/ single sided lighting because the model will look unshaded, although it will be shaded inside.
5) I just want to be able to tell opengl, to shade( ie lighting calculations for a front, or back on command). So, the user can switch,
and see both sides(one at a time) lit correctly, but still keep the speed.
Is there a correct way to do this, ie
single sided lighting, front or back, and to switch between them. From what I understood, my method should have worked.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.