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?

  • \$\begingroup\$ Are you using shaders? \$\endgroup\$ – Notabene Mar 2 '11 at 17:05
  • \$\begingroup\$ You can add second triangle in geometry shader with opposite vertex order (CCW or CW) and with opposite normal vector. \$\endgroup\$ – zacharmarz Mar 2 '11 at 17:18
  • \$\begingroup\$ @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. \$\endgroup\$ – Marnix Mar 2 '11 at 17:23
  • \$\begingroup\$ @notabene: No not yet, but I would like to have answer for both then =) \$\endgroup\$ – Marnix Mar 2 '11 at 17:24

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

  • \$\begingroup\$ 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. \$\endgroup\$ – Marnix Mar 2 '11 at 17:57
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – void Mar 2 '11 at 19:44
  • \$\begingroup\$ + a lot for your comment on glLightModel. This is exactly what I was looking for. \$\endgroup\$ – 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.

  • \$\begingroup\$ Thanks for the confirmation. What about @void's solution? Does it sound solid to you? \$\endgroup\$ – Marnix Mar 2 '11 at 17:59
  • \$\begingroup\$ I think @void's solution is correct. \$\endgroup\$ – zacharmarz Mar 2 '11 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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