Ejemplo n.º 1
0
    void CreateSphere(Cubemap _texture, Vector3 pos)
    {
        GameObject go   = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        GameObject temp = new GameObject(_texture.ToString());

        spheres.Add(go.transform);
        go.transform.SetParent(temp.transform);
        Transform t = temp.GetComponent <Transform> ();

        t.localScale = Vector3.one * scale;
        MeshRenderer mr  = go.GetComponent <MeshRenderer> ();
        Material     mat = new Material(_shader);

        Cubemap tex = null;

        tex = new Cubemap(_texture.width, TextureFormat.ARGB32, false);
        Color[][] pixels = new Color[6][];
        if (!getPixel)
        {
            for (int i = 0; i < 6; i++)
            {
                pixels [i] = new Color[_texture.width * _texture.width];
                pixels [i] = _texture.GetPixels(cubemapFaces [i]);
                tex.SetPixels(pixels [i], cubemapFaces [i]);
            }
        }
        else
        {
            for (int ii = 0; ii < 6; ii++)
            {
                pixels [ii] = new Color[_texture.width * _texture.width];
                int i = 0;
                for (int y = 0; y < _texture.width; y++)
                {
                    for (int x = 0; x < _texture.width; x++)
                    {
                        pixels [ii] [i] = _texture.GetPixel(cubemapFaces [ii], x, y);
                        i++;
                    }
                }
                tex.SetPixels(pixels [ii], cubemapFaces [ii]);
            }
        }
        //tex.SetPixels (pixels);
        tex.Apply();
        LabelMaker.MakeLabel(_texture.name.ToString().Remove(0, 5), Color.white, t);
        tex.filterMode  = FilterMode.Point;
        mat.mainTexture = tex;
        mat.name        = _texture.name;
        go.name         = _texture.name;
        mr.material     = mat;
        tex.wrapMode    = TextureWrapMode.Clamp;
        tex.Apply();
        t.SetParent(transform);
        t.position = pos;
    }
Ejemplo n.º 2
0
    static int Apply(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            Cubemap obj = LuaScriptMgr.GetNetObject <Cubemap>(L, 1);
            obj.Apply();
            return(0);
        }
        else if (count == 2)
        {
            Cubemap obj  = LuaScriptMgr.GetNetObject <Cubemap>(L, 1);
            bool    arg0 = LuaScriptMgr.GetBoolean(L, 2);
            obj.Apply(arg0);
            return(0);
        }
        else if (count == 3)
        {
            Cubemap obj  = LuaScriptMgr.GetNetObject <Cubemap>(L, 1);
            bool    arg0 = LuaScriptMgr.GetBoolean(L, 2);
            bool    arg1 = LuaScriptMgr.GetBoolean(L, 3);
            obj.Apply(arg0, arg1);
            return(0);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: Cubemap.Apply");
        }

        return(0);
    }
Ejemplo n.º 3
0
    /*!
     * Add a reflection line with the specified Rotation on the specified face.
     *
     * \param cubemap The Cubemap to add to.
     * \param rotation Rotation of the reflection line
     * \param faces The Cubemap faces to add the line to.
     */

    public static void addReflectionlineToCubemap(Cubemap cubemap, float rotation, int lineWidth, params CubemapFace[] faces)
    {
        UnityDebug.assert(cubemap.width == cubemap.height, "Cubemap is not square!");

        foreach (CubemapFace face in faces)
        {
            var colors = cubemap.GetPixels(face);

            int middle = (cubemap.width / 2) - 1;

            var center = new int[] { middle, middle };

            var origStart = new int[] { middle, 0 };
            var newStart  = rotatePointAroundPoint2D(origStart, center, rotation);

            var origEnd = new int[] { middle, cubemap.height - 2 };
            var newEnd  = rotatePointAroundPoint2D(origEnd, center, rotation);

            LineDrawer.plotThickLineAA(newStart[0], newStart[1], newEnd[0], newEnd[1], lineWidth, delegate(int x, int y, float i) {
                colors[y * cubemap.width + (cubemap.width - 1 - x)] = new Color(i, i, i);
            });

            cubemap.SetPixels(colors, face);
        }

        if (faces.Length > 0)
        {
            cubemap.Apply();
        }
    }
Ejemplo n.º 4
0
    public void OnResetCubemap()
    {
        if (Index > 0)
        {
            return;
        }

        if (mCubemap == null)
        {
            mCubemap = new Cubemap(2, TextureFormat.RGB24, false);
        }

        Color[] xzPixels = new Color[4] {
            mEnvirment_MidColor, mEnvirment_MidColor, mEnvirment_MidColor, mEnvirment_MidColor
        };
        Color[] yPositivePixels = new Color[4] {
            mEnvirment_Skycolor, mEnvirment_Skycolor, mEnvirment_Skycolor, mEnvirment_Skycolor
        };
        Color[] yNavigatePixels = new Color[4] {
            mEnvirment_GroundColor, mEnvirment_GroundColor, mEnvirment_GroundColor, mEnvirment_GroundColor
        };

        mCubemap.SetPixels(xzPixels, CubemapFace.NegativeX, 0);
        mCubemap.SetPixels(xzPixels, CubemapFace.PositiveX, 0);
        mCubemap.SetPixels(xzPixels, CubemapFace.NegativeZ, 0);
        mCubemap.SetPixels(xzPixels, CubemapFace.PositiveZ, 0);

        mCubemap.SetPixels(yPositivePixels, CubemapFace.PositiveY, 0);
        mCubemap.SetPixels(yNavigatePixels, CubemapFace.NegativeY, 0);


        mCubemap.Apply();
    }
Ejemplo n.º 5
0
    IEnumerator Capture(Cubemap cubemap, CubemapFace face, Camera cam)
    {
        var       width    = Screen.width;
        var       height   = Screen.height;
        Texture2D tex      = new Texture2D(height, height, texFor, mipmap);
        int       cubeSize = cubemap.height;

        cam.transform.localRotation = RotationOf(face);

        yield return(new WaitForEndOfFrame());

        tex.ReadPixels(new Rect((width - height) / 2, 0, height, height), 0, 0);
        tex.Apply();
        tex = Scale(tex, cubeSize, cubeSize);

        Color cubeCol;

        for (int y = 0; y < cubeSize; y++)
        {
            for (int x = 0; x < cubeSize; x++)
            {
                cubeCol = tex.GetPixel(cubeSize + x, (cubeSize - 1) - y);
                if (Linear)
                {
                    cubeCol = cubeCol.linear;
                }
                cubemap.SetPixel(face, x, y, cubeCol);
            }
        }
        cubemap.Apply();
        DestroyImmediate(tex);
    }
Ejemplo n.º 6
0
    void ComputeEncodeSkyBox()
    {
        ComputeShader cs = Resources.Load <ComputeShader>("EncodeSkyBox");

        if (cs == null)
        {
            return;
        }

        int kanel = cs.FindKernel("CS_EncodeSkyBox");

        CubemapFace[] faces = new CubemapFace[]
        {
            CubemapFace.PositiveX,
            CubemapFace.NegativeX,
            CubemapFace.PositiveY,
            CubemapFace.NegativeY,
            CubemapFace.PositiveZ,
            CubemapFace.NegativeZ,
        };

        Cubemap clone = new Cubemap(mCubeSize, TextureFormat.RGBA32, false);

        for (int i = 0; i < faces.Length; ++i)
        {
            Color[] cols;
            CreateFace(cs, kanel, i, out cols);
            clone.SetPixels(cols, faces[i]);
        }

        clone.Apply(false, !mOutputTextureReadable);
        SaveTexture <Cubemap>(clone, GetPath());
    }
Ejemplo n.º 7
0
    void TestGenerateSpecCubemap()
    {
        float dv = 1.0f / m_Cubemap.height;
        float du = 1.0f / m_Cubemap.width;

        float uoffs = 0.5f / m_Cubemap.width;
        float voffs = 0.5f / m_Cubemap.height;

        m_DbgLightDir0.Normalize();
        m_DbgLightDir1.Normalize();

        foreach (CubemapFace face in CubemapFace.GetValues(typeof(CubemapFace)))
        {
            for (int y = 0; y < m_Cubemap.height; y++)
            {
                float v = y * dv + voffs;

                for (int x = 0; x < m_Cubemap.width; x++)
                {
                    float   u   = x * du + uoffs;
                    Vector3 dir = UVToDir(u, v, face);

                    dir.Normalize();

                    m_Cubemap.SetPixel(face, x, y, EvalSpecLighting(dir));
                }
            }
        }

        m_Cubemap.Apply();
    }
Ejemplo n.º 8
0
    IEnumerator CaptureImportanceSample(Cubemap cubemap, CubemapFace face, Camera cam, int mip)
    {
        var       width  = Screen.width;
        var       height = Screen.height;
        Texture2D tex    = new Texture2D(height, height, TextureFormat.ARGB32, false);

        cam.transform.localRotation = Rotation(face);

        yield return(new WaitForEndOfFrame());

        tex.ReadPixels(new Rect((width - height) / 2, 0, height, height), 0, 0);
        tex.Apply();

        int cubeSize = Mathf.Max(1, cubemap.width >> mip);

        tex = Resize(tex, cubeSize, cubeSize, true);

        Color[] tempCol = tex.GetPixels();

        cubemap.SetPixels(tempCol, face, mip);

        cubemap.Apply(false);

        DestroyImmediate(tex);
    }
Ejemplo n.º 9
0
    IEnumerator CreateCubemap(CubePoint point)
    {
        GameObject camObject = new GameObject("CubemapCamera");

        camObject.transform.parent        = point.transform;
        camObject.transform.localPosition = Vector3.zero;
        Camera cam = (Camera)camObject.AddComponent(typeof(Camera));

        cam.fieldOfView   = 90;
        cam.depth         = 10;
        cam.nearClipPlane = 0.001f;
        cam.farClipPlane  = 1000.0f;

        Cubemap cubemap = new Cubemap(this.size, this.textureFormat, this.mipmap);

        //yield return new WaitForEndOfFrame();
        yield return(StartCoroutine(Snapshot(cubemap, CubemapFace.PositiveZ, cam)));

        yield return(StartCoroutine(Snapshot(cubemap, CubemapFace.PositiveX, cam)));

        yield return(StartCoroutine(Snapshot(cubemap, CubemapFace.NegativeX, cam)));

        yield return(StartCoroutine(Snapshot(cubemap, CubemapFace.NegativeZ, cam)));

        yield return(StartCoroutine(Snapshot(cubemap, CubemapFace.PositiveY, cam)));

        yield return(StartCoroutine(Snapshot(cubemap, CubemapFace.NegativeY, cam)));

        cubemap.Apply(mipmap);
        AssetDatabase.CreateAsset(cubemap, "Assets/AssetStore/" + path + "/" + point.cubePointName + ".cubemap");
        AssetDatabase.SaveAssets();

        Destroy(camObject);
    }
Ejemplo n.º 10
0
        public void capture(ref Cubemap targetCube, Transform at, bool HDR)
        {
            if (targetCube == null)
            {
                return;
            }
            GameObject go = new GameObject("_temp_probe");

            go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
            go.SetActive(true);
            Camera cam = go.AddComponent <Camera>();

            if (at != null)
            {
                go.transform.position = at.position;
            }
            if (HDR)
            {
                Shader.EnableKeyword("MARMO_RGBM");
                Shader.DisableKeyword("MARMO_RGBA");
                Shader.SetGlobalFloat("_GlowStrength", 0f);
                Shader.SetGlobalFloat("_EmissionLM", 0f);
                cam.SetReplacementShader(Shader.Find("Hidden/Marmoset/RGBM Replacement"), "RenderType");
            }
            cam.RenderToCubemap(targetCube);
            targetCube.Apply(false);
            if (HDR)
            {
                cam.ResetReplacementShader();
                Shader.DisableKeyword("MARMO_RGBM");
                Shader.EnableKeyword("MARMO_RGBA");
            }
            GameObject.DestroyImmediate(go);
        }
Ejemplo n.º 11
0
    private Cubemap mapToCubemap(float[,,] map, int size)
    {
        Color[][] colors = new Color[6][];

        for (int m = 0; m < 6; m++)
        {
            colors[m] = new Color[size * size];
            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    colors[m][x + y * size] = Color.Lerp(Color.black, Color.white, (map[m, x, y] + 1.0f) / 2.0f);
                }
            }
        }

        Cubemap cubemap = new Cubemap(size, TextureFormat.RGB24, true);

        cubemap.SetPixels(colors[0], CubemapFace.PositiveX);
        cubemap.SetPixels(colors[1], CubemapFace.NegativeX);
        cubemap.SetPixels(colors[2], CubemapFace.PositiveY);
        cubemap.SetPixels(colors[3], CubemapFace.NegativeY);
        cubemap.SetPixels(colors[4], CubemapFace.PositiveZ);
        cubemap.SetPixels(colors[5], CubemapFace.NegativeZ);
        cubemap.Apply();

        cubemap.name       = "Perlin Noise Cubemap";
        cubemap.wrapMode   = TextureWrapMode.Clamp;
        cubemap.filterMode = FilterMode.Point;

        return(cubemap);
    }
Ejemplo n.º 12
0
    void Awake()
    {
        cam = gameObject.GetComponent <Camera>();
        cam.depthTextureMode |= DepthTextureMode.Depth | DepthTextureMode.MotionVectors;

        ssrtMaterial = new Material(Shader.Find("Hidden/SSRT"));

        mesh          = new Mesh();
        mesh.vertices = new Vector3[]
        {
            new Vector3(-1, -1, 1),
            new Vector3(-1, 1, 1),
            new Vector3(1, 1, 1),
            new Vector3(1, -1, 1)
        };
        mesh.uv = new Vector2[]
        {
            new Vector2(0, 1),
            new Vector2(0, 0),
            new Vector2(1, 0),
            new Vector2(1, 1)
        };
        mesh.SetIndices(new int[] { 0, 1, 2, 3 }, MeshTopology.Quads, 0);

        if (fallbackMethod == FallbackMethod.DynamicCubemap)
        {
            cubemapFallback = new Cubemap(32, TextureFormat.RGB24, true);
            cubemapFallback.Apply(true);
        }
    }
Ejemplo n.º 13
0
        void AddToCubemap(StreetView.Face face, Texture2D tex)
        {
            if (cubemap == null)
                cubemap = new Cubemap(downloader.options.resolution, TextureFormat.ARGB32, false);

            CubemapFace cubemapFace = CubemapFace.PositiveX;
            switch (face) {
                case StreetView.Face.Up:
                    cubemapFace = CubemapFace.NegativeY;
                    break;
                case StreetView.Face.Down:
                    cubemapFace = CubemapFace.PositiveY;
                    break;
                case StreetView.Face.Front:
                    cubemapFace = CubemapFace.PositiveZ;
                    break;
                case StreetView.Face.Back:
                    cubemapFace = CubemapFace.NegativeZ;
                    break;
                case StreetView.Face.Left:
                    cubemapFace = CubemapFace.NegativeX;
                    break;
                case StreetView.Face.Right:
                    cubemapFace = CubemapFace.PositiveX;
                    break;
            }

            cubemap.SetPixels(tex.GetPixels(), cubemapFace);
            cubemap.Apply();
            material.SetTexture("_Cubemap", cubemap);
            targetRenderer.material = material;
        }
Ejemplo n.º 14
0
    void SetCookie()
    {
        float y = 0.0F;

        while (y < noise.height)
        {
            float x = 0.0F;
            while (x < noise.width)
            {
                //Perlin Noise
                float xCoord = x_org + x / noise.width * scale;
                float yCoord = y_org + y / noise.height * scale;
                float sample = Mathf.PerlinNoise(xCoord, yCoord);

                sample += brightness;
                pix[(int)y * noise.width + (int)x] = new Color(sample, sample, sample, sample);
                x++;
            }
            y++;
        }

        x_org += speed;
        y_org += speed;

        noise.SetPixels(pix, CubemapFace.NegativeX);
//		noise.SetPixels(pix, CubemapFace.NegativeY);
        noise.SetPixels(pix, CubemapFace.NegativeZ);
        noise.SetPixels(pix, CubemapFace.PositiveX);
        noise.SetPixels(pix, CubemapFace.PositiveY);
        noise.SetPixels(pix, CubemapFace.PositiveZ);
        noise.Apply();
    }
Ejemplo n.º 15
0
    //--------------------------------------------------------------------------------------
    // Builds a normalizer cubemap, with the texels solid angle stored in the fourth component

    void BuildNormalizerSolidAngleCubemap(int a_Size, Cubemap a_Surface)
    {
	    //a_Size = a_Surface.width;
	    int iCubeFace, u, v;
	    Vector3 a_XYZ = new Vector3(0,0,0);
	    Color[] i_CubeMapColors = new Color[a_Size*a_Size];
	    //
	    float weight = 0.0f;
	    //iterate over cube faces
	    for(iCubeFace=0; iCubeFace<6; iCubeFace++)
	    {
		    for(v=0; v< a_Size; v++)
		    {
			    for(u=0; u < a_Size; u++)
			    {
            	    // calc TexelToVect in a_XYZ
				    a_XYZ = TexelToVect(iCubeFace, (float)u, (float)v, a_Size);
				    // calc weight
        		    weight = TexelCoordSolidAngle(iCubeFace, (float)u, (float)v, a_Size);
				    // Compress a_XYZ to fit into Color
				    i_CubeMapColors[v * a_Size + u] = new Color ((a_XYZ[0]+1.0f)/2.0f, (a_XYZ[1]+1.0f)/2.0f, (a_XYZ[2]+1.0f)/2.0f, weight);
			    }         
		    }
		    // set CubemapFace
		    a_Surface.SetPixels(i_CubeMapColors, (CubemapFace)iCubeFace);
	    }
	    // set cubeMap
	    a_Surface.Apply(true);
	    // Debug.Log ("BuildNormalizerSolidAngleCubemap finished");
    }
Ejemplo n.º 16
0
    private Cubemap InterpolateTexture(Cubemap tex0, Cubemap tex1, Cubemap tex2, Vector3 weight)
    {
        Cubemap result = new Cubemap(256, TextureFormat.Alpha8, true);

        foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace)))
        {
            if (face == CubemapFace.Unknown)
            {
                continue;
            }

            for (int y = 0; y < 256; ++y)
            {
                for (int x = 0; x < 256; ++x)
                {
                    Color c0 = tex0.GetPixel(face, x, y);
                    Color c1 = tex1.GetPixel(face, x, y);
                    Color c2 = tex2.GetPixel(face, x, y);

                    Color color = weight.x * c0 + weight.y * c1 + weight.z * c2;

                    result.SetPixel(face, x, y, color);
                }
            }
        }

        result.Apply();
        return(result);
    }
Ejemplo n.º 17
0
    public static void DirectionalCubemap()
    {
        int     faceSize = 8;
        Cubemap cube     = new Cubemap(faceSize, TextureFormat.RGB24, false);

        // For each side
        foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace)))
        {
            Color[] pixels = new Color[faceSize * faceSize];
            for (int x = 0; x < faceSize; ++x)
            {
                for (int y = 0; y < faceSize; ++y)
                {
                    int     index = x + y * faceSize;
                    Vector3 dir   = Utils.Cubemap.CubemapDirection(face,
                                                                   (x + 0.5f) / (float)faceSize - 0.5f,
                                                                   (y + 0.5f) / (float)faceSize - 0.5f);

                    pixels[index] = new Color(dir.x, dir.y, dir.z);
                }
            }

            cube.SetPixels(pixels, face);
            cube.Apply();
        }

        AssetDatabase.CreateAsset(cube, "Assets/BiasedPhysics/DirectionalCubemap.cubemap");
        Debug.Log("Generated /BiasedPhysics/DirectionalCubemap.cubemap");
    }
Ejemplo n.º 18
0
        public static void clearCheckerCube(ref Cubemap cube)
        {
            Color gray0 = new Color(0.25f, 0.25f, 0.25f, 0.25f);
            Color gray1 = new Color(0.50f, 0.50f, 0.50f, 0.25f);

            Color[] c   = cube.GetPixels(CubemapFace.NegativeX);
            int     w   = cube.width;
            int     sqw = Mathf.Max(1, w / 4);          //width of square

            for (int face = 0; face < 6; ++face)
            {
                for (int x = 0; x < w; ++x)
                {
                    for (int y = 0; y < w; ++y)
                    {
                        if (((x / sqw) % 2) == ((y / sqw) % 2))
                        {
                            c[y * w + x] = gray0;
                        }
                        else
                        {
                            c[y * w + x] = gray1;
                        }
                    }
                }
                cube.SetPixels(c, (CubemapFace)face);
            }
            cube.Apply(true);
        }
Ejemplo n.º 19
0
    //Convert a RenderTexture to a Cubemap
    public static Cubemap RenderTextureToCubemap(RenderTexture input)
    {
        if (input.dimension != UnityEngine.Rendering.TextureDimension.Cube)
        {
            Debug.LogWarning("Input render texture dimension must be cube");
            return(null);
        }

        if (input.width != input.height)
        {
            Debug.LogWarning("Input render texture must be square");
            return(null);
        }

        Cubemap   output   = new Cubemap(input.width, ConvertFormat(input.format), false);
        Texture2D tmp_face = new Texture2D(input.width, input.height, output.format, false);

        RenderTexture active = RenderTexture.active;

        for (int face = 0; face < 6; ++face)
        {
            Graphics.SetRenderTarget(input, 0, (CubemapFace)face);
            tmp_face.ReadPixels(new Rect(0, 0, input.width, input.height), 0, 0);
            output.SetPixels(tmp_face.GetPixels(), (CubemapFace)face);
        }
        output.Apply();

        RenderTexture.active = active;

        Object.DestroyImmediate(tmp_face);

        return(output);
    }
Ejemplo n.º 20
0
    public void CopyToFace()
    {
        if (cubemapResolution != sourceTextureResolution.x || cubemapResolution != sourceTextureResolution.y)
        {
            throw new Exception("Panoramic texture to cubemap texture generator error: cubemap resolution is different from source texture width or height.");
        }

        for (int x = 0; x < cubemapResolution; x++)
        {
            for (int y = 0; y < cubemapResolution; y++)
            {
                targetCubemap.SetPixel(targetFace, x, y, sourceTexture.GetPixel(x, y));
            }
        }

        targetCubemap.Apply();
    }
Ejemplo n.º 21
0
    // Use this for initialization
    void Start()
    {
        cam = GameObject.Find("Camera");
        //gameObject.transform.eulerAngles = new Vector3(0,0,0);
        Mesh mesh = gameObject.GetComponent <MeshFilter>().mesh;

        child0 = new GameObject("child0");
        child0.AddComponent <MeshFilter>();
        child0.AddComponent <MeshRenderer>();
        child0.transform.position = gameObject.transform.position;
        child0.transform.parent   = gameObject.transform;
        child0.GetComponent <MeshFilter>().mesh       = mesh;
        child0.GetComponent <MeshRenderer>().material = gameObject.GetComponent <MeshRenderer>().material;
        //child0.transform.localScale = new Vector3(1,1,1);
        child0.transform.eulerAngles = new Vector3(0, 90, 0);

        child1 = new GameObject("child1");
        child1.AddComponent <MeshFilter>();
        child1.AddComponent <MeshRenderer>();
        child1.transform.position = gameObject.transform.position;
        child1.transform.parent   = gameObject.transform;
        child1.GetComponent <MeshFilter>().mesh       = mesh;
        child1.GetComponent <MeshRenderer>().material = gameObject.GetComponent <MeshRenderer>().material;
        //child0.transform.localScale = new Vector3(1,1,1);
        child1.transform.eulerAngles = new Vector3(0, 180, 0);

        child2 = new GameObject("child2");
        child2.AddComponent <MeshFilter>();
        child2.AddComponent <MeshRenderer>();
        child2.transform.position = gameObject.transform.position;
        child2.transform.parent   = gameObject.transform;
        child2.GetComponent <MeshFilter>().mesh       = mesh;
        child2.GetComponent <MeshRenderer>().material = gameObject.GetComponent <MeshRenderer>().material;
        //child0.transform.localScale = new Vector3(1,1,1);
        child2.transform.eulerAngles = new Vector3(0, 270, 0);



        gameObject.transform.up = cam.transform.position - gameObject.transform.position;
        int width = 256;

        heightMap = new Cubemap(width, TextureFormat.ARGB32, false);
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < width; j++)
            {
                heightMap.SetPixel(CubemapFace.NegativeX, i, j, new Color(1, 0, 0, 1));
                heightMap.SetPixel(CubemapFace.NegativeY, i, j, new Color(1, 1, 0, 1));
                heightMap.SetPixel(CubemapFace.NegativeZ, i, j, new Color(1, 0, 1, 1));
                heightMap.SetPixel(CubemapFace.PositiveX, i, j, new Color(1, 1, 0.5f, 1));
                heightMap.SetPixel(CubemapFace.PositiveY, i, j, new Color(1, 1, 0.75f, 1));
                heightMap.SetPixel(CubemapFace.PositiveZ, i, j, new Color(1, 1, 1, 1));
            }
        }
        heightMap.Apply();
    }
Ejemplo n.º 22
0
 void OnWizardCreate()
 {
     if (camera == null)
     {
         camera = Camera.main;
     }
     // render into cubemap
     camera.RenderToCubemap(cubemap);
     cubemap.Apply();
     ConvertToPng();
 }
    private static void ClearBakedTexture(Texture cubemap)
    {
        Cubemap p = cubemap as Cubemap;

        FillCubemapFace(p, CubemapFace.PositiveX, Color.black);
        FillCubemapFace(p, CubemapFace.PositiveY, Color.black);
        FillCubemapFace(p, CubemapFace.PositiveZ, Color.black);
        FillCubemapFace(p, CubemapFace.NegativeX, Color.black);
        FillCubemapFace(p, CubemapFace.NegativeY, Color.black);
        FillCubemapFace(p, CubemapFace.NegativeZ, Color.black);
        p.Apply();
    }
Ejemplo n.º 24
0
        public override void OnInspectorGUI()
        {
            if (this.m_Images == null)
            {
                this.InitTexturesFromCubemap();
            }
            EditorGUIUtility.labelWidth = 50f;
            Cubemap cubemap = this.target as Cubemap;

            if (cubemap == null)
            {
                return;
            }
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Right\n(+X)", CubemapFace.PositiveX);
            this.ShowFace("Left\n(-X)", CubemapFace.NegativeX);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Top\n(+Y)", CubemapFace.PositiveY);
            this.ShowFace("Bottom\n(-Y)", CubemapFace.NegativeY);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            this.ShowFace("Front\n(+Z)", CubemapFace.PositiveZ);
            this.ShowFace("Back\n(-Z)", CubemapFace.NegativeZ);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            EditorGUIUtility.labelWidth = 0f;
            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.HelpBox("Lowering face size is a destructive operation, you might need to re-assign the textures later to fix resolution issues. It's preferable to use Cubemap texture import type instead of Legacy Cubemap assets.", MessageType.Warning);
            int num = TextureUtil.GetGLWidth(cubemap);

            num = EditorGUILayout.IntPopup("Face size", num, CubemapInspector.kSizes, CubemapInspector.kSizesValues, new GUILayoutOption[0]);
            int  num2      = TextureUtil.CountMipmaps(cubemap);
            bool useMipmap = EditorGUILayout.Toggle("MipMaps", num2 > 1, new GUILayoutOption[0]);
            bool flag      = TextureUtil.GetLinearSampled(cubemap);

            flag = EditorGUILayout.Toggle("Linear", flag, new GUILayoutOption[0]);
            bool flag2 = TextureUtil.IsCubemapReadable(cubemap);

            flag2 = EditorGUILayout.Toggle("Readable", flag2, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                if (TextureUtil.ReformatCubemap(ref cubemap, num, num, cubemap.format, useMipmap, flag))
                {
                    this.InitTexturesFromCubemap();
                }
                TextureUtil.MarkCubemapReadable(cubemap, flag2);
                cubemap.Apply();
            }
        }
Ejemplo n.º 25
0
    public IEnumerator LoadAndSaveCubemapMaterials(string path, bool isRightEye)
    {
        List <Texture2D> textures = new List <Texture2D>();

        if (Directory.Exists(GetCacheDirectory(path)))
        {
            StatusText.SetText("Loading textures from cache");


            yield return(StartCoroutine(GetTexturesFromCache(path, textures)));
        }
        else
        {
            StatusText.SetText("Loading textures from tif");

            yield return(StartCoroutine(GetTexturesFromTif(path, textures)));
        }

        int           texSize = textures[0].width;
        TextureFormat format  = textures[0].format;

        StatusText.SetText("Creating cubemap");

        yield return(null);

        Cubemap cubemap = new Cubemap(texSize, format, false);

        yield return(StartCoroutine(CreateCubemapFromTextures(textures, cubemap)));

        cubemap.Apply();

        Material eyeMat = new Material(Shader.Find("Skybox/Cubemap"));

        eyeMat.SetTexture(Shader.PropertyToID("_Tex"), cubemap);

        if (isRightEye)
        {
            rightEye = eyeMat;
        }
        else
        {
            leftEye = eyeMat;
        }

        loaded = true;
        for (int i = 0; i < textures.Count; ++i)
        {
            Destroy(textures[i]);
        }
        textures.Clear();
        textures = null;
    }
Ejemplo n.º 26
0
        private static Cubemap GenerateHeightmap(Config cfg)
        {
            Random.State savedState = Random.state;

            int     size      = cfg.heightCubemapSize;
            Cubemap heightMap = new Cubemap(size, TextureFormat.RGB24, false);

            // Pixels are laid out right to left, top to bottom
            Color[] pixels = new Color[size * size];
            Color   pixel  = new Color();

            var generator = new LibNoise.Generator.Perlin();

            generator.Frequency   = cfg.noiseScale;
            generator.OctaveCount = cfg.octaves;
            generator.Seed        = cfg.seed;

            foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace)))
            {
                if (face == CubemapFace.Unknown)
                {
                    continue;
                }

                for (int y = 0; y < size; ++y)
                {
                    for (int x = 0; x < size; ++x)
                    {
                        Vector2 uv        = new Vector2((float)x / (size - 1), (float)y / (size - 1));
                        Vector3 radiusVec = CubemapProjections.GetRadiusVectorFromFace(face, uv);

                        /*pixel.r = (radius.x + 1) * 0.5f;
                        *  pixel.g = (radius.y + 1) * 0.5f;
                        *  pixel.b = (radius.z + 1) * 0.5f;*/

                        float height = (float)generator.GetValue(radiusVec * cfg.radius);
                        height  = (height + 1) * 0.5f;
                        pixel.r = pixel.g = pixel.b = height;

                        pixels[x + y * size] = pixel;
                    }
                }

                heightMap.SetPixels(pixels, face);
                heightMap.Apply();
            }


            Random.state = savedState;

            return(heightMap);
        }
Ejemplo n.º 27
0
        //Reads the pixels in from the side, and assigns it to the proper face of the cubemap
        private void AssignCubemapFace(Texture2D side, CubemapFace cubemapFace)
        {
            for (int i = 0; i < _size; i++)
            {
                for (int j = 0; j < _size; j++)
                {
                    Color pixel = side.GetPixel(i, j);
                    _tempCubeMap.SetPixel(cubemapFace, i, j, pixel);
                }
            }

            _tempCubeMap.Apply();
        }
    private static Cubemap GetDefaultBlackCube()
    {
        var cm = new Cubemap(1, TextureFormat.RGB24, true);

        cm.SetPixels(new Color[] { Color.black }, CubemapFace.NegativeX, 0);
        cm.SetPixels(new Color[] { Color.black }, CubemapFace.PositiveX, 0);
        cm.SetPixels(new Color[] { Color.black }, CubemapFace.NegativeY, 0);
        cm.SetPixels(new Color[] { Color.black }, CubemapFace.PositiveY, 0);
        cm.SetPixels(new Color[] { Color.black }, CubemapFace.NegativeZ, 0);
        cm.SetPixels(new Color[] { Color.black }, CubemapFace.PositiveZ, 0);
        cm.Apply();
        return(cm);
    }
Ejemplo n.º 29
0
        public void toCube(ref Cubemap cube, int mip, ColorMode cubeColorMode, bool useGamma)
        {
            int faceLength = faceSize * faceSize;

            Color[] facePixels = new Color[faceLength];
            for (int face = 0; face < 6; ++face)
            {
                pixelCopy(ref facePixels, 0, pixels, face * faceLength, faceLength);
                encode(ref facePixels, facePixels, cubeColorMode, useGamma);
                cube.SetPixels(facePixels, (CubemapFace)face, mip);
            }
            cube.Apply(false);
        }
Ejemplo n.º 30
0
    void Start()
    {
        Camera mainCam = GetComponent <Camera>();

        if (GenerateNewMap)
        {
            cubemap = new Cubemap(512, TextureFormat.ARGB32, false);
        }

        mainCam.RenderToCubemap(cubemap);

        cubemap.Apply();
    }