Exemplo n.º 1
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();
    }
Exemplo n.º 2
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;
    }
Exemplo n.º 3
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");
    }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
    private Cubemap ToCubemap(RenderTexture renderTexture)
    {
        CubemapFace[] faces = new CubemapFace[] {
            CubemapFace.PositiveX, CubemapFace.NegativeX,
            CubemapFace.PositiveY, CubemapFace.NegativeY,
            CubemapFace.PositiveZ, CubemapFace.NegativeZ
        };

        RenderTexture.active = renderTexture;

        Texture2D cubemapHorizontal = new Texture2D(6 * renderTexture.height, renderTexture.height, TextureFormat.RGBA32, false);

        cubemapHorizontal.ReadPixels(new Rect(0, 0, renderTexture.height, renderTexture.height), 0, 0);
        Texture2D tmp = new Texture2D(6 * renderTexture.height, renderTexture.height, TextureFormat.Alpha8, false);

        tmp.SetPixels(cubemapHorizontal.GetPixels());

        RenderTexture.active = null;

        Cubemap cubemap = new Cubemap(renderTexture.height, TextureFormat.Alpha8, false);

        for (int i = 0; i < 6; ++i)
        {
            cubemap.SetPixels(tmp.GetPixels(i * cubemapHorizontal.height, 0, cubemapHorizontal.height, cubemapHorizontal.height), faces[i]);
        }

        return(cubemap);
    }
Exemplo n.º 6
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);
    }
Exemplo n.º 7
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");
    }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 将此函数添加到一个子类中,以在立方体贴图纹理完成导入之前获取通知
        /// </summary>
        public void OnPostprocessCubemap(Cubemap cubemap)
        {
            string lowerCaseAssetPath = assetPath.ToLower();

            if (lowerCaseAssetPath.IndexOf("/postprocessedcubemaps/") == -1)
            {
                return;
            }

            for (int m = 0; m < cubemap.mipmapCount; m++)
            {
                for (int face = 0; face < 6; face++)
                {
                    CubemapFace f = (CubemapFace)face;

                    Color[] c = cubemap.GetPixels(f, m);

                    for (int i = 0; i < c.Length; i++)
                    {
                        c[i].r = c[i].r * 0.5f;
                        c[i].g = c[i].g * 0.5f;
                        c[i].b = c[i].b * 0.5f;
                    }
                    cubemap.SetPixels(c, f, m);
                }
            }
        }
Exemplo n.º 10
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());
    }
 // Start is called before the first frame update
 void Start()
 {
     if (transform.rotation.eulerAngles.y == 90)
     {
         currCube = new Cubemap(cube.height, cube.format, true);
     }
     for (int i = 0; i < cube.mipmapCount; i++)
     {
         currCube.SetPixels(cube.GetPixels(CubemapFace.PositiveX, i), CubemapFace.PositiveZ, i);
         currCube.SetPixels(cube.GetPixels(CubemapFace.PositiveZ, i), CubemapFace.NegativeX, i);
         currCube.SetPixels(cube.GetPixels(CubemapFace.NegativeX, i), CubemapFace.NegativeZ, i);
         currCube.SetPixels(cube.GetPixels(CubemapFace.NegativeZ, i), CubemapFace.PositiveX, i);
     }
     currCube.Apply();
     GetComponent <ReflectionProbe>().customBakedTexture = currCube;
 }
Exemplo n.º 12
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();
        }
    }
Exemplo 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;
        }
Exemplo n.º 14
0
    static int SetPixels(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 3)
        {
            Cubemap     obj   = LuaScriptMgr.GetNetObject <Cubemap>(L, 1);
            Color[]     objs0 = LuaScriptMgr.GetArrayObject <Color>(L, 2);
            CubemapFace arg1  = LuaScriptMgr.GetNetObject <CubemapFace>(L, 3);
            obj.SetPixels(objs0, arg1);
            return(0);
        }
        else if (count == 4)
        {
            Cubemap     obj   = LuaScriptMgr.GetNetObject <Cubemap>(L, 1);
            Color[]     objs0 = LuaScriptMgr.GetArrayObject <Color>(L, 2);
            CubemapFace arg1  = LuaScriptMgr.GetNetObject <CubemapFace>(L, 3);
            int         arg2  = (int)LuaScriptMgr.GetNumber(L, 4);
            obj.SetPixels(objs0, arg1, arg2);
            return(0);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: Cubemap.SetPixels");
        }

        return(0);
    }
Exemplo n.º 15
0
 private void setCubemap()
 {
     for (int a = 0; a < 6; a++)
     {
         cubemap.SetPixels(cubemapColors[a], faceArray[a]);
     }
 }
Exemplo n.º 16
0
        //helper stuff
        private static void SetFacePixels(Cubemap cube, CubemapFace face, Texture2D tex, int mip, bool flipHorz, bool flipVert, bool convertHDR)
        {
            Color[] pixels = tex.GetPixels();
            Color   temp   = Color.black;

            Color[] dstPixels;
            int     tw = tex.width >> mip;
            int     th = tex.height >> mip;

            //we read a sub-rectangle of tex into the cubemap mip
            dstPixels = new Color[tw * th];
            for (int x = 0; x < tw; ++x)
            {
                for (int y = 0; y < th; ++y)
                {
                    int i     = x + y * tex.width;
                    int dst_i = x + y * tw;
                    dstPixels[dst_i] = pixels[i];
                    //this forces LDR data to be compliant with HDR rendering by setting a lowest non-zero exposure in the alpha channel
                    if (convertHDR)
                    {
                        dstPixels[dst_i].a = 1f / 6f;
                    }
                }
            }

            if (flipHorz)
            {
                for (int x = 0; x < tw / 2; ++x)
                {
                    for (int y = 0; y < th; ++y)
                    {
                        int swap_x = tw - x - 1;
                        int i      = x + y * tw;
                        int swap_i = swap_x + y * tw;
                        temp = dstPixels[swap_i];
                        dstPixels[swap_i] = dstPixels[i];
                        dstPixels[i]      = temp;
                    }
                }
            }
            if (flipVert)
            {
                for (int x = 0; x < tw; ++x)
                {
                    for (int y = 0; y < th / 2; ++y)
                    {
                        int swap_y = th - y - 1;
                        int i      = x + y * tw;
                        int swap_i = x + swap_y * tw;
                        temp = dstPixels[swap_i];
                        dstPixels[swap_i] = dstPixels[i];
                        dstPixels[i]      = temp;
                    }
                }
            }
            cube.SetPixels(dstPixels, face, mip);
        }
Exemplo n.º 17
0
    public static void RenderIntoCubemap(Camera ownerCamera, Cubemap outCubemap)
    {
        int width  = outCubemap.width;
        int height = outCubemap.height;

        CubemapFace[] array = new CubemapFace[6];
        RuntimeHelpers.InitializeArray(array, fieldof(< PrivateImplementationDetails >.$field - DB17E883A647963A26D973378923EF4649801319).FieldHandle);
        CubemapFace[] array2 = array;
        Vector3[]     array3 = new Vector3[]
        {
            new Vector3(0f, 90f, 0f),
            new Vector3(0f, -90f, 0f),
            new Vector3(-90f, 0f, 0f),
            new Vector3(90f, 0f, 0f),
            new Vector3(0f, 0f, 0f),
            new Vector3(0f, 180f, 0f)
        };
        RenderTexture active        = RenderTexture.active;
        float         fieldOfView   = ownerCamera.fieldOfView;
        float         aspect        = ownerCamera.aspect;
        Quaternion    rotation      = ownerCamera.transform.rotation;
        RenderTexture renderTexture = new RenderTexture(width, height, 24);

        renderTexture.antiAliasing = 8;
        renderTexture.dimension    = TextureDimension.Tex2D;
        renderTexture.hideFlags    = HideFlags.HideAndDontSave;
        Texture2D texture2D = new Texture2D(width, height, TextureFormat.RGB24, false);

        texture2D.hideFlags       = HideFlags.HideAndDontSave;
        ownerCamera.targetTexture = renderTexture;
        ownerCamera.fieldOfView   = 90f;
        ownerCamera.aspect        = 1f;
        Color[] array4 = new Color[texture2D.height * texture2D.width];
        for (int i = 0; i < array2.Length; i++)
        {
            ownerCamera.transform.eulerAngles = array3[i];
            ownerCamera.Render();
            RenderTexture.active = renderTexture;
            texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
            Color[] pixels = texture2D.GetPixels();
            for (int j = 0; j < height; j++)
            {
                for (int k = 0; k < width; k++)
                {
                    array4[j * width + k] = pixels[(height - 1 - j) * width + k];
                }
            }
            outCubemap.SetPixels(array4, array2[i]);
        }
        outCubemap.SmoothEdges();
        RenderTexture.active           = active;
        ownerCamera.fieldOfView        = fieldOfView;
        ownerCamera.aspect             = aspect;
        ownerCamera.transform.rotation = rotation;
        ownerCamera.targetTexture      = active;
        UnityEngine.Object.DestroyImmediate(texture2D);
        UnityEngine.Object.DestroyImmediate(renderTexture);
    }
 private static void FillCubemapFace(Cubemap c, CubemapFace f, Color color)
 {
     Color[] colors = c.GetPixels(f);
     for (int i = 0; i < colors.Length; i++)
     {
         colors[i] = color;
     }
     c.SetPixels(colors, f);
 }
Exemplo n.º 19
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();
    }
Exemplo n.º 20
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);
    }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
    /*!
     * Initialize a single Cubemap face to all black.
     *
     * \param cubemap The Cubemap.
     * \param face The face to init.
     */

    public static void initCubeMapFace(Cubemap cubemap, CubemapFace face)
    {
        Color[] colors = new Color[cubemap.width * cubemap.height];

        for (uint i = 0; i < colors.Length; ++i)
        {
            colors[i] = Color.black;
        }

        cubemap.SetPixels(colors, face);

        cubemap.Apply();
    }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
    public static void CopyTextureToCubemapFace(Texture2D texture, ref Cubemap targetCubemap, CubemapFace targetFace, bool applyChanges = true)
    {
        if (texture.height != targetCubemap.height || texture.width != targetCubemap.height)
        {
            throw new Exception("Panoramic to cubemap texture converter: 'CopyTextureToCubemapFace' texture to copy to face is non square or its resolution does not match the target cubemap's resolution.");
        }

        targetCubemap.SetPixels(texture.GetPixels(), targetFace);

        if (applyChanges)
        {
            targetCubemap.Apply();
        }
    }
Exemplo n.º 25
0
    public void SaveRenderTexture(RenderTexture texture, Cubemap cube, CubemapFace face, bool flipX = false, bool flipY = true)
    {
        RenderTexture.active = texture;
        // read render target
        Texture2D texture_ = new Texture2D(m_TextureSize, m_TextureSize, TextureFormat.ARGB32, false);

        texture_.ReadPixels(new Rect(0, 0, m_TextureSize, m_TextureSize), 0, 0);
        texture_.Apply();
        // flip
        if (flipY)
        {
            for (int x = 0; x < m_TextureSize; x++)
            {
                for (int y1 = 0, y2 = m_TextureSize - 1; y1 < y2; y1++, y2--)
                {
                    Color t1 = texture_.GetPixel(x, y1);
                    texture_.SetPixel(x, y1, texture_.GetPixel(x, y2));
                    texture_.SetPixel(x, y2, t1);
                }
            }
        }
        texture_.Apply();
        if (flipX)
        {
            for (int x1 = 0, x2 = m_TextureSize - 1; x1 < x2; x1++, x2--)
            {
                for (int y = 0; y < m_TextureSize; y++)
                {
                    Color t1 = texture_.GetPixel(x1, y);
                    texture_.SetPixel(x1, y, texture_.GetPixel(x2, y));
                    texture_.SetPixel(x2, y, t1);
                }
            }
        }
        texture_.Apply();
        if (m_saveImage)
        {
            byte[]   bytes = texture_.EncodeToPNG();
            string[] path_ = EditorApplication.currentScene.Split(char.Parse("/"));
            path_[path_.Length - 1] = filename + "_" + face.ToString() + ".png";
            System.IO.File.WriteAllBytes(string.Join("/", path_), bytes);
        }
        // save to cubemap
        cube.SetPixels(texture_.GetPixels(), face);
        cube.Apply();
        DestroyImmediate(texture_);

        RenderTexture.active = null;
    }
Exemplo n.º 26
0
        public void resampleToCube(ref Cubemap cube, int mip, ColorMode cubeColorMode, bool useGamma)
        {
            int mipSize   = cube.width >> mip;
            int mipLength = mipSize * mipSize * 6;

            Color[] mipPixels = new Color[mipLength];

            for (int face = 0; face < 6; ++face)
            {
                resampleFace(ref mipPixels, face, mipSize, false);
                encode(ref mipPixels, mipPixels, cubeColorMode, useGamma);
                cube.SetPixels(mipPixels, (CubemapFace)face, mip);
            }
            cube.Apply(false);
        }
Exemplo n.º 27
0
    void EndCubeFaceRender(Cubemap target, CubemapFace f, int mipLevel, Camera cam, bool aa)
    {
        // read pixels into destination
        int       size    = target.width >> mipLevel;
        Texture2D tempTex = new Texture2D(size, size);

        tempTex.ReadPixels(new Rect(0, 0, size, size), 0, 0, false);
        //Debug.Log (mipLevel);
        target.SetPixels(tempTex.GetPixels(), f, mipLevel);
        Object.DestroyImmediate(tempTex);

        // cleanup camera
        RenderTexture.ReleaseTemporary(cam.targetTexture);
        cam.targetTexture = null;
        cam.ResetWorldToCameraMatrix();
    }
Exemplo n.º 28
0
    void CannyCubemap(Cubemap cube, Cubemap cannycube)
    {
        Texture2D faceTex = new Texture2D(cannycube.height, cannycube.width);

        foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace)))
        {
            if (cube)
            {
                Color[] cols = cube.GetPixels(face, mip);
                faceTex.SetPixels(cols);
                cols = CannyTex2d(faceTex, s1, s2, f1).GetPixels();
                cannycube.SetPixels(cols, face);
            }
        }
        cannycube.Apply();
    }
Exemplo n.º 29
0
    public static void ConvertLatLongToCubemap()
    {
        foreach (Object o in Selection.GetFiltered(typeof(Texture2D),
                                                   SelectionMode.Assets))
        {
            try {
                Texture2D latLong = o as Texture2D;

                int     faceSize = Mathf.ClosestPowerOfTwo(latLong.width / 4);
                Cubemap cube     = new Cubemap(faceSize, latLong.format, latLong.mipmapCount > 0);

                // For each side
                foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace)))
                {
                    EditorUtility.DisplayProgressBar("Latlong to cubemap", "Processing " + latLong.name + " " + face, (float)face / 6.0f);
                    Color[] pixels = new Color[faceSize * faceSize];
                    for (int x = 0; x < faceSize; ++x)
                    {
                        for (int y = 0; y < faceSize; ++y)
                        {
                            Vector3 dir = Utils.Cubemap.CubemapDirection(face,
                                                                         (x + 0.5f) / (float)faceSize - 0.5f,
                                                                         (y + 0.5f) / (float)faceSize - 0.5f);

                            Vector2 uv = Utils.Cubemap.DirectionToSphericalUV(dir);

                            int index = x + y * faceSize;
                            pixels[index] = latLong.GetPixelBilinear(uv.x, uv.y);
                        }
                    }

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

                string sourcePath = AssetDatabase.GetAssetPath(latLong);
                string saveFolder = System.IO.Path.GetDirectoryName(sourcePath);
                string destPath   = saveFolder + "/" + latLong.name + ".cubemap";
                AssetDatabase.CreateAsset(cube, destPath);
                Debug.Log("Converted " + sourcePath + " to cubemap");
            } catch (System.Exception e) {
                Debug.LogError("Convertion from lat long to cubemap failed:\n" + e);
            }
        }
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 30
0
    private Cubemap ToCubemap(Texture2DArray array)
    {
        CubemapFace[] faces = new CubemapFace[] {
            CubemapFace.PositiveX, CubemapFace.NegativeX,
            CubemapFace.PositiveY, CubemapFace.NegativeY,
            CubemapFace.PositiveZ, CubemapFace.NegativeZ
        };

        Cubemap cubemap = new Cubemap(array.width, array.format, false);

        for (int i = 0; i < 6; ++i)
        {
            cubemap.SetPixels(array.GetPixels(i), faces[i]);
        }

        return(cubemap);
    }