Skybox

Hello everyone…

I want to ask you how do you do a skybox,

Do you model a giant cube in a modeler then export it?..

Or do you get this through some engine’s code?

I tried to do it in blender, scaling it too much, but in panda engine the cube is some small… not emulate well a sky…

thanks.

Cube size is irrelevant, as is the size of the scene you render onto the cube. The trick is to render the cube before everything else in the scene without depth testing or updating, with the cube centred at the camera - that way when the rest of the scene is rendered it will appear in front of the cube map. I just used the search function of this forum to get https://discourse.panda3d.org/viewtopic.php?t=3192&highlight=skybox, which has code that looks right in the 4th post. Also, there is a cubemap generation tutorial posted in general discussion right, now which might be of use.

As a side not if you want stuff in your skybox like mountains, clouds or planets i suggest creating a separate display region with its own root nodes and stuff.

If you want blender for skybox, try this:
discourse.panda3d.org/viewtopic.php?t=5959

It comes with blender template. You just make (or download) the scene, activate each camera, render, save…repeat 6 times. Then you have a perfect skybox. Can do it in 2 minutes.

Thank you you three…

I tried thought code, but something wrong happens with blender mesh, it wont be texturized… i followed the solar system tutorial made by Shao Zhang and Phil Saltzman, all understood, but seems to be that i have the trouble with blender…

ClCheung, thanks for that tip, i’m going to check it out…

That tutorial serves too much for me… i have now the six images… but i dont know the code to apply them…

What should add to the script to get these image to work??

import direct.directbase.DirectStart

model0 = loader.loadModel("models/model0")
model0.reparentTo(render)

skybox = loader.loadCubeMap("images/skybox_1.jpg")

run()

Based into Panda3d’s Manual, there is a CubeMap section, that i couldn’t understand very well… the skybox variable in the code i just typed is a wrong syntax, what could be the right way to script 6 images for a cubemap…?

Thanks !!

To load a cubemap, the syntax is:

tex = loader.loadCubeMap(‘cubemap_#.png’)

But if you just want a skybox, you don’t need a cubemap.
I use cubemap only for a shader, usually.

If you already have 6 skybox image, you can just load the model with that 6 images. e.g. the model I copied from another example:

<CoordinateSystem> { Z-up }

<Comment> { "Egg laid by Chicken for Blender vR44" }

<Texture> t_north.png {
  "t_north.png"
  <Scalar> wrap    { CLAMP }
  <Scalar> magfilter { BILINEAR }
  <Scalar> uv-name { UVTex }
  <Scalar> envtype { modulate }
}
<Texture> t_south.png {
  "t_south.png"
  <Scalar> wrap    { CLAMP }
  <Scalar> magfilter { BILINEAR }
  <Scalar> uv-name { UVTex }
  <Scalar> envtype { modulate }
}
<Texture> t_up.png {
  "t_up.png"
  <Scalar> wrap    { CLAMP }
  <Scalar> magfilter { BILINEAR }
  <Scalar> uv-name { UVTex }
  <Scalar> envtype { modulate }
}
<Texture> t_east.png {
  "t_east.png"
  <Scalar> wrap    { CLAMP }
  <Scalar> magfilter { BILINEAR }
  <Scalar> uv-name { UVTex }
  <Scalar> envtype { modulate }
}
<Texture> t_west.png {
  "t_west.png"
  <Scalar> wrap    { CLAMP }
  <Scalar> magfilter { BILINEAR }
  <Scalar> uv-name { UVTex }
  <Scalar> envtype { modulate }
}
<Texture> down.png {
  "down.png"
  <Scalar> wrap    { CLAMP }
  <Scalar> magfilter { BILINEAR }
  <Scalar> uv-name { UVTex }
  <Scalar> envtype { modulate }
}
<Group> Cube {
  <VertexPool> Cube {
    <Vertex> 0 {
      1.0 0.999999940395 -1.0
      <UV> UVTex { 1.000000 1.000000 }
    }
    <Vertex> 1 {
      -0.999999642372 1.00000035763 -1.0
      <UV> UVTex { 1.000000 0.000000 }
    }
    <Vertex> 2 {
      -1.00000011921 -0.999999821186 -1.0
      <UV> UVTex { 0.000000 0.000000 }
    }
    <Vertex> 3 {
      1.0 -1.0 -1.0
      <UV> UVTex { 0.000000 1.000000 }
    }
    <Vertex> 4 {
      1.00000047684 0.999999463558 1.0
      <UV> UVTex { 1.000000 0.000000 }
    }
    <Vertex> 5 {
      0.999999344349 -1.00000059605 1.0
      <UV> UVTex { 1.000000 1.000000 }
    }
    <Vertex> 6 {
      -1.00000035763 -0.999999642372 1.0
      <UV> UVTex { 0.000000 1.000000 }
    }
    <Vertex> 7 {
      -0.999999940395 1.0 1.0
      <UV> UVTex { 0.000000 0.000000 }
    }
    <Vertex> 8 {
      1.0 0.999999940395 -1.0
      <UV> UVTex { 0.000000 0.000000 }
    }
    <Vertex> 9 {
      1.0 -1.0 -1.0
      <UV> UVTex { 1.000000 0.000000 }
    }
    <Vertex> 10 {
      0.999999344349 -1.00000059605 1.0
      <UV> UVTex { 1.000000 1.000000 }
    }
    <Vertex> 11 {
      1.00000047684 0.999999463558 1.0
      <UV> UVTex { 0.000000 1.000000 }
    }
    <Vertex> 12 {
      1.0 -1.0 -1.0
      <UV> UVTex { 0.000000 0.000000 }
    }
    <Vertex> 13 {
      -1.00000011921 -0.999999821186 -1.0
      <UV> UVTex { 1.000000 0.000000 }
    }
    <Vertex> 14 {
      -1.00000035763 -0.999999642372 1.0
      <UV> UVTex { 1.000000 1.000000 }
    }
    <Vertex> 15 {
      0.999999344349 -1.00000059605 1.0
      <UV> UVTex { 0.000000 1.000000 }
    }
    <Vertex> 16 {
      -1.00000011921 -0.999999821186 -1.0
      <UV> UVTex { 0.000000 0.000000 }
    }
    <Vertex> 17 {
      -0.999999642372 1.00000035763 -1.0
      <UV> UVTex { 1.000000 0.000000 }
    }
    <Vertex> 18 {
      -0.999999940395 1.0 1.0
      <UV> UVTex { 1.000000 1.000000 }
    }
    <Vertex> 19 {
      -1.00000035763 -0.999999642372 1.0
      <UV> UVTex { 0.000000 1.000000 }
    }
    <Vertex> 20 {
      -0.999999642372 1.00000035763 -1.0
      <UV> UVTex { 0.000000 0.000000 }
    }
    <Vertex> 21 {
      1.0 0.999999940395 -1.0
      <UV> UVTex { 1.000000 0.000000 }
    }
    <Vertex> 22 {
      1.00000047684 0.999999463558 1.0
      <UV> UVTex { 1.000000 1.000000 }
    }
    <Vertex> 23 {
      -0.999999940395 1.0 1.0
      <UV> UVTex { 0.000000 1.000000 }
    }
  }
  <Polygon> {
    <TRef> { down.png }
    <Normal> { 0.000000 0.000000 1.000000 }
    <VertexRef> { 0 1 2 3 <Ref> { Cube } }
  }
  <Polygon> {
    <TRef> { t_up.png }
    <Normal> { 0.000000 0.000000 -1.000000 }
    <VertexRef> { 4 5 6 7 <Ref> { Cube } }
  }
  <Polygon> {
    <TRef> { t_east.png }
    <Normal> { -1.000000 0.000000 -0.000000 }
    <VertexRef> { 8 9 10 11 <Ref> { Cube } }
  }
  <Polygon> {
    <TRef> { t_south.png }
    <Normal> { 0.000000 1.000000 0.000000 }
    <VertexRef> { 12 13 14 15 <Ref> { Cube } }
  }
  <Polygon> {
    <TRef> { t_west.png }
    <Normal> { 1.000000 -0.000000 0.000000 }
    <VertexRef> { 16 17 18 19 <Ref> { Cube } }
  }
  <Polygon> {
    <TRef> { t_north.png }
    <Normal> { -0.000000 -1.000000 -0.000000 }
    <VertexRef> { 20 21 22 23 <Ref> { Cube } }
  }
}

To load it:

        skybox = loader.loadModel(skyboxfile)
        skybox.setScale(512)
        skybox.setBin('background', 1)
        skybox.setDepthWrite(0)
        skybox.setLightOff()
        skybox.reparentTo(render)

i saved the xml code as space.egg, renamed the contents image name files (into egg) to the existent ones… and success …

Skybox is visible now, its works good and looks fine !

A question… : Its looks like camera can reach the end of skybox and cross over it, (because skybox is a model).

It is possible to parent camera with skybox? so player never will get cross over the skybox… certainly, the camera moves with skybox at the same time… you can imagine that will made a perfect skybox…

If not possible, make the spaceshuttle very slow and tiny could be a solution…

Thank you !

I usually do it by adding a task, set the position of the skybox to the position of camera. May be reparent the skybox to camera node also do the work. Try it and let us know !

Hi Cheung,

I tried to do parent skybox with the camera, the result was the skybox does not won’t to move, just the spaceship… now i think it, its logic that happened, since while the camera rotate, rotate the skybox too, so we are going to see for ever the front of the skybox,

i guess there is a difference between cubemaps and skybox, skybox is a model right?, a cubemap is a permanent image that you never will reach or touch, for the space maybe better to do a cubemap, for a fighting game skybox is nice,…

The technic you teach me is very useful, but the problem when the player’s ship moves, the star’s images lose resolution…

Just let me put to you two examples in video… soon i’m going to upload… and will let’s opine about it :slight_smile:

Thanks !

you can try to use the compass effect to set the rotatino of your skybox. or just use a task which sets the skybox rotation to 0,0,0 each frame.

Hi Thomas, try a task should be a solution, but do you mean the skybox must be parent to the cam? or like a simple model?..

Here i let the video :

youtube.com/watch?v=3Gh4QZblREU

See and judge it please, note the background on each one.
I like to get like 2nd type ogre 3d skybox, just see that it does not move.

You both are agree with task, should be this well scripted ?

 def SkyboxReset(task):

        space.setPos(0,0,0)
        space.setHpr(0,0,0)
        return Task.cont

you can do it both ways.
either reparent the skybox to the camera and use a task to do a

skybox.setHpr(render,0,0,0)

or you do not reparent the skybox to to the camera (but to render) and do

skybox.setPos(base.camera,0,0,0)

May be you can take a look on how the skybox can be well positioned with Yarr demo or my demo:
discourse.panda3d.org/viewtopic.php?t=5915
In my demo, you can select “Ocean 2 - xxx”. Skybox is always positioned to the camera position (but not follow the rotation). It will have the proper effect that you want. It is not neccessary to use cubemap, as far as I know.

Thomas : The second way was very well, i think i should that way inside the planets !,

ClCheung : Nice !!!, “Skybox is always positioned to the camera position (but not follow the rotation)” that is just that i’m looking for (to the space scene), i’m going to check out your link post to view your framework program…

Thank you !