Implementing a Skybox

Is there an example anywhere of how to implement a skybox in C++?

If not, what’s the best way to do this?

Cheers,

Chris

Simply load a model, parent it to the camera, and set it to render before everything else in the scene by using binning. Disable depth write if you like. There are numerous examples in Python, which you should be able to translate directly to C++ syntax. For instance, here’s a thread that shows one example:

discourse.panda3d.org/viewtopic.php?t=7638

There are more in the forums if you search for “skybox”.

David

Thanks!

I’ve managed to implement a skybox however the top of the box is missing.

I’ve checked the .egg file and everything seems to be ok. Any idea why the top wouldn’t be appearing?

The normal of the top face could be pointing the wrong way. Can you post the .egg file?

Here’s the .egg file:

<CoordinateSystem> { Z-up }

<Comment> { "Egg laid by Chicken for Blender, version R81" }

<Texture> sky_ft.bmp {
  "./../textures/sky_ft.bmp"
  <Scalar> saved-result { 1 }
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR }
  <Scalar> magfilter { LINEAR }
  <Scalar> wrap { REPEAT }
}
<Texture> sky_up.bmp {
  "./../textures/sky_up.bmp"
  <Scalar> saved-result { 1 }
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR }
  <Scalar> magfilter { LINEAR }
  <Scalar> wrap { REPEAT }
}
<Texture> sky_lf.bmp {
  "./../textures/sky_lf.bmp"
  <Scalar> saved-result { 1 }
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR }
  <Scalar> magfilter { LINEAR }
  <Scalar> wrap { REPEAT }
}
<Texture> sky_bk.bmp {
  "./../textures/sky_bk.bmp"
  <Scalar> saved-result { 1 }
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR }
  <Scalar> magfilter { LINEAR }
  <Scalar> wrap { REPEAT }
}
<Texture> sky_rt.bmp {
  "./../textures/sky_rt.bmp"
  <Scalar> saved-result { 1 }
  <Scalar> envtype { MODULATE }
  <Scalar> minfilter { LINEAR }
  <Scalar> magfilter { LINEAR }
  <Scalar> wrap { REPEAT }
}
<Group> Plane {
  <Transform> {
    <Matrix4> {
      -1.000000 0.000000 0.000000 0.000000
      -0.000000 1.000000 -0.000000 0.000000
      -0.000000 -0.000000 -1.000000 0.000000
      -0.002879 0.038611 2.334409 1.000000
    }
  }
  <VertexPool> Plane {
    <Vertex> 0 {
      -1.00287950039 1.03861057758 2.33440876007
      <UV>  {
        0.000000 0.000000
        <Tangent> { -1.000000 -0.000000 0.000000 }
        <Binormal> { 0.000000 -1.000000 0.000000 }
      }
    }
    <Vertex> 1 {
      0.997120141983 1.03861093521 2.33440852165
      <UV>  {
        1.000000 0.000000
        <Tangent> { -1.000000 -0.000000 0.000000 }
        <Binormal> { 0.000000 -1.000000 0.000000 }
      }
    }
    <Vertex> 2 {
      0.99712061882 -0.961389243603 2.33440876007
      <UV>  {
        1.000000 1.000000
        <Tangent> { -1.000000 -0.000000 0.000000 }
        <Binormal> { 0.000000 -1.000000 0.000000 }
      }
    }
    <Vertex> 3 {
      -1.00287950039 -0.961389422417 2.33440899849
      <UV>  {
        0.000000 1.000000
        <Tangent> { -1.000000 -0.000000 0.000000 }
        <Binormal> { 0.000000 -1.000000 0.000000 }
      }
    }
  }
  <Polygon> {
    <TRef> { sky_up.bmp }
    <Normal> { -0.000000 -0.000000 -1.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane } }
  }
}
<Group> Plane.005 {
  <Transform> {
    <Matrix4> {
      -0.000000 1.000000 0.000000 0.000000
      -0.000000 0.000000 -1.000000 0.000000
      -1.000000 -0.000000 0.000000 0.000000
      0.997120 0.038610 1.334409 1.000000
    }
  }
  <VertexPool> Plane.005 {
    <Vertex> 0 {
      0.997120022774 1.03861045837 0.334408611059
      <UV>  {
        0.000000 0.000000
        <Tangent> { -0.000000 1.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
    <Vertex> 1 {
      0.997120082378 -0.961389183998 0.334408134222
      <UV>  {
        1.000000 0.000000
        <Tangent> { -0.000000 1.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
    <Vertex> 2 {
      0.997120261192 -0.96138972044 2.33440828323
      <UV>  {
        1.000000 1.000000
        <Tangent> { -0.000000 1.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
    <Vertex> 3 {
      0.997120201588 1.03861033916 2.33440852165
      <UV>  {
        0.000000 1.000000
        <Tangent> { -0.000000 1.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
  }
  <Polygon> {
    <TRef> { sky_ft.bmp }
    <Normal> { -1.000000 -0.000000 0.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane.005 } }
  }
}
<Group> Plane.004 {
  <Transform> {
    <Matrix4> {
      -0.000000 -1.000000 -0.000000 0.000000
      -0.000000 0.000000 -1.000000 0.000000
      1.000000 -0.000000 -0.000000 0.000000
      -1.002880 0.038610 1.334409 1.000000
    }
  }
  <VertexPool> Plane.004 {
    <Vertex> 0 {
      -1.00288009644 -0.961389541626 0.334408789873
      <UV>  {
        0.000000 0.000000
        <Tangent> { 0.000000 -1.000000 0.000000 }
        <Binormal> { 0.000000 0.000000 1.000000 }
      }
    }
    <Vertex> 1 {
      -1.00288009644 1.03861010075 0.334408432245
      <UV>  {
        1.000000 0.000000
        <Tangent> { 0.000000 -1.000000 0.000000 }
        <Binormal> { 0.000000 0.000000 1.000000 }
      }
    }
    <Vertex> 2 {
      -1.00287914276 1.03861045837 2.33440852165
      <UV>  {
        1.000000 1.000000
        <Tangent> { 0.000000 -1.000000 0.000000 }
        <Binormal> { 0.000000 0.000000 1.000000 }
      }
    }
    <Vertex> 3 {
      -1.00287914276 -0.961389601231 2.33440876007
      <UV>  {
        0.000000 1.000000
        <Tangent> { 0.000000 -1.000000 0.000000 }
        <Binormal> { 0.000000 0.000000 1.000000 }
      }
    }
  }
  <Polygon> {
    <TRef> { sky_bk.bmp }
    <Normal> { 1.000000 -0.000000 -0.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane.004 } }
  }
}
<Group> Plane.001 {
  <Transform> {
    <Matrix4> {
      -1.000000 0.000000 0.000000 0.000000
      -0.000000 -0.000000 -1.000000 0.000000
      -0.000000 -1.000000 0.000000 0.000000
      -0.002880 1.038610 1.334409 1.000000
    }
  }
  <VertexPool> Plane.001 {
    <Vertex> 0 {
      -1.00287985802 1.03861045837 0.334408730268
      <UV>  {
        0.000000 0.000000
        <Tangent> { -1.000000 0.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
    <Vertex> 1 {
      0.997119724751 1.03861045837 0.334408015013
      <UV>  {
        1.000000 0.000000
        <Tangent> { -1.000000 0.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
    <Vertex> 2 {
      0.997120499611 1.03861045837 2.33440828323
      <UV>  {
        1.000000 1.000000
        <Tangent> { -1.000000 0.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
    <Vertex> 3 {
      -1.0028796196 1.03861045837 2.33440876007
      <UV>  {
        0.000000 1.000000
        <Tangent> { -1.000000 0.000000 0.000000 }
        <Binormal> { 0.000000 -0.000000 1.000000 }
      }
    }
  }
  <Polygon> {
    <TRef> { sky_rt.bmp }
    <Normal> { 0.000000 -1.000000 -0.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane.001 } }
  }
}
<Group> Plane.003 {
  <Transform> {
    <Matrix4> {
      1.000000 0.000000 -0.000000 0.000000
      0.000000 -0.000000 -1.000000 0.000000
      -0.000000 1.000000 -0.000000 0.000000
      -0.002880 -0.961390 1.334409 1.000000
    }
  }
  <VertexPool> Plane.003 {
    <Vertex> 0 {
      0.997120261192 -0.961389541626 0.334408819675
      <UV>  {
        0.000000 0.000000
        <Tangent> { 1.000000 0.000000 0.000000 }
        <Binormal> { -0.000000 0.000000 1.000000 }
      }
    }
    <Vertex> 1 {
      -1.00287938118 -0.961389839649 0.334408402443
      <UV>  {
        1.000000 0.000000
        <Tangent> { 1.000000 0.000000 0.000000 }
        <Binormal> { -0.000000 0.000000 1.000000 }
      }
    }
    <Vertex> 2 {
      -1.00287985802 -0.961389541626 2.33440852165
      <UV>  {
        1.000000 1.000000
        <Tangent> { 1.000000 0.000000 0.000000 }
        <Binormal> { -0.000000 0.000000 1.000000 }
      }
    }
    <Vertex> 3 {
      0.997120261192 -0.961389243603 2.33440876007
      <UV>  {
        0.000000 1.000000
        <Tangent> { 1.000000 0.000000 0.000000 }
        <Binormal> { -0.000000 0.000000 1.000000 }
      }
    }
  }
  <Polygon> {
    <TRef> { sky_lf.bmp }
    <Normal> { -0.000000 1.000000 -0.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane.003 } }
  }
}
<Group> Plane.002 {
  <Transform> {
    <Matrix4> {
      -1.000000 0.000000 0.000000 0.000000
      -0.000000 1.000000 -0.000000 0.000000
      -0.000000 -0.000000 -1.000000 0.000000
      -0.002879 0.038611 2.334409 1.000000
    }
  }
  <VertexPool> Plane.002 {
    <Vertex> 0 {
      -1.00287950039 1.03861057758 2.33440876007
    }
    <Vertex> 1 {
      0.997120141983 1.03861093521 2.33440852165
    }
    <Vertex> 2 {
      0.99712061882 -0.961389243603 2.33440876007
    }
    <Vertex> 3 {
      -1.00287950039 -0.961389422417 2.33440899849
    }
  }
  <Polygon> {
    <Normal> { -0.000000 -0.000000 -1.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Plane.002 } }
  }
}

That egg file appears to lack a bottom. Is it possible you’ve attached the model to the camera upside-down, or something like that?

Or, perhaps you scale the model larger when you parent it in, and the top of the sky is then outside the far plane? Or, conversely, that it’s too small and is within the near plane?

David

I didn’t put a bottom in the skybox as I thought that the ground would cover it so it wasn’t necessary.

I can see the top edges of the sides of the box so the top should be in view.

I’ll have a play around with it and see if I can come up with anything.