1
\$\begingroup\$

I have some trouble creating a sky box from a panoramic texture. Everything appears to be working. However there are some artifacts in one place. How do i get rid of them?

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ That's most likely because the texture you inserted in the shader's slot does not follow the panoramic image guidelines. \$\endgroup\$
    – user115399
    Commented Jan 15, 2019 at 15:05
  • \$\begingroup\$ The texture has similar pixels on left and right side, so there should not be any dotted line. It has dimensions: 2000x1000 pixels. \$\endgroup\$
    – hal
    Commented Jan 15, 2019 at 16:07

1 Answer 1

2
\$\begingroup\$

My approach is to generate an Inverted Sphere and put an Equirectangular texture (2:1 ratio) on it, it will work by default.

here is an editor script that will generate an inverted sphere for you:

using UnityEngine;
using UnityEditor;

public class InvertedSphere : EditorWindow
{
    private string st = "1.0";

[MenuItem ("GameObject/Create Other/Inverted Sphere...")]
public static void ShowWindow ()
{
    EditorWindow.GetWindow (typeof(InvertedSphere));
}

public void OnGUI ()
{
    GUILayout.Label ("Enter sphere size:");
    st = GUILayout.TextField (st);

    float f;
    if (!float.TryParse (st, out f))
        f = 1.0f;
    if (GUILayout.Button ("Create Inverted Sphere")) {
        CreateInvertedSphere (f);
    }
}

private void CreateInvertedSphere (float size)
{
    GameObject go = GameObject.CreatePrimitive (PrimitiveType.Sphere);
    MeshFilter mf = go.GetComponent<MeshFilter> ();
    Mesh mesh = mf.sharedMesh;

    GameObject goNew = new GameObject ();    
    goNew.name = "Inverted Sphere";
    MeshFilter mfNew = goNew.AddComponent<MeshFilter> ();
    mfNew.sharedMesh = new Mesh ();


    //Scale the vertices;
    Vector3[] vertices = mesh.vertices;
    for (int i = 0; i < vertices.Length; i++)
        vertices [i] = vertices [i] * size;
    mfNew.sharedMesh.vertices = vertices;

    // Reverse the triangles
    int[] triangles = mesh.triangles;
    for (int i = 0; i < triangles.Length; i += 3) {
        int t = triangles [i];
        triangles [i] = triangles [i + 2];
        triangles [i + 2] = t;
    }
    mfNew.sharedMesh.triangles = triangles;

    // Reverse the normals;
    Vector3[] normals = mesh.normals;
    for (int i = 0; i < normals.Length; i++)
        normals [i] = -normals [i];
    mfNew.sharedMesh.normals = normals;


    mfNew.sharedMesh.uv = mesh.uv;
    mfNew.sharedMesh.uv2 = mesh.uv2;
    mfNew.sharedMesh.RecalculateBounds ();

    // Add the same material that the original sphere used
    MeshRenderer mr = goNew.AddComponent<MeshRenderer> ();
    mr.sharedMaterial = go.GetComponent<Renderer>().sharedMaterial;

    DestroyImmediate (go);
}
}
\$\endgroup\$
1
  • \$\begingroup\$ It works. Thank You. But I am still curious how to fix skybox. \$\endgroup\$
    – hal
    Commented Jan 16, 2019 at 9:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .