Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
ChrisM545's avatar
ChrisM545
Honored Guest
12 years ago

Unity SkyBox Solution

I had the same problem many people where having here, using the Example Oculus Sky box solution and having it clip large terrain at a distance.

The solution is to use use a shader that is set to "Queue"="Background" and ZWrite off for the sky box materials.

Here is the shader I modified:

Shader "Unlit/Vertex Color Multiply Background" {

Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
}

Category {
Tags { "Queue"="Background" }
ZWrite Off

Lighting Off
Fog {Mode Off}

BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}

SubShader {
Pass {

SetTexture [_MainTex] {
Combine texture
}

SetTexture [_MainTex] {
constantColor [_Color]
combine previous * constant
}
}
}
}
}


I use it by dragging the /Assets/Tuscany/Models/Prefabs/Skybox.prefab in to my scene, I replaced each material to use the above shader

I also created a script that makes the skybox copy my OVRCamera position but not its rotation:

using UnityEngine;
using System.Collections;

public class MatchPosition : MonoBehaviour {

public Transform ParentPosition;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
if(ParentPosition !=null)
this.transform.position = ParentPosition.position;
}
}


So this way you can make the sky box small, encompassing both cameras and it will draw first before the entire scene without updating the zbuffer. Also i set both cameras Clear Flags property to Depth Only, since the background will clear the color buffer, you save a little bit of render time.

4 Replies

Replies have been turned off for this discussion
  • yes it does. in the editor it may get confusing when you fly past the cube as its rendered out of order.
  • hi, i also have problems with the skybox. i can see the moon and clouds 2 times :(. my english is not sooo good so i can't understand how to fix it. can you please say what i should do? thanks

    pcProfie