Changing the environment

So now you are able to create simple scenes using primitive objects. But a scene is not only made up of objects. There are more things that belong to a complete scene. Some of them will be described now. This chapter is really easy, because Ultimate 3D does everything automatically. You just have to tell it what you want.


Ambient lighting

Ambient lighting is the light that is everywhere. If you look around in your room you'll probably notice that there's no place that's absolutely dark. Even if something is not directly lit there's always enough adventitious light to brighten it up a bit. Of course everything is actually lit by something else. Objects reflect light and that's what lights the objects that are not directly lit by light sources. But simulating this behavior would take awfully huge amounts of computing time. For that reason there's the ambient lighting.

Ambient lighting is the simplest kind of lighting one could imagine. Everything gets lit by it with the same intensity and the same color. For this reason ambient lighting is made up of only one color value. This color can be changed by the following function:

SetAmbient(
R,
G,
B
)

R, G, B
The new color of the ambient light. The values for these parameters have to be in the range from 0 to 255.

By default the ambient lighting has the color (128|128|128). So if you write SetAmbient(255,0,0) everything will glow red. If you write SetAmbient(0,0,0) all objects except for those that have an emissive material would be totally black. By changing the ambient lighting you can strongly influence the atmosphere of your game. You can switch between day and night or you can create an apocalyptic atmosphere by using red light.


Setting up 3D backgrounds

Another thing that's very important for the atmosphere is the background image. Ultimate 3D supports three different kinds of backgrounds. Currently you are using the first one a solid color. The background color can be changed by changing the values of the variables control.BG_r, control.BG_g and control.BG_b. You can give them values in the range from 0 to 255.

The second kind of background is called a sky sphere. In this case you have one 2D image that contains a 360 picture of the environment. This picture gets used as the texture for a sphere that surrounds the scene. The disadvantage of sky spheres is that you get strange distortions at the top. All degrees of latitude meet in one point there. That is not that pretty. But in most games it's usually not necessary to look straight up. So most of the time sky spheres are useful anyway.

But what about games where the background has to look good in all directions? The best example for this is a space shooter. Words like up and down have no meaning in space. For cases like this Ultimate 3D supports another kind of background that does not lead to any distortions: a sky cube. A sky cube is not made up of one 2D image, but six quadratic images that get put together into a cube. As with the sphere, the cube surrounds the whole scene. Creating the pictures required for sky cubes is more difficult than creating sphere maps. But the results are better indeed.

Now that you know which kinds of backgrounds are supported let's get to the practical realization. There's only one function to load backgrounds:

This function loads either a sphere map or six textures for a cube map depending on the parameter given.

LoadBackground(
File
)

File
You have to enter a string for this parameter. If the string contains only a file name, this file will be loaded and used as the texture for the sky sphere. If the file string contains a * sign this sign will be replaced by the words "Front", "Back", "Top", "Bottom", "Left" and "Right". So Ultimate 3D loads six different files. They will be used for a sky cube.

If you do not want to use a background anymore you can call UnloadBackground(). Then the solid color will be used again.


Setting up fog

Thick fog is rare in most parts of the world. In computer games it occurs more often. But actually there's almost always a little bit of fog. On rainy days everything that's far away gets gray and colorless. On really hot evenings everything that's far away has a very dark orange tone. So you can almost always use fog; usually it looks quite cool. It supports the impression of real depth. However, using too much fog will make people think you couldn't offer a higher visual range. In some cases this may actually be true. Then fog is the lesser of two evils. It's better than having everything just disappear when it gets too far away from the camera.

Setting up fog is not any more difficult than setting up a background picture. There's one function to enable it and one to disable it. Here's the one that enables it:

SetFog(
R,
G,
B,
StartDistance,
EndDistance
)

R, G, B
The fog color. The values for these variables have to be in the range from 0 to 255.

StartDistance, EndDistance
The distance values for the fog. Everything that's closer to the camera than StartDistance will not be influenced by the fog. Everything that's farther away from the camera than EndDistance will have the fog color. Everything in between these values Ultimate 3D will interpolate linearly.


If you want to disable fog simply call DisableFog().



© Christoph Peters. Some rights reserved.

Creative Commons License XHTML 1.0 Transitional