JohnRobertPett
JohnRobertPett

Reputation: 1183

Skybox with alpha in Unity 3D with Cardboard

I have set up my Photoshop document as per the instructions in the Unity guidelines.

I realise this is for textures with alpha, but I have tried to create a skybox using the same technique. When I set up the scene using a texture, the alpha channel is preserved (so my PSD appears to be correct):

enter image description here

However, when I make the image a 'cubemap' and the shader is a 'skybox' accepting a 'cubemap' the alpha channel is lost:

enter image description here

I think that there are two options here, 1) Use the image as a texture and render the back face, 2) Find the reason it cannot render alpha in a 'skybox'.

Anyone had this gotcha or have some useful advice?

Upvotes: 0

Views: 1037

Answers (1)

JohnRobertPett
JohnRobertPett

Reputation: 1183

Unity 5.3.2 tested only

This script will help make all the meshes in your scene have their normals point inwards to your Cardboard camera. Create a custom C# script and put this inside.

void Start () {
        MeshFilter filter = GetComponent(typeof (MeshFilter)) as MeshFilter;

    if (filter != null) {
        Mesh mesh = filter.mesh;

        Vector3[] normals = mesh.normals;
        for (int i=0;i<normals.Length;i++)
            normals[i] = -normals[i];
        mesh.normals = normals;

        for (int m=0;m<mesh.subMeshCount;m++)
        {
            int[] triangles = mesh.GetTriangles(m);
            for (int i=0;i<triangles.Length;i+=3)
            {
                int temp = triangles[i + 0];
                triangles[i + 0] = triangles[i + 1];
                triangles[i + 1] = temp;
            }
            mesh.SetTriangles(triangles, m);
        }
    }
}

Upvotes: 0

Related Questions