SkyBox code doesn't work

Blitz3D Forums/Blitz3D Beginners Area/SkyBox code doesn't work

nx01(Posted 2004) [#1]
The various skybox codes that I have seen on the forums do not work with a first-person space simulation game. My camera is a child Entity of my spaceship. So the camera follows the ship around while it's flying. I have two enemy ships in space that don't move (as of now). My sky is an inverted sphere.

This does not work:
EntityOrder sphereSky, 1;
EntityParent sphereSky, camera;

The above has the effect of making the sky move with the main spaceship, so when I turn, the stars don't move. Also, the other two enemy ships disappear if I fly too far away from them, becuase they pass right through the other side of the sky.

I have also tried:
EntityOrder sphereSky, 10; higher z-buffer numbers
along with
EntityParent sphereSky, camera;
or
PositionEntity sphereSky, EntityX(camera),EntityY(camera),EntityZ(camera);
Which has no effect.

So If I don't make the sphere a child of the camera/ship, my ship can fly right through the sphere. When I make the sphere a child of the camera/ship, the stars don't move (relative to me) AND the other ships move out of the sphere when I fly too far away from them.

None of the above situations look/feel even close to realistic. Perhaps the skybox code works for games that are set on the ground (i.e. first person shooters), but not in an outer space simulation.

I asked Blitz programmers to create a special SkyBox entity, but all I got was the recommendations that I used above. And a few put off Blitz programmers who responded with things like, "There's no need for a skybox, becuase it's easy to implement."

If you think I'm incorrect then prove me wrong. Set up a simple situation like the one I described above and get the sky to work correctly and then post it. I can also email or post my code for anyone, who thinks they can make it work. It's a small program.

Thanks,


Gabriel(Posted 2004) [#2]
I agree with the people who said a special skybox entity is completely unnecessary and you've just demonstrated why. Because a skybox that suited people making one type of game wouldn't suit people making another type of game.

What's wrong with

PositionEntity sphereSky, EntityX(camera),EntityY(camera),EntityZ(camera)

Which has no effect is not very specific. What exactly does it not do that it should? As long as you don't parent it, it shouldn't rotate when the ship does.


Gabriel(Posted 2004) [#3]
Oh, if the camera is parented to the ship, you'll need

PositionEntity sphereSky, EntityX(camera,true),EntityY(camera,true),EntityZ(camera,true)


That'll make it use Global ( world ) coordinates instead of local ( relative to the ship ) ones.


nx01(Posted 2004) [#4]
Adding the true to the EntityX(camera, true) etc. Did help two of the three problems. First it solved the part about the main ship flying through the sphere. Second, the stars move relative to my main ship position.

However the third problem still exists. When I fly the main ship far away from the enemy ships, the enemy ships go right through the other side of the sky sphere. So they disappear. When I turn around and fly toward the direction of the enemy ships, I can see them reappear through the other side of the sky sphere.

This is not how a skybox is supposed to work. No matter what direction I fly in or for how long I go in that direction, nothing within the confines of the skybox should ever reach the edge of the skybox.

When you play 3D games, do objects in the scene ever go through the skybox, no matter how far away you move from them? No, so it still doesn't work correctly.


sswift(Posted 2004) [#5]
Make a second camera. Place it somewhere far away in the world. Put the skybox around that.

Set your main cameraclsmode to clear the zbuffer but not the color buffer.

Hide the first camera, show the second camera. Render the scene.
Hide the second camera, show the first camera. Render the scene.

Voila, perfect sky.


WolRon(Posted 2004) [#6]
Why the two cameras sswift? What's wrong with just one?


sswift(Posted 2004) [#7]
Well if you want to keep track of all your objects and hide everything in the level during the first render, then you could use a single camera.

The idea is to render the sky first and then clear all the zbuffer information so that nothing can appear behind the sky.

If entityorder is giving you trouble with your sky, then this method will always work. I use this method to render heads up displays, because there is the off chance someone might want to have a 3D object in the HUD and it does not suffer from the shaking some people reported on their HUDS when they tried parenting them to the camera and moved the camera far from the center of the world.


WolRon(Posted 2004) [#8]
I think I'm following you sswift but it sounds like you made a conflicting statement:

Make a second camera. Place it somewhere far away in the world. Put the skybox around that.

it does not suffer from the shaking some people reported on their HUDS when they tried parenting them to the camera and moved the camera far from the center of the world.



Damien Sturdy(Posted 2004) [#9]
Right, i understand sswifts idea- but why not use EntityZOrder!?


sswift(Posted 2004) [#10]
No, my statement isn't conflicting.

Some folks tried makign a space game, and they parented the hud to the camera. But when the camera MOVED AROUND while far from the center of the world, the children would shake because of 32bit floating point inaccuracy.

When I say stick the camera far from the center of the world, for most cases, 65536, 0, 0 would be just fine. That's not nearly as far away as these guys were sticking their camera. But even if it were, the camera is just sitting at one location, so even if the other objects were children of the camera, which they are not, they would not jiggle as they are not being moved by the camera.


sswift(Posted 2004) [#11]
"but why not use EntityZOrder!?"

I dunno. For the case of a skysphere, in general that should work fine, so long as the skysphere is small enough that it falls within the clipping radius of the camera, and you move it with the camera using positionentity. (Parenting it would make it rotate with the camera which would look wrong.)

I offered an alternative suggestion because the fellow above was syaing entityorder didn't do what he wanted.


"However the third problem still exists. When I fly the main ship far away from the enemy ships, the enemy ships go right through the other side of the sky sphere."

Have you considered making the skysphere so large that the enemies would be really tiny before they pass through the sphere? At some point the enemies are going to be clipped by your clipping plane on your camera, OR be too small to see. So if you make the sky sphere big enough then it won't matter if they pass through it at some point cause you won't be able to see it happening.


JKP(Posted 2004) [#12]
You could use fog with a high start distance and a slightly higher far distance. That way the entities will fade out as they approach the sky sphere. You would need to get the distances right, and you would also need to disable fog for the sky sphere.


TomToad(Posted 2004) [#13]
nx01, When I made a skybox, it was only a couple of units bigger than the camera. Nothing disappeared even though I know objects were outside of the box. EntityOrder makes sure the skybox is drawn before anything else is, so it will always appear behind. You sure that the ships are just simply not disappearing beyond the camera's clipping plane? Try adjusting the camera range and see what happens.

Sswift, as for the jittering, I had the same problem. Turns out it was the collisions that were causing it. I'd move the entity, move the skybox, do an updateworld, then renderworld. What was happening was that my character would move, then the skybox, but updateworld would move the character again, leaving the skybox offset. I solved it by making sure I didn't move the skybox until right before renderworld.

nx01, I just happened to think, you using Entityorder on the ships? If so, you should only use EntityOrder on the skybox. When setting EntityOrder to anything other than 0 will disable z buffering on the entity, so objects will not be drawn as expected.


Defoc8(Posted 2004) [#14]
Ive been developing my own space game for a while now..
- all you need to do is ensure that you have set the
- camera range to a reasonable value, force the z-order
- rendering of skybox/sphere + position the skybox
- at the world coords of your camera...simple..

This is pretty much jst repitition of whats already been
said...but it should be quite easy to get working...

anyway - goodluck....