Log On
     
 





Tutorial: Sky Portals

Part 1

Skies give your level a sense of space and place. You can use sky portals to tell the engine where to show sky in your level, and use sky boxes  to define what the sky looks like. You may be familiar with games already using this concept, such as FAKK, Alice, and RTCW.

You should already be familiar with normal skybox's as they are drawn with shaders. If you've ever noclipped around in a map, you notice that as soon as you are outside the level, you see a Hall Of Mirrors effect which is turned off if you set "r_fastsky" to 1 at the console.

Well let me define loosely how the quake3 engine draws things and how it's interpreted by your video card. Your card is given a surface that is defined with a 'shader', or a simple instruction to draw an image based on coordinates. Even if this is a plain image and not referenced in any .shader file, it's still considered a shader. Shaders can have additional instructions on how to draw them, as you already know from reading the shader manual.

In each part of the player's view you have those shaders drawing up the HUD, which is technically an 'in your face' type overlay, then the world which stops the nothingness that is sealed up aka the void. Now what is to be drawn in this void is usually stopped at a  wall or floor with a normal shader reference, or a ceiling with a sky shader. This sky shader set tells the q3 engine to draw some passes, or an image if it's a skybox, instead of 'nothingness' or what was rendered in the video buffer last. (The buffer is also like a big temporary trashcan of what is to be drawn on the screen.) If you have ever seen the Hall Of Mirrors effect, you've noticed that the images shown in that HOM are the last referenced and defined shaders that passed into view, but since no other shaders are present it holds what was there last.

Now for portals. Portals are just segregated areas in the bsp based on VIS. Just try to think of them as 'areas to draw'. Even if you are not facing a part of one of these areas, your client is always thinking about everything that is inside the current portal. Portals are defined in VIS using structural brushes. Sounds in WFA are similar, as are target location entities; they are not considered active if they are not inside the player's current visible portal. If you have ever blocked an area, created a structural wall with just a caulk texture and have seen a HOM when looking directly at it, that is because what is behind that caulk brush is in a different portal (or even a null portal like the void). Since structural caulk is basically a solid nodraw 'instruction', nothing can be drawn behind it if the current portal has no data about what is in the other portal behind that wall. (If you have ever seen entities drawn through the sky, that is because of crap ID code anomalies but still must be considered when designing for  this new entity.)

If you can tell so far, we are basically trying to achieve creating a sky surface to purposefully become a hall of mirrors surface, just like caulk would create if used in place of the sky textures. But that leads into new considerations such as how to emit light and sun from a nodraw surface, which will be explained later.

So what is a sky portal then? A sky portal is a referenced defined portal that will always be drawn whenever the client has no textures and no portal references on a "nodraw" surface. There are certain circumstances (explained later) where this can be unwanted, so additionally an entity can be placed to tell the client to only draw that referenced portal if that entity is in the current player's portal. If not, then the sky portal can be drawn regardless of the existence of that entity.

The referenced portal is hinged with a new entity called a misc_portal_sky that becomes the new 'eye' for whatever is to be drawn when there otherwise would be a HOM.

 

Note the keys and spawnflags. The use_surface spawnflag is for only drawing what the origin of this entity 'sees' when a misc_portal_sky_surface entity is in the same portal (PVS) as the player. To figure out if the misc_portal_sky_surface is visible from any particular place, you can do one of 6 things.

  1. Make a little func_rotating brush at the sky and run around the map in r_Showtris, if you can see the func_rotating at every point you can see the sky then put the misc_portal_sky_surface there
     
  2. Use bobToolz's plugin, ent viewer in GTK after a full VIS compile with -saveprt in VIS
     
  3. Put a target_location ent and see if it shows up in the HUD while you can see the sky.
     
  4. Make a speaker with a wrong path to the wav and make sure you can hear it whenever you see the sky.
     
  5. Guess
     
  6. Use too many misc_portal_sky_surface entities and tempt the wrath of resources

Next, where to put this entity and some considerations.