two sided normals

Is there a way to set two opposing normals on a polygon model’s face ?

I have used { 1 } and also set_two_sided(true), but they seem to do the same thing which is to allow both sides of the polygon to be visible (no back face clipping).

The problem is the lighting when I rotate the polygon. When the normal is pointing in the general direction of the light source, it will be lit up more, and as it rotates away ( that is the normal defined in the egg file for that face) it darkens. The face that is now “pointing” toward the light source has taken on the shading of the face where the actual polygon normal is. I know in other graphic APIs you can set two sided lighting which will supply opposing normals to a poly, there can be a “NotSolid” type of shading. Is there a way to set this kind of attribute in Panda ?

Thanks

tim

I believe this can be done using setTwoside in the Material object.

Note, for the record, that setTwoside only works in OpenGL; it is not supported by DirectX.

If you add the config variable:

egg-emulate-bface 1

to your Config.prc file, then an egg file will be loaded in such a way that it actually generates two-sided polygons; and this works in both OpenGL and DirectX and is also usually slightly faster than the setTwoside method.

David

Thanks rdb and drwr

I guess having a Material in my egg file makes a difference, because I didn’t have one. Now that I put the Material lines in the egg file the lighting looks right as I rotate the model around. I’m just using { 1 } in the egg file and not set_two_sided, and it does work if I set egg-emulate-bface 1 or not. I remember reading drwr’s post about this to Anon on March 21, the difference being that “the egg loader doesn’t double polygons by default; it does it only if you set “egg-emulate-bface 1” in your Config.prc file (and then blow away the model-cache or at least touch the egg file to force it to reload)”

What I’m doing is making a “cross-quad” egg model that I then put different grass clumps on in code.

here is the egg model if anyone finds any improvements to make:

<CoordinateSystem> { Z-up }
<Material> Material {
  <Scalar> diffr {1.}
  <Scalar> diffg {1.}
  <Scalar> diffb {1.}
  <Scalar> ambr {1.0}
  <Scalar> ambg {1.0}
  <Scalar> ambb {1.0}
  <Scalar> specr {0.}
  <Scalar> specg {0.}
  <Scalar> specb {0.}
  <Scalar> shininess {0.0}
}
<Group> CrossQuad {
  <VertexPool> CrossQuad {
    <Vertex> 0 {
      0.5 0.0 0.5
      <UV>  {
        1.0 1.0
      }
    }
    <Vertex> 1 {
      -0.5 0.0 0.5
      <UV>  {
        0.0 1.0
      }
    }
    <Vertex> 2 {
      -0.5 0.0 -0.5
      <UV>  {
        0.0 0.0
      }
    }
    <Vertex> 3 {
      0.5 0.0 -0.5
      <UV>  {
        1.0 0.0
      }
    }

    <Vertex> 4 {
      0.0 0.5 0.5
      <UV>  {
        1.0 1.0
      }
    }
    <Vertex> 5 {
      0.0 -0.5 0.5
      <UV>  {
        0.0 1.0
      }
    }
    <Vertex> 6 {
      0.0 -0.5 -0.5
      <UV>  {
        0.0 0.0
      }
    }
    <Vertex> 7 {
      0.0 0.5 -0.5
      <UV>  {
        1.0 0.0
      }
    }

  }
  <Polygon> {
    <MRef> { Material }
    <BFace> { 1 }
    <Normal> { 0.000000 -1.000000 0.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { CrossQuad } }
  }
  <Polygon> {
    <MRef> { Material }
    <BFace> { 1 }
    <Normal> { 1.000000 0.000000 0.000000 }
    <VertexRef> { 4 5 6 7 <Ref> { CrossQuad } }
  }
}

Putting a material in the egg file will automatically make the material two-sided in the presence of the bface flag. So that’s fine.

David

I tried to use this code but it doesnt work.

from panda3d.core import loadPrcFileData
loadPrcFileData("", "egg-emulate-bface 1")

What are you trying to do?

I want two sided models.

Well, you have to add the {1} flag to your polygons or use setTwoSided(True) on your models. That configuration variable only changes the nature of how “bface” is interpreted - whether it actually generates two back-to-back polygons or whether it generates polygons that have a cull attribute set.

Can it work with collision meshes?

No. Collision meshes don’t respect the flag. You wouldn’t want them to anyway–two-sided collision polygons generally behave poorly, because the collision system has a hard time resolving which way to move an intersecting object to correct it.

David