Multiple 3d skyboxes

Discussion in 'Tutorials & Resources' started by monster860, Mar 11, 2018.

  1. monster860

    monster860 L1: Registered

    Messages:
    16
    Positive Ratings:
    7
    So, you want to create multiple 3d skyboxes? Well with some slight workarounds, you can! When valve was developing their source engine, they considered the idea of having multiple skyboxes. Some code is still left around for this functionality that we can take advantage of, with a bit of hammer trickery.

    1. The point_template entity

    The first thing you'll need to do is create a point_template somewhere in your map. Preferably, this should be somewhere in the "skybox" area of your map. Then, place a sky_camera in the exact same spot.

    ! Wherever you place a sky_camera entity, vvis will not optimize. Do not place it in the main playable area of your map.

    Open the entity properties of the sky_camera, turn off SmartEdit, click Add, and put in "targetname" for key and "current_camera" for targetname. Then, open the point_template entity you created, turn SmartEdit back on, and change it's name to "camera_template", set Template 1 to "current_camera" and make sure that under Flags, "Preserve entity names (Don't do name fixup) is checked.

    Now, this is the part where we get into major hack territory. Unfortunately, you can't actually use a point_template with a sky_camera normally, because sky_camera entities are preserved across map loads. point_template builds it's template on map load, and since the sky_camera isn't there on consequent map loads, it won't be able to use it. This means that in order to actually use a point_template with a sky_camera, it needs to be preserved across map loads as well.

    To do this, simply create (or use an existing one) logic_auto, and add an output with the output "OnNewGame", targeting the camera_template entity, and the input of "AddOutput" with a paremeter override of "classname sky_camera"

    Normally, once an entity is spawned, Source doesn't care about what the classname of an entity is. It will still work fine. However, it is used, when deciding upon map reload, whether to keep the entity or whether to discard it. Thus, changing the classname will cause it to be preserved across map loads as well. (You can use this trick to make other entities preserved across map loads as well if you want to.)

    2. The env_entity_maker

    Place an env_entity_maker wherever you want the origin of a skybox to be. Give it whatever name, set the template to be "camera_template" and leave all the flags unchecked.

    Add the following outputs:

    OnUser1 -> !self -> ForceSpawn
    OnUser1 -> current_camera -> Kill

    (both of them can have no delay)

    3. Wrapping it all up

    Now, whenever you do FireUser1 on any of the env_entity_maker entities, it will place the sky_camera at it's location, and it will instantly update to clients.

    For fun times, you can parent the env_entity_maker to a func_tracktrain, have it move around, and do FireUser1 with a logic_timer ever 0.02 seconds to have a skybox that moves around. This is the result of that.
     
    • Thanks Thanks x 5
    • Like Like x 2
  2. ficool2

    ficool2 L4: Comfortable Member

    Messages:
    158
    Positive Ratings:
    159
    I tried this and the skybox was inconsistent in updating, sometimes it updated instantly and other times it lagged for a few seconds. Nevertheless, pretty cool trick.
     
  3. Kill_the_Bug

    aa Kill_the_Bug

    Messages:
    1,802
    Positive Ratings:
    377
    Can you put in some pics to show it in action?
     
  4. Izotope

    aa Izotope Sourcerer

    Messages:
    672
    Positive Ratings:
    698
    I just tried this and the skybox change works fine, however it doesn't seem to load the first one at the map start, so I start with no 3d skybox.
     
  5. monster860

    monster860 L1: Registered

    Messages:
    16
    Positive Ratings:
    7
    I mean you really ought to be doing the skybox change *on* map start. Otherwise it might remember the wrong skybox across a load.
     
  6. Izotope

    aa Izotope Sourcerer

    Messages:
    672
    Positive Ratings:
    698
    Wasn't mentioned in the above tutorial, though :3
    I'll try more of this later

    EDIT:
    Made it so it picks the default sky at the mapstart and now I can flawlessly alternate between skies.
    [​IMG]
     
    • Like Like x 1
    Last edited: Mar 11, 2018
  7. Mince

    Mince L1: Registered

    Messages:
    4
    Positive Ratings:
    0
    It should be noted that when you kill the active sky_camera and spawn the new one in, the outputs have to be entered in exactly as specified in the article, with the same delay for both outputs. Adding a delay between the killing the camera and spawning a new one (e.g. 0.01) will instantly crash the game. So you have to rely on Hammer's last to first ordering for outputs with the same delay instead of adding a small delay yourself. This threw me for a loop for a bit trying to figure out why my game kept crashing.
     
  8. monster860

    monster860 L1: Registered

    Messages:
    16
    Positive Ratings:
    7
    Yeah, deleting a sky_camera without replacing it is a recipe for a game crash. Although if memory serves me right, it shouldn't be a problem to create a sky camera and then kill the old one, it's just that the way this particular tutorial is setup doesn't allow that to happen.