Search Unity

Creating a SOURCE engine style 3D skybox

Discussion in 'Community Learning & Teaching' started by ufoRomantics, Sep 8, 2013.

  1. ufoRomantics

    ufoRomantics

    Joined:
    Aug 1, 2013
    Posts:
    4
    $t1.jpg

    So, this is a really simple technique, which uses Layers.

    What I going to show you is the same thing which is described here:
    http://docs.unity3d.com/Documentation/Manual/Cameras.html
    The idea is to render the sky first (on a different layer), then the world, etc..

    1. create your skybox: it can be anything, I've created a sphere with a sky texture,.
    2. Create a new Layer for the 3dskybox, then put your skybox model to this layer.
    3. create a new Camera, and move it into the exact middle of your 3d skybox, set its depth to 0, and set the culling mask to render the skybox layer only.
    4. Set your Main Camera Depth to 1,set the clear flags to: Depth, and set the culling mask to render everything except the skybox layer.
    5.add a script to your skybox camera which applies the main cameras rotation to itself.
    this one will do:
    void Update ()
    {
    transform.rotation = Camera.main.transform.rotation;
    }

    That's it:)

    a close up of my 3d skybox:
    $t2.jpg
     

    Attached Files:

    Last edited: Sep 8, 2013
  2. davidsirmons

    davidsirmons

    Joined:
    Mar 16, 2014
    Posts:
    190
    Tried this. It's promising, but the problem is that the cameras don't update in perfect unison. There is a horrible and unacceptable wobble of what is seen in the 2nd camera compared to the 1st camera. Does anyone know a way to solve this? Is this script forwarding the rotation of camera 1 to camera2, or are rotations being applied to both at once? The wobble I'm seeing tells me the 1st situation is what's happening.
     
  3. ufoRomantics

    ufoRomantics

    Joined:
    Aug 1, 2013
    Posts:
    4
    If I remember correctly,I think I just had to make sure that the rotation of the skybox camera should be the last thing to happen.
     
  4. davidsirmons

    davidsirmons

    Joined:
    Mar 16, 2014
    Posts:
    190
    Interesting. Where is that accessed?
     
  5. ufoRomantics

    ufoRomantics

    Joined:
    Aug 1, 2013
    Posts:
    4
    It is easy to make sure that it is the last thing to happen if you do the skybox camera rotation in the same script where you move/rotate your main camera.
     
  6. BDX777

    BDX777

    Joined:
    Dec 21, 2013
    Posts:
    14
    Very promising, do you have a miniature scene to showcase the perspectives moving around?
     
  7. Illuminism

    Illuminism

    Joined:
    Jul 30, 2015
    Posts:
    5
    I have made a full tutorial with a demonstration!

    Exactly, using LateUpdate() is how this is achieved!
     
    Kennai likes this.
  8. dozhwal

    dozhwal

    Joined:
    Aug 21, 2014
    Posts:
    59
    I put this here because it was hard to find it :)
    How to really make "Skyboxes meshes" like source engine (useful to make different landscapes view from different windows) :

    Code (CSharp):
    1. Shader "Custom/Window" {
    2.      Properties {
    3.          _Skybox ("Skybox Cubemap", Cube) = "" {}
    4.      }
    5.    
    6.      SubShader {
    7.          Tags { "RenderType"="Opaque" }
    8.          CGPROGRAM
    9.          #pragma surface surf Lambert noambient
    10.          #pragma target 3.0
    11.          samplerCUBE _Cube;
    12.          samplerCUBE _Skybox;
    13.          struct Input {
    14.              float3 viewDir;
    15.          };
    16.          void surf (Input IN, inout SurfaceOutput o) {
    17.              o.Emission = texCUBE (_Skybox, IN.viewDir);
    18.          }
    19.          ENDCG
    20.      }
    21. }
    Create a quad with a Material with this shader and a cubemap from a skybox, and you will see skybox through it.

    Source : https://answers.unity.com/questions/1253808/-making-a-window-that-you-can-see-nothing-but-sky.html
    PS : to make cubemap, you need to create a cubemap with Create/legacy/cubeMap
    PS2 : you can make cubemap easily in unity with : https://docs.unity3d.com/ScriptReference/Camera.RenderToCubemap.html
    PS3 : another way is to use a Render Depth Only Shader, but you will see only the skybox of the Camera. not the skybox you want to use that is maybe different from the skybox Camera.