Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I think this isn't possible, but I just want to check this:

Is it possible to create a face in opengl that has two normals?

So: I want the inside and outside of some cilinder to be drawn, but I want the lights to do as expected and not calculate it for the normal given. I was trying to do this with backface culling off, so I would have both faces, but the light was wrongly calculated of course. Is this possible, or do I have to draw an inside and an outside? So draw twice?

share|improve this question
    
Are you using shaders? –  Notabene Mar 2 '11 at 17:05
    
You can add second triangle in geometry shader with opposite vertex order (CCW or CW) and with opposite normal vector. –  zacharmarz Mar 2 '11 at 17:18
    
@zacharmarz, I know that I can draw 2 faces, but that is what I want to avoid. If the answer is: no it can't, than it can't. –  Marnix Mar 2 '11 at 17:23
    
@notabene: No not yet, but I would like to have answer for both then =) –  Marnix Mar 2 '11 at 17:24

2 Answers 2

up vote 3 down vote accepted

Use gl_FrontFacing in your fragment program and set your normal to -in_normal if back facing.

share|improve this answer
    
Sounds nice, I will have a look at it once I arrive at the shader-part of my project. I'm first trying to implement it without and will later care about things like shaders and so. –  Marnix Mar 2 '11 at 17:57
2  
I digged around a bit. You can use the fixed function pipeline and set glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); GL will then light backfaces with your back material and reversed normals. –  void Mar 2 '11 at 19:44
    
+ a lot for your comment on glLightModel. This is exactly what I was looking for. –  Marnix Mar 2 '11 at 23:26

Unless you will use custom shaders for triangle replication in geometry shader, there is no way to do this and you have to use twice more triangles.

There is also another way to do it in pixel shader (which is considered to be easier than gs), but it is buggy. You can use abs(n dot l) in phong, but it will cause that the side of the triangle which should be lighted just with ambient light is also lighted with diffuse light.

share|improve this answer
    
Thanks for the confirmation. What about @void's solution? Does it sound solid to you? –  Marnix Mar 2 '11 at 17:59
    
I think @void's solution is correct. –  zacharmarz Mar 2 '11 at 18:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.