PGD Home

P-152: Virtual World Concept Update 114: Sky Spheres (and Water Spheres)

by on Apr.22, 2016, under Astral Realms, P-0, Software Engines, Spiritus Astrum

With my spherical terrain implementation hopefully nearing completion, I have begun thinking about the next steps in my virtual world project.

One of the problems that I will need to solve will be creating a realistic sky, or atmosphere. Most games use a simple skybox, which is basically just 6 (or 5, if the bottom is not rendered) images textured onto the inside of a cube. The entire game level then fits inside this cube. If the images are of a high enough resolution, the effect is seamless, and it is not possible to tell that the sky isn’t “real”.  It is also possible to add animated cloud layers, moving sun and moon objects, changing textures for different times of the day, etc, to improve realism.

This kind of approach wouldn’t work for a game with a traversable space environment, or for a game where it is possible to travel to space from the surface without a transition. This is simply because conventional skyboxes contain the entire playable world, ie, when you leave the planet and enter space, the skybox will still show clouds and blue sky.

The solution to this problem could actually be easier than I thought. What I could do is create a sphere around the planet, at the maximum distance that the atmosphere of that planet would reach. I could then apply a shader to this sphere, and pass it the position of the player.

Now, when the player is at the planets surface, I can generate a solid blue sky texture. I wouldn’t use a texture map, I would generate it in a similar way to, for example, the “scatter sky” object in stock T3D.

As the player ascends higher and higher into the atmosphere, all I need to do is change the colour of the procedurally generated texture, making it a lighter shade of blue, to simulate the density of the atmosphere decreasing. I would also animate the transparency of the atmosphere, so that the player can see more and more of the space background outside the sphere. By the time the player reaches the actual sphere object itself, the transparency would be set to 0, so they would not notice any visual artifacts as they pass through it and into space.

This should work very well. Some other advantages would be that at night, I can simply set the transparency to 0, and the player will be able to see through the atmosphere from the surface of the planet as well. I would also add features to the shader to simulate different light conditions, sunset, sunrise, midday, etc.

In addition, adding volumetric clouds to the atmosphere would significantly improve realism. Volumetric clouds are 3D, not flat 2D images, so the player will be able to pass through them as they ascend and descend through the atmosphere.

This is a very simple system, but I can’t think of any reason why it wouldn’t work. The only problem I can think of would be with creating a sphere of such a large size. If I scale the planet to a size comparable to a real-world planet, I will run into the famous “10k” problem, where 32-bit floating point numbers lose precision. I would likely also have issues creating a single sphere with a radius greater than 10k, although this could be solved in a similar way to the method I used with the terrain, and the other game objects.

I could try creating the sphere around the player, rather than around the planet. With a large enough radius, this shouldn’t be noticeable. I could also try creating a sphere from code, rather than spawning an actual object. The existing skybox code does this, and I believe, although I am not sure, this gives it essentially unlimited range, since it is not occupying a particular 3D-position in the world. I would have to look into it in more detail when I get to that stage.

Currently, I am working within the 10k limit, so this shouldn’t be a problem.

I will also need to think about adding Oceans to the game. This could be done in a very similar way, I would create a sphere of a certain radius (enough to cover some of the land in the world, but not all of it) and then texture it with an animated water shader. I could probable reuse most of the existing water plane code.

I would need to add collision for the water sphere however, to allow the player to interact with it in a realistic way, but this should be doable. I would also like to add more complex effects, like shoreline rendering, large storm waves, or water that behaves differently at different depths.

The collision issues is one I will need to spend more time on, for both the water and the terrain, I will make a separate post shortly about this.

 

Facebooktwitterredditpinterestlinkedinmail

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!