How to Make A 2D Skybox Texture from Scratch

Discussion in 'Tutorials & Resources' started by Mikroscopic, Sep 18, 2016.

  1. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    Today I’m going to teach you one of the methods I used to make a custom skybox from scratch, without just changing the brightness or saturation of an existing skybox texture. In order to do this, you’ll need to know a bit of the basics about using a 3d modeling program. I use Blender, but the process should be applicable to any program.

    What we will be doing is basically making a texture and mapping it to a sphere, then capturing the view of each side from within the sphere and saving it as a set of 6 images. This will provide us with the correct perspective for our skybox, so it doesn’t look like an obvious cube like this:

    [​IMG]

    You will need:
    • A 3D modeling program (like Blender)
    • VTFedit
    • Your Favorite Image Editor

    Setting up the Texture

    First we have to create the texture to map to our sphere. Open up Your Favorite Image Editor and create a new image that is 4096 pixels wide and 2048 pixels tall. Then, draw your sky. There are a few things to keep in mind:
    • The horizon will be in the middle of the image, so you can leave the lower half blank if you want (unless you’re making some sort of outer space skybox).
    • The texture needs to tile horizontally, or else there will be a very obvious seam in your skybox.
    • Don’t draw anything too close to the top or bottom of the image, or else it will become distorted when we map it to the sphere (I’ll go into other ways to do this later).
    [​IMG]

    Save your image as something like “sky_yoursky_spheremap”.

    Setting up the Scene in Blender

    If you’ve never used Blender before, here is a list of some basic controls.

    Blender will give you a default scene with a cube, a camera, and a light source. Press A to select everything and delete it. Then go to Add > Mesh > UV Sphere.

    [​IMG]

    With the sphere selected, press tab to go into edit mode. Then select Mesh > Normals > Flip Normals. This will make sure our texture is rendered on the inside of the sphere, and not the outside.

    [​IMG]

    On the panel on the right, click on the Material tab (the checkered sphere) and press the “+ New” button to add a new material.

    [​IMG]

    Scroll down to the Shading section and check “Shadeless”. This will make sure there will not be shadows cast on the inside of the sphere.

    [​IMG]

    Then click on the Texture tab (the checkered square) and press “+ New”. Scroll down to the Image section and press “Open” to load your image.

    [​IMG]

    Navigate to where you saved your image and select it. You should now see your image in the preview window. If you click on Viewport Shading in the bottom toolbar and select “Material”, you should be able to see the texture on the sphere.

    [​IMG]

    However, the texture probably isn’t mapped correctly. With the sphere selected, go into edit mode (you can toggle between edit mode and object mode by pressing tab). Then, on the numpad, press 5, then 1. The screen should now look like this:

    [​IMG]

    Press U, and select “Sphere Projection”. Things should now look a lot better.

    [​IMG]

    If the texture still seems a bit stretched or misaligned, you may need to tweak the UV map. Click on the cube icon in the bottom left corner and select “UV / Image editor”.

    [​IMG]

    Press “Open” on the bottom toolbar next to the folder icon, and find your image just like before. You should now see something like this:

    [​IMG]

    You can now adjust the map so it fits cleanly over the image. In this case I pressed G to slide it over a bit to the left.

    Note: If you want to have complex elements like clouds or planets in your skybox, I recommend making them separate meshes inside the sphere instead of drawing them as part of the sphere's texture. For example, if you want a layer of clouds directly overhead, create a flat plane inside the sphere and texture it with clouds. This will prevent them from becoming distorted when the texture is "pinched" at the top and bottom of the sphere. For the simple gradient in this example, however, it doesn't matter.

    Getting the Images

    Next we need to capture the view of each side. To do this, we’ll use a camera. In object mode, go to Add > Camera. In the panel on the right, change “Millimeters” to “Field of View”, set the field of view to 90, and set the size to 0.5.

    [​IMG]

    Next, go to this tab and make sure the resolution is set to 1024 x 1024.

    [​IMG]

    Press N to open up an extra panel. At the top you will see a section that says Rotation. Make sure X is set to 90, Y is 0, and Z is 0 (While you're at it, make sure the Location values are all set to 0).

    [​IMG]

    Then press F12 and like magic, Blender will show you what the camera sees. Press F3 to save the image somewhere. Name it “sky_yoursky_01ft” (Don't actually name it "yoursky"). The "ft" in this case means front.

    [​IMG]

    Click the icon in the bottom left to return to the 3D view. Repeat this process 3 more times, with the Z value set to 0, 90, 180, and 270. Name these images with the suffixes “lf”, “bk”, and “rt”. For the top image, set X to 180 and Z to 0. Name this one ending in “up”. The bottom image can be anything, as long as it’s 1024 x 1024 and ends in “dn”.

    Now we should have a nice set of 6 images like this:

    [​IMG]

    Making the Textures Usable

    Now we need to convert these images into vtfs and create vmts for them.

    Note: Ingame, the textures will get flipped around (for whatever reason). Therefore, you must mirror them in Your Favorite Image Editor before you convert them to vtfs.

    Open VTFedit and choose File > Import to open an image. Save it as a .vtf with the same name.

    [​IMG]

    Now go to Tools > Create VMT file. Change the entry for "Base Texture 1" to "skybox/(your texture)" and click create.

    Open up the new vmt and change the parameters to this:

    Code:
    "UnlitGeneric"
    {
        "$basetexture" "skybox/(your texture)"
        "$nofog" 1
        "$ignorez" 1
    }
    [​IMG]

    Repeat this for the other 5 textures, the only difference being the appropriate texture name in the "$basetexture" parameter.

    Now take all the vtfs and vmts and drop them in your tf/materials/skybox folder (or wherever you keep your skybox textures).

    And there you go! Your skybox should be ready to use in hammer and should show up ingame (as long as you packed your bsp correctly).

    [​IMG]
     
    • Thanks Thanks x 16
    • Like Like x 3
    Last edited: Oct 1, 2016
  2. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    • Thanks Thanks x 1
  3. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    Wonderful job
    Not only will I be able to use this
    But many others.
     
    • Like Like x 1
  4. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    I take it clouds/ other complex parts are added through a program like skypaint
     
  5. CriminalBunny

    aa CriminalBunny Lasers are just deadly rainbows

    Messages:
    277
    Positive Ratings:
    411
    I was expecting a Tatooine map at the end of the post
     
    • Agree Agree x 1
  6. Crowbar

    aa Crowbar perfektoberfest

    Messages:
    1,439
    Positive Ratings:
    1,186
    Guess you gotta make one now.
     
    • Agree Agree x 1
  7. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    The issue with clouds is that the top of the skybox texture will get distorted as it is "pinched" at the top of the sphere. I would recommend creating a bunch of flat plane meshes, placing them inside the sphere, and mapping a separate cloud texture to those.
     
  8. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    yeah I figured it out, this is a very good tutorial.
    I'm still having some problems with cameras.
    Every time I render it doesn't properly represent its view.
    It has this weird effect over it making it all wavy.
     
    Last edited: Oct 1, 2016
  9. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    Can I see a screenshot?
     
  10. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    sorry here you go!
    Capture.PNG
     
  11. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    Hmm, it's a bit hard to see what you mean. Can I see the full rendered image?
     
  12. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    The image on the side is the full rendered image. I can send you the .blend and the textures with it.
     
  13. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    Alright, I'll see if I can take a look at it.
     
  14. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    thanks!
     

    Attached Files:

  15. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    any luck?
     
  16. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    For me it looks like it almost renders perfectly fine, but somehow at the last second it changes to this. I can see you have a lot of settings that are different from mine, and I don't quite know what all of them are or if some of them might be affecting the render. But try selecting "Load factory settings" then copy and paste the objects into there and see if it works.

    Also I realize I should probably put something in the OP about setting the correct resolution.
     
    • Thanks Thanks x 1
  17. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    no luck
    I'm honestly really confused, can you repeat the render, this time go to the tabs below the new window and under and find the one that when you click on has "render view" as an option.
    Just so we first rule that its not just something with the camera.
     
  18. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    I'm really confused as well. When I go to render It starts loading what looks like the image you have

    [​IMG]

    But as soon as it finishes it turns into this

    [​IMG]

    This is very strange to me, I have no idea why this is happening. Is this what you are experiencing?
     
  19. The Letter Before A

    The Letter Before A Cool Idiot

    Messages:
    300
    Positive Ratings:
    119
    Exactly.
    Maybe ill do a test in a new file to see whats wrong
     
  20. Mikroscopic

    aa Mikroscopic

    Messages:
    604
    Positive Ratings:
    613
    Hold on, I think I figured it out. Go down to the bottom tab and change "Composite" to "RenderLayer".

    [​IMG]