How do I make a skybox?

Hello,

I am creating a space game for my computer science project at college and I read that using a technique called a skybox can make the 3D world seem a lot bigger than it actually is.

I know the fundamentals of python but I am an absolute beginner to panda3D. I have read different things on the internet to no success and now I am completely clueless on where to even begin with creating a skybox.

Is making a skybox a bit too out of my league for a beginner? Or is it something I can definitely do?

Hope some of you can help!

1 Like

Welcome to the forum :smile:

A skybox is 100% something you can accomplish. Effectively to create a skybox we want a 3d cube with a texture on each face there are lots of premade ones but you can also make one pretty easily. Once we have a 3d model creating one in Panda3D is simple.

# Load the skybox
self.skybox = loader.loadModel("skybox/name_of_your_skybox")
self.skybox.setScale(2000)
self.skybox.reparentTo(render)
self.skybox.setShaderOff()
self.skybox.setBin('background', 0)
self.skybox.setDepthWrite(0)
self.skybox.setLightOff()

What the above does is make it so the box has no depth and will be unaffected by any lights we’ve . Finally setBin helps us set when a model will be rendered and so any models in background will be the first ones drawn. Combining all of this will create a skybox.

Code is from this post.

If you need any additional help feel free to ask. :smile:

1 Like

I just wanted to through out that you can also make skyboxes using displayRegions, which is useful if you want to have visual effects like a much greater fov on the skybox than the regular world, which is what some other engines use as their definition of “skybox”.

skyBox = loader.loadModel('skyBoxes/skybox')

base.camNode.get_display_region(0).set_sort(1)#ensure the skybox display region is behind
viewSky = base.win.make_display_region(0, 1, 0, 1)
viewSky.set_sort(0)

lens = PerspectiveLens()
#do some lens manipulation here (fov, etc.)
skyCamNode = Camera('skybox camera', orthoLens)
skyCam= skyBox.attach_new_node(newCam)
del skyCamNode
del lens

viewSky.setCamera(skyCam)
#Not shown: tasks to keep skyCam lined up with the player's camera.

of course, you would have to turn this on an off where relevant. Especially when the player is indoors, because then you’d be rendering a skybox they can’t even see!

1 Like

You can also just generate the cube at runtime if you don’t want to mess with a model. You can find an example of this here: https://github.com/Moguri/panda3d-simplepbr/blob/5eaaa64cc9d0409f414cc4f3443fc1c338fc8fc4/simplepbr/utils.py#L11

Feel free to just copy that function into your code. You can also install simplepbr to have access to that function too.

1 Like

Thank you very much!

This is just what I needed and I appreciate the detailed explanation as well as it really helps me to understand what is happening rather than blindly copying some code.

You’re amazing!

This is also great, Thank you so much!

I haven’t tried this method yet but I definitely will try soon and then see which skybox method I prefer.

I have read briefly about simplepbr and I have it installed. I will definitely experiment with this as well as models are somewhat of a minor hassle to get right. Textures even more of a pain!

Thanks a lot! You have been very helpful

You can try using cubemap.

https://docs.panda3d.org/1.10/python/programming/texturing/cube-maps

1 Like