- Home /
How would you render a seemlessly wrapping scene?
What I'm trying to achieve:
A 3D flying game in which there is a map, but if you fly off one end of the map, you appear at the other end and continue.
Now, technically achieving this is quite trivial; check player position, and if they fall outside the bounds, teleport them to the other side of the map.
The problem:
From the players perspective this sucks.
You fly to the end of the map and see an empty gray void beyond it... and when you try to fly into it you're magically teleported.
What you want is to somehow render the 'other side' of the scene to the player, so the transition appears seemless.
The question is, how do you do that?
Approaches I've already tried:
1) Mirroring the actual scene
Totally a non-starter. Everything is wrong with this, it requires you to have multiple copies (up to 8) of all the content in the scene, mirrored in real time. This is not a solution.
2) A series of giant quads on the edge that render the 'other side' to the texture.
Works well, but you need many many cameras along each edge that render the scene in realtime to the quads.
Seems like you should be able to dynamically control which of these is active at any time, but if you stand right on the border and look down it you have to render many many of these quads.
Super. Slow.
3) Dynamically place a render-to-texture quad in front of the player camera that shows the 'other side'.
This solution is ideal, but it seems impossible to get the edges of the quad to be 'seemless'; it appears as a floating window into the otherwise empty void with obvious edges.
Remember that you must render both the 'local' area and the 'other side' when you hit the 'edge' of the scene.
So, any ideas?
I almost feel like the solution to this is like some kind of magical sky box shader, but I have no idea how I would write it...
Depending on your requirements, a cheap fix could be to surround the land with water, scaled quite large and when you hit the invisible edge on one side teleport player to the other
You mean like a real 3D world right, in which you can fly in all directions (x, y and z)?
The only thing I can think of would be working with 2 camera's.
The first camera is at the position of the airplane. this camera his clipping planes can be anything and clear flags set to depth only.
The second camera is a child of the first camera and is placed behind the first camera (the distance equal to the width/heigt/depth of the level). The important thing here is that the clipping planes are set manually. The near clipping plane should be placed depending on the airplane's forward distance to the edge of the level. If the distance is high, the near clipping plane will be equal to the far clipping plane, if the distance is short, the near clipping plane will be closer to the first camera's clipping plane.
You should abviously make sure that the second camera does not render the back of the airplane, and for consistency, I think it would be best if both far clipping planes are equal to each other, or perhaps even better, the distance between the near and far clipping planes of boh cameras combined shouldn't change over time.
Clear flags of the second camera can be skybox and the first camera should render on top of the second camera.
Once you reach the end, teleport the airplane to the other side and make sure you update the clipping planes accordingly. Basicallly before teleporting, almost everything is rendered by camera2 and after teleporting everything should be rendered by camera 1 again.
I haven't tested anything like this yet, so it could be flawed... But I think it might work as I see no reason why it shouldn't. The only problems I can see is when there are other airplanes flying on the edge of the level so that half of the model is outside it. The part that is outside the level then could get clipped.
EDIT:
Now that I think about it, this does cause some problems. Forget the parenting of the camera's :D you would have to claculate the position of the second camera in a different way, so that it is always on the other side of the map and mirroring the rotation of the first camera otherwise you could get a weird effect if flying towards the edge under an angle...
Answer by astorga · Sep 10, 2015 at 01:15 PM
I would suggest you to do the teleport thing, but away from the end of the world, so the player would not see the "void".
You can also repeat the world. Just use a prefab. Also, you probably won't need more than 4 instances of the world at the same time (worst case is in the corners of the world, unless your world is small enough), so you should reposition world instances accordingly.
Also, don't let the player go too far from the origin (and I mean really far) because rendering issues will occur.