SetPixels() private method

private SetPixels ( Color colors, CubemapFace face ) : void
colors Color
face CubemapFace
return void
コード例 #1
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");
    }
コード例 #2
0
 static public int SetPixels(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(UnityEngine.Color[]), typeof(UnityEngine.CubemapFace), typeof(int)))
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             UnityEngine.Color[] a1;
             checkType(l, 2, out a1);
             UnityEngine.CubemapFace a2;
             checkEnum(l, 3, out a2);
             System.Int32 a3;
             checkType(l, 4, out a3);
             self.SetPixels(a1, a2, a3);
             return(0);
         }
         else if (matchType(l, 2, typeof(UnityEngine.Color[]), typeof(UnityEngine.CubemapFace)))
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             UnityEngine.Color[] a1;
             checkType(l, 2, out a1);
             UnityEngine.CubemapFace a2;
             checkEnum(l, 3, out a2);
             self.SetPixels(a1, a2);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
コード例 #3
0
 static public int SetPixels(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             UnityEngine.Color[] a1;
             checkArray(l, 2, out a1);
             UnityEngine.CubemapFace a2;
             a2 = (UnityEngine.CubemapFace)LuaDLL.luaL_checkinteger(l, 3);
             self.SetPixels(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             UnityEngine.Color[] a1;
             checkArray(l, 2, out a1);
             UnityEngine.CubemapFace a2;
             a2 = (UnityEngine.CubemapFace)LuaDLL.luaL_checkinteger(l, 3);
             System.Int32 a3;
             checkType(l, 4, out a3);
             self.SetPixels(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetPixels to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #4
0
ファイル: CubeMapper.cs プロジェクト: imclab/CubeMapRenderer
    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();
    }
コード例 #5
0
        void Create()
        {
            try {
            string planetFolder = Application.dataPath + "/Worlds/Planets/" + worldName;
            System.IO.Directory.CreateDirectory(planetFolder);

            NoiseVector[] noiseVectors = CreateNoiseVectors(noiseLayers);

            Cubemap clouds = new Cubemap(detail, TextureFormat.RGBA32, false); // false for now as unity doesn't have seamless cubemaps $)%ˆ#)!_#

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

                        float intensity = 0.0f;
                        foreach (NoiseVector vec in noiseVectors) {
                            float distance = (dir - vec.Normal).magnitude;
                            float v = Mathf.Max(0.0f, 1.0f - distance / vec.Radius);
                            intensity += v * vec.Amplitude;
                        }

                        int index = x + y * detail;
                        pixels[index] = new Color(intensity, intensity, intensity, intensity);
                    }

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

            clouds.SmoothEdges(); // Because unity doesn't support seamless filtering, but is it enough?

            string saveFolder = "Assets/Worlds/Planets/" + worldName + "/";
            string savePath = saveFolder + "clouds.cubemap";
            AssetDatabase.CreateAsset(clouds, savePath);

            } catch (System.Exception e) {
            Debug.LogError("Creation of clouds failed:\n" + e);
            }

            EditorUtility.ClearProgressBar();
        }
コード例 #6
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();
    }
コード例 #7
0
        void Awake()
        {
            fogEffect = FindObjectOfType<FogEffect>();
            renderProperties = FindObjectOfType<RenderProperties>();

            var tmp = new Texture2D(4096, 4096);
            tmp.LoadImage(File.ReadAllBytes("C:\\Users\\nlight\\Desktop\\sky.png"));
            var pixels = tmp.GetPixels();

            cubemap = new Cubemap(4096, TextureFormat.RGBA32, false);
            cubemap.SetPixels(pixels, CubemapFace.NegativeX);
            cubemap.SetPixels(pixels, CubemapFace.NegativeY);
            cubemap.SetPixels(pixels, CubemapFace.NegativeZ);
            cubemap.SetPixels(pixels, CubemapFace.PositiveX);
            cubemap.SetPixels(pixels, CubemapFace.PositiveY);
            cubemap.SetPixels(pixels, CubemapFace.PositiveZ);
            cubemap.Apply();
        }
コード例 #8
0
 static public int SetPixels(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 3)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             UnityEngine.Color[] a1;
             checkArray(l, 2, out a1);
             UnityEngine.CubemapFace a2;
             checkEnum(l, 3, out a2);
             self.SetPixels(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 4)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             UnityEngine.Color[] a1;
             checkArray(l, 2, out a1);
             UnityEngine.CubemapFace a2;
             checkEnum(l, 3, out a2);
             System.Int32 a3;
             checkType(l, 4, out a3);
             self.SetPixels(a1, a2, a3);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #9
0
ファイル: LuxCubeProcessor.cs プロジェクト: Backman/Hellbound
// brute force: no look up table used

    void FilterCubefacesBF (Cubemap RadianceCubeMap, int mipLevel, float a_FilterConeAngle, float a_SpecularPower)
    {
	    // Read the first CubeFace
	    Color[] InputCubeFacePixels = RadianceCubeMap.GetPixels(CubemapFace.PositiveX, mipLevel);
	    // Get its dimensions
	    int faceLength = InputCubeFacePixels.Length;
	    int a_Size = (int)Mathf.Sqrt(faceLength);
	    // Create new array for all Faces
	    Color[] PixelsOfAllFaces = new Color[faceLength * 6];
	    // Copy first face
	    InputCubeFacePixels.CopyTo(PixelsOfAllFaces, 0);
	    // Copy all other Faces
	    for (int readFace = 1; readFace < 6; readFace++ ) {
		    InputCubeFacePixels = RadianceCubeMap.GetPixels((CubemapFace)readFace, mipLevel);
		    InputCubeFacePixels.CopyTo(PixelsOfAllFaces, faceLength * readFace);
	    }
	    InputCubeFacePixels = null;

	    // declare jagged output array and init its child arrays
	    Color[][] OutputCubeFacePixels = new Color[6][];
	    OutputCubeFacePixels[0] = new Color[faceLength];
	    OutputCubeFacePixels[1] = new Color[faceLength];
	    OutputCubeFacePixels[2] = new Color[faceLength];
	    OutputCubeFacePixels[3] = new Color[faceLength];
	    OutputCubeFacePixels[4] = new Color[faceLength];
	    OutputCubeFacePixels[5] = new Color[faceLength];


	    // FilterCubeSurfaces
	    float srcTexelAngle;
        float dotProdThresh;
        int filterSize;
	    //angle about center tap to define filter cone
	    float filterAngle;
	    //min angle a src texel can cover (in degrees)
	    srcTexelAngle = (180.0f / CP_PI) * Mathf.Atan2(1.0f, (float)a_Size);  
	    //filter angle is 1/2 the cone angle
        filterAngle = a_FilterConeAngle / 2.0f;
        //ensure filter angle is larger than a texel
        if(filterAngle < srcTexelAngle)
        {
            filterAngle = srcTexelAngle;    
        }
        //ensure filter cone is always smaller than the hemisphere
        if(filterAngle > 90.0f)
        {
            filterAngle = 90.0f;
        }

	    // The maximum number of texels in 1D the filter cone angle will cover
	    // Used to determine bounding box size for filter extents
	    filterSize = (int)Mathf.Ceil(filterAngle / srcTexelAngle);
	    // Ensure conservative region always covers at least one texel
        if(filterSize < 1)
        {
            filterSize = 1;
        }

	    // dotProdThresh threshold based on cone angle to determine whether or not taps 
	    // Reside within the cone angle
	    dotProdThresh = Mathf.Cos( (CP_PI / 180.0f) * filterAngle );

	    // Process required faces
	    for (int a_FaceIdx = 0; a_FaceIdx < 6; a_FaceIdx++)
	    {
		    // Iterate over dst cube map face texel
		    for (int a_V  = 0; a_V < a_Size; a_V++)
		    {
			    for (int a_U = 0; a_U < a_Size; a_U++)
			    {
				    Vector4 Sample = new Vector4();
				    Color tempCol = new Color();
				
				    // get center tap direction
				    Vector3 centerTapDir = TexelToVect(a_FaceIdx, (float)a_U, (float)a_V, a_Size);

				    //--------------------------------------------------------------------------------------
				    //	ProcessFilterExtents 

				    float weightAccum = 0.0f;

				    // Iterate over cubefaces
				    for(int iFaceIdx = 0; iFaceIdx < 6; iFaceIdx++ )
				    {
					    for(int v = 0; v < a_Size; v++)
					    {
						    for(int u = 0; u < a_Size; u++)
						    {
							    // CP_FILTER_TYPE_COSINE_POWER
							    // Pointer to direction in cube map associated with texel
							    Vector3 texelVect = TexelToVect(iFaceIdx, (float)u, (float)v, a_Size);
							    // Check dot product to see if texel is within cone
							    float tapDotProd = Vector3.Dot(texelVect, centerTapDir);


							    float weight = 0.0f;
							    if( tapDotProd >= dotProdThresh && tapDotProd > 0.0f )
							    {
								
								    // Weight should be proportional to the solid angle of the tap
                 				    weight = TexelCoordSolidAngle(iFaceIdx, (float)u, (float)v, a_Size);
								    // Here we decide if we use a Phong/Blinn or a Phong/Blinn BRDF.
								    // Phong/Blinn BRDF is just the Phong/Blinn model multiply by the cosine of the lambert law
								    // so just adding one to specularpower do the trick.					   
								    // weight *= pow(tapDotProd, (a_SpecularPower + (float32)IsPhongBRDF));
							    // CP_FILTER_TYPE_COSINE_POWER
								    weight *= Mathf.Pow(tapDotProd, a_SpecularPower);
							    // CP_FILTER_TYPE_COSINE
								    //weight *= tapDotProd;
							    }
							    // Accumulate weight
							    weightAccum += weight;

							    // Get pixel from the input cubeMap array
							    tempCol = PixelsOfAllFaces[a_Size*a_Size*iFaceIdx + a_Size*v + u];
							    Sample += new Vector4(tempCol.r * weight, tempCol.g * weight, tempCol.b * weight, 1.0f);
						    }
					    }
				    }
				    // one pixel processed
				    // Lux needs alpha!
				    OutputCubeFacePixels[a_FaceIdx][a_V*a_Size + a_U] = new Color(Sample.x/ weightAccum, Sample.y/ weightAccum, Sample.z/ weightAccum, 1.0f);
			    // end inner loops
			    }
		    }
	    }
	    // Write Pixel from the jagged array back to the cubemap faces
	    for (int writeFace = 0; writeFace < 6; writeFace++ ) {
		    Color[] tempColors = OutputCubeFacePixels[writeFace];
		    RadianceCubeMap.SetPixels(tempColors, (CubemapFace)writeFace, mipLevel);
	    }
    }
コード例 #10
0
    public IEnumerator RenderCube(GameObject lightShapeObjTemp, GameObject lightShapeObjTempAlt, GameObject groundShapeObjTemp, Material gMat, Material lsMat, Material alsMat)
    {
        yield return new WaitForEndOfFrame();
        var cubeCamera = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
        cubeCamera.hideFlags = HideFlags.HideInHierarchy;
        var cubeCam = cubeCamera.GetComponent("Camera") as Camera;
        var tempFull = new Cubemap (LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, LightShapeProbe.LightShapeManager.hasMips) as Cubemap;
        yield return new WaitForEndOfFrame();
        cubeCam.nearClipPlane = 0.001f;
        cubeCam.aspect = 1.0f;

        if(LightShapeProbe.LightShapeManager.worldCamera)
        {
            if(!RenderSettings.skybox)
            {
                if(!LightShapeProbe.overrideCameraColor)
                {
                    cubeCam.backgroundColor = LightShapeProbe.LightShapeManager.worldCamera.backgroundColor;
                }

                if(LightShapeProbe.overrideCameraColor)
                {
                    cubeCam.backgroundColor = LightShapeProbe.BGColor;
                }
            }

                if(RenderSettings.skybox)
                {
                    if(!LightShapeProbe.overrideCameraColor)
                    {
                        cubeCam.clearFlags = CameraClearFlags.Skybox;
                    }
                    if(LightShapeProbe.overrideCameraColor)
                    {
                        cubeCam.clearFlags = CameraClearFlags.SolidColor;
                        cubeCam.backgroundColor = LightShapeProbe.BGColor;
                    }
                }
        }

        cubeCam.fov = 90;
        cubeCam.cullingMask = 1 << 0;
        cubeCamera.transform.position = transform.position;

        cubeCamera.transform.eulerAngles = new Vector3(0, 90, 0);
        Texture2D tex = new Texture2D (LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, false);

        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        Color [,] bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        Color [,] flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveX);
        tempFull.Apply();

        cubeCamera.transform.eulerAngles = new Vector3(0, 270, 0);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
            CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeX);
        tempFull.Apply();

        cubeCamera.transform.eulerAngles = new Vector3(0, 0, 0);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
            CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveZ);
        tempFull.Apply();

        cubeCamera.transform.eulerAngles = new Vector3(0, 180, 0);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
            CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeZ);
        tempFull.Apply();

        cubeCamera.transform.eulerAngles = new Vector3(270, 0, 0);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
            CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveY);
        tempFull.Apply();

        cubeCamera.transform.eulerAngles = new Vector3(90, 0, 0);
        yield return new WaitForEndOfFrame();
        tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
        yield return new WaitForEndOfFrame();
        tex.Apply ();
        CubeMapColors = tex.GetPixels();

        bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors[i];
        }

        flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
            {
                flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
        }

        row = -1;

        for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
        {
            if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
            CubeMapColors[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
        }

        tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeY);
        tempFull.Apply();

        yield return new WaitForEndOfFrame();

            var cubeCamera2 = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
            cubeCamera2.hideFlags = HideFlags.HideInHierarchy;
            var cubeCam2 = cubeCamera2.GetComponent("Camera") as Camera;
            var tempFull2 = new Cubemap (LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, LightShapeProbe.LightShapeManager.hasMips) as Cubemap;
            yield return new WaitForEndOfFrame();
            cubeCam2.clearFlags = CameraClearFlags.SolidColor;
            cubeCam2.nearClipPlane = 0.001f;
            cubeCam2.aspect = 1.0f;
            cubeCam2.cullingMask = 2 << 0;
            cubeCam2.fov = 90;
            cubeCam2.backgroundColor = Color.black;
            yield return new WaitForEndOfFrame();
            cubeCamera2.transform.position = transform.position;

            cubeCamera2.transform.eulerAngles = new Vector3(0, 90, 0);

            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors2 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors2[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors2[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull2.SetPixels(CubeMapColors2, CubemapFace.PositiveX);
            tempFull2.Apply();

            cubeCamera2.transform.eulerAngles = new Vector3(0, 270, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors2 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors2[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors2[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull2.SetPixels(CubeMapColors2, CubemapFace.NegativeX);
            tempFull2.Apply();

            cubeCamera2.transform.eulerAngles = new Vector3(0, 0, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors2 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors2[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors2[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull2.SetPixels(CubeMapColors2, CubemapFace.PositiveZ);
            tempFull2.Apply();

            cubeCamera2.transform.eulerAngles = new Vector3(0, 180, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors2 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors2[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors2[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull2.SetPixels(CubeMapColors2, CubemapFace.NegativeZ);
            tempFull2.Apply();

            cubeCamera2.transform.eulerAngles = new Vector3(270, 0, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors2 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors2[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors2[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull2.SetPixels(CubeMapColors2, CubemapFace.PositiveY);
            tempFull2.Apply();

            cubeCamera2.transform.eulerAngles = new Vector3(90, 0, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors2 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors2[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors2[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull2.SetPixels(CubeMapColors2, CubemapFace.NegativeY);
            tempFull2.Apply();

            yield return new WaitForEndOfFrame();

            CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveX);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.PositiveX);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveX);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeX);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.NegativeX);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeX);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveY);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.PositiveY);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveY);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeY);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.NegativeY);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeY);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveZ);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.PositiveZ);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveZ);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeZ);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.NegativeZ);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeZ);
            tempFull.Apply();

            if(lightShapeObjTemp)
            {
                Destroy(lightShapeObjTemp.gameObject);
                Destroy(lsMat);

            }

            if(lightShapeObjTempAlt)
            {
                Destroy(lightShapeObjTempAlt.gameObject);
                Destroy(alsMat);
            }

            if(LightShapeProbe.hasGround)
            {
                var cubeCamera3 = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
                var cubeCam3 = cubeCamera3.GetComponent("Camera") as Camera;

                cubeCam3.clearFlags = CameraClearFlags.SolidColor;
                cubeCam3.nearClipPlane = 0.001f;
                cubeCam3.farClipPlane = 5f;
                cubeCam3.aspect = 1.0f;
                cubeCam3.cullingMask = 2 << 0;

                cubeCam3.fov = 90;
                cubeCam3.backgroundColor = Color.white;
                yield return new WaitForEndOfFrame();

                cubeCamera3.transform.position = transform.position;
                cubeCamera3.transform.rotation = transform.rotation;
                var tempFull3 = new Cubemap (LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, false) as Cubemap;

                cubeCamera3.transform.eulerAngles = new Vector3(0, 90, 0);
            //1
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors3 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors3[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors3[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull3.SetPixels(CubeMapColors3, CubemapFace.PositiveX);
            tempFull3.Apply();
            //2
            cubeCamera3.transform.eulerAngles = new Vector3(0, 270, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors3 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors3[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors3[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull3.SetPixels(CubeMapColors3, CubemapFace.NegativeX);
            tempFull3.Apply();
            //3
            cubeCamera3.transform.eulerAngles = new Vector3(0, 0, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors3 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors3[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors3[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull3.SetPixels(CubeMapColors3, CubemapFace.PositiveZ);
            tempFull3.Apply();
            //4
            cubeCamera3.transform.eulerAngles = new Vector3(0, 180, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors3 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors3[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors3[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull3.SetPixels(CubeMapColors3, CubemapFace.NegativeZ);
            tempFull3.Apply();
            //5

            cubeCamera3.transform.eulerAngles = new Vector3(270, 0, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors3 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors3[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors3[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull3.SetPixels(CubeMapColors3, CubemapFace.PositiveY);
            tempFull3.Apply();
            //6
            cubeCamera3.transform.eulerAngles = new Vector3(90, 0, 0);
            yield return new WaitForEndOfFrame();
            tex.ReadPixels (new Rect(1, 1, LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize), 0, 0);
            yield return new WaitForEndOfFrame();
            tex.Apply ();
            CubeMapColors3 = tex.GetPixels();

            bigPicture = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
           		  if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
          		  bigPicture[row, i % LightShapeProbe.LightShapeManager.CubeMapSize] = CubeMapColors3[i];
            }

            flippedX = new Color[LightShapeProbe.LightShapeManager.CubeMapSize, LightShapeProbe.LightShapeManager.CubeMapSize];

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                for( int j = 0; j < LightShapeProbe.LightShapeManager.CubeMapSize; ++j)
                {
                    flippedX[LightShapeProbe.LightShapeManager.CubeMapSize - 1 - i, j] = bigPicture[i, j];
           		}
            }

            row = -1;

            for( int i = 0; i < LightShapeProbe.LightShapeManager.CubeMapSize * LightShapeProbe.LightShapeManager.CubeMapSize; ++i )
            {
                if ( i % LightShapeProbe.LightShapeManager.CubeMapSize == 0 ) ++row;
                CubeMapColors3[i] = flippedX[row, i % LightShapeProbe.LightShapeManager.CubeMapSize];
            }

            tempFull3.SetPixels(CubeMapColors3, CubemapFace.NegativeY);
            tempFull3.Apply();

            yield return new WaitForEndOfFrame();

                //1
                CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveY);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.PositiveY);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveY);
                tempFull.Apply();

                //2
                CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeY);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.NegativeY);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeY);
                tempFull.Apply();

                //3
                CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveX);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.PositiveX);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveX);
                tempFull.Apply();

                //4
                CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeX);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.NegativeX);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeX);
                tempFull.Apply();
                //5
                CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveZ);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.PositiveZ);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveZ);
                tempFull.Apply();
                //6
                CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeZ);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.NegativeZ);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeZ);
                tempFull.Apply();

                DestroyImmediate( cubeCamera3 );
            }

            if(groundShapeObjTemp)
            {
                Destroy(groundShapeObjTemp.gameObject);
                Destroy(gMat);
            }

        AssetDatabase.CreateAsset(tempFull, LightShapeProbe.LightShapeManager.savePath + LightShapeProbe.LightShapeManager.folderName + "/Cube_" + LightShapeProbe.LightShapeManager.CubeMapSize + "_" + (LightShapeProbe.myIndex + 1) + ".cubemap");

        yield return new WaitForEndOfFrame();

        if(LightShapeProbe.LightShapeManager.AltMethodManger.curProbeInt == LightShapeProbe.LightShapeManager.cubeProbes.Length)
        {
            if(!LightShapeProbe.LightShapeManager.AltMethodManger.secondPass)
            {
                LightShapeProbe.LightShapeManager.AltMethodManger.StopBatch();
            }
        }

        if(LightShapeProbe.LightShapeManager.AltMethodManger.secondPass)
        {
            if(LightShapeProbe.LightShapeManager.AltMethodManger.curProbeInt == LightShapeProbe.LightShapeManager.AltMethodManger.reflectObjs.Length)
            {
                LightShapeProbe.LightShapeManager.AltMethodManger.StopBatch();
            }

            if(LightShapeProbe.LightShapeManager.AltMethodManger.curProbeInt < LightShapeProbe.LightShapeManager.AltMethodManger.reflectObjs.Length)
            {
                StartCoroutine(LightShapeProbe.LightShapeManager.AltMethodManger.RenderCubeMaps());
            }
        }

        if(!LightShapeProbe.LightShapeManager.AltMethodManger.secondPass)
        {
            if(LightShapeProbe.LightShapeManager.AltMethodManger.curProbeInt < LightShapeProbe.LightShapeManager.cubeProbes.Length)
            {
                StartCoroutine(LightShapeProbe.LightShapeManager.AltMethodManger.RenderCubeMaps());
            }
        }

        UpdateCubeMaps();

        rewardInt = Random.Range(0, LightShapeProbe.LightShapeManager.rewardStrings.Length);

        if(!LightShapeProbe.LightShapeManager.renderingCubeMaps)
        {
            Debug.Log(LightShapeProbe.LightShapeManager.rewardStrings[rewardInt] + " CubeMap Rendered!");
            EditorApplication.isPlaying = false;
        }
    }
コード例 #11
0
    void UseColor()
    {
        var othersCube = new Cubemap (LightShapeProbe.LightShapeManager.CubeMapSize, TextureFormat.RGB24, false) as Cubemap;

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.PositiveX);

        for(var rXp = 0; rXp < CubeMapColorsR.Length; rXp++)
        {
            CubeMapColorsR[rXp] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.PositiveX);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.NegativeX);
        for(var rXn = 0; rXn < CubeMapColorsR.Length; rXn++)
        {
            CubeMapColorsR[rXn] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.NegativeX);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.PositiveY);
        for(var rYp = 0; rYp < CubeMapColorsR.Length; rYp++)
        {
            CubeMapColorsR[rYp] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.PositiveY);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.NegativeY);
        for(var rYn = 0; rYn < CubeMapColorsR.Length; rYn++)
        {
            CubeMapColorsR[rYn] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.NegativeY);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.PositiveZ);
        for(var rZp = 0; rZp < CubeMapColorsR.Length; rZp++)
        {
            CubeMapColorsR[rZp] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.PositiveZ);
        othersCube.Apply();

        CubeMapColorsR = othersCube.GetPixels(CubemapFace.NegativeZ);
        for(var rZn = 0; rZn < CubeMapColorsR.Length; rZn++)
        {
            CubeMapColorsR[rZn] = LightShapeProbe.reflectedColor;
        }

        othersCube.SetPixels(CubeMapColorsR, CubemapFace.NegativeZ);
        othersCube.Apply();

        GameObject[] wObjects = LightShapeProbe.LightShapeManager.cubeProbes;

        foreach(GameObject o in wObjects)
        {
            var oo = o.GetComponent("LightShapeProbe") as LightShapeProbe;

            foreach(GameObject ooo in oo.myObjects)
            {
                var tempMat = ooo.GetComponent<MeshRenderer>();

         				tempMat.sharedMaterial.SetTexture("_Cube", othersCube);
            }
        }
    }
コード例 #12
0
    ///<summary>
    /// Copy a mipmap level data to the array.
    ///</summary>
    static void SetCubeMipMap(Cubemap cubemap, Color[] data, int imageSize, int mipLevel)
    {
        // Copy all texels of the cubemap to an array.
        Color[] temp = new Color[imageSize];
        System.Array.Copy(data, 0, temp, 0, imageSize);
        cubemap.SetPixels(temp, CubemapFace.PositiveX, mipLevel);

        System.Array.Copy(data, imageSize, temp, 0, imageSize);
        cubemap.SetPixels(temp, CubemapFace.NegativeX, mipLevel);

        System.Array.Copy(data, imageSize * 2, temp, 0, imageSize);
        cubemap.SetPixels(temp, CubemapFace.PositiveY, mipLevel);

        System.Array.Copy(data, imageSize * 3, temp, 0, imageSize);
        cubemap.SetPixels(temp, CubemapFace.NegativeY, mipLevel);

        System.Array.Copy(data, imageSize * 4, temp, 0, imageSize);
        cubemap.SetPixels(temp, CubemapFace.PositiveZ, mipLevel);

        System.Array.Copy(data, imageSize * 5, temp, 0, imageSize);
        cubemap.SetPixels(temp, CubemapFace.NegativeZ, mipLevel);
    }
コード例 #13
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);
        }
コード例 #14
0
	IEnumerator ConvolveSpecularCubeMap()
	{
		int size = 0;
		int samples = 0;
		size = CubeSizeSetup(false);
		samples = qualitySetup(false);

		if(radianceModel == radianceEnum.BlinnPhong)
		{
			convolveSpecularSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Radiance/Blinn"));
		}

		if(radianceModel == radianceEnum.GGX)
		{
			convolveSpecularSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Radiance/GGX"));
		}

		convolveSpecularSkybox.SetInt("_specSamples",samples);
		convolveSpecularSkybox.SetInt("_specularSize", size);
		convolveSpecularSkybox.SetTexture("_SpecCubeIBL", specularCube);

		UnityEngine.RenderSettings.skybox = convolveSpecularSkybox;

		Cubemap tempCube = new Cubemap(size, TextureFormat.ARGB32, true);

		for(int mip = 0; (size >> mip) > 0; mip++)
		{

			// v0.035 better way to get exponent with different cubemap size
			float minExponent = 0.005f;

			float exponent = Mathf.Max( (float)specularExponent / (float)size * (float)mip, minExponent );

			/*
			float[] expVal = new float [] {
				0.01f,0.1f,0.2f,0.3f,0.4f,0.5f,0.6f,0.7f,0.8f,0.9f,1.0f
			};

			float exponent = expVal[mip];

			convolveSpecularSkybox.SetFloat("_Shininess", exponent );
			*/

			if( mip == 0 )
			{
				convolveSpecularSkybox.SetFloat("_Shininess", minExponent);
			}
			if( mip != 0 && radianceModel == radianceEnum.GGX)
			{
				convolveSpecularSkybox.SetFloat("_Shininess", exponent + 0.05f);
			}
			if( mip != 0 && radianceModel == radianceEnum.BlinnPhong)
			{
				convolveSpecularSkybox.SetFloat("_Shininess", exponent);
			}

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

			Cubemap mipCube = new Cubemap(cubeSize, TextureFormat.ARGB32, false);

			if( hasPro == true )
			{		
				cubeCamera.RenderToCubemap(mipCube);

				for(int f=0; f<6; ++f) 
				{
					CubemapFace face = (CubemapFace)f;
					tempCube.SetPixels(mipCube.GetPixels(face), face, mip);
				}

			}
			else
			{
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.PositiveZ, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.PositiveX, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.NegativeX, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.NegativeZ, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.PositiveY, cubeCamera,mip));
				yield return StartCoroutine(CaptureImportanceSample(tempCube, CubemapFace.NegativeY, cubeCamera,mip));
			}
		}

		// v0.035 this fix the ugly mipmap transition
		tempCube.filterMode = FilterMode.Trilinear;
		tempCube.wrapMode = TextureWrapMode.Clamp;

		if (SystemInfo.graphicsShaderLevel != 50)
		{
			tempCube.SmoothEdges(smoothEdge);
		}

		tempCube.Apply(false);

		specularCube = tempCube;

		string convolvedSpecularPath = GetOutPutPath(specularCube,false);
	
		AssetDatabase.CreateAsset(specularCube, convolvedSpecularPath);
		SerializedObject serializedCubemap = new SerializedObject(specularCube);
		SetLinearSpace(ref serializedCubemap, false);

		yield return StartCoroutine(CaptureFinished());
	}
コード例 #15
0
ファイル: LuxCubeProcessor.cs プロジェクト: Backman/Hellbound
    void FakeHDR (Cubemap CubeMap, bool hasmipLevels) {
	    int maxMipLevels = 1;
	    if (hasmipLevels) {
		    maxMipLevels = (int)(Mathf.Log((float)CubeMap.width, 2.0f)) + 1;
	    }
	    int base_Size = CubeMap.width;
	    Vector4 rgbmColor = new Vector4();

	    for (int mipLevel = 0; mipLevel < maxMipLevels; mipLevel++)
	    {
		    int a_Size = base_Size >> mipLevel;
		    // As we use a_Size as pointer in our arrays we have to lower it by 1
		    //a_Size -= 1;


		    for (int a_FaceIdx = 0; a_FaceIdx < 6; a_FaceIdx++)
		    {
			    // Get all pixels of the given face
			    Color[] FaceColors = CubeMap.GetPixels((CubemapFace)a_FaceIdx, mipLevel);
			    // Iterate over dst cube map face texel
			    for (int a_V  = 0; a_V < a_Size; a_V++)
			    {
				    for (int a_U = 0; a_U < a_Size; a_U++)
				    {
					    rgbmColor.x = FaceColors[a_V * a_Size + a_U].r;
					    rgbmColor.y = FaceColors[a_V * a_Size + a_U].g;
					    rgbmColor.z = FaceColors[a_V * a_Size + a_U].b;
					    rgbmColor *= 1.0f/6.0f;
					    rgbmColor.w = Mathf.Clamp01(Mathf.Max(Mathf.Max(rgbmColor.x, rgbmColor.y), rgbmColor.z));
					    rgbmColor.w = Mathf.Ceil(rgbmColor.w*255.0f) / 255.0f;
					    rgbmColor.x = rgbmColor.x / rgbmColor.w;
					    rgbmColor.y = rgbmColor.y / rgbmColor.w;
					    rgbmColor.z = rgbmColor.z / rgbmColor.w;
					    FaceColors[a_V * a_Size + a_U] = rgbmColor;
				    }
			    }
			    CubeMap.SetPixels(FaceColors,(CubemapFace)a_FaceIdx, mipLevel);
		    }
	    }
	    CubeMap.Apply(false);
    }
コード例 #16
0
ファイル: PanoramaToCubemap.cs プロジェクト: koko11/MatrixVR
	/**
	 * キューブマップの作成.
	 */
	private void m_CreateCubemap() {
		if (m_srcTexture == null) {
			EditorUtility.DisplayDialog("Error", "Please set panorama image!", "OK");
			return;
		}

		// Textureを出力するディレクトリの作成.
		if (!Directory.Exists(PanoramaToCubemap.outputImageDirectory)) {
			Directory.CreateDirectory(PanoramaToCubemap.outputImageDirectory);
		}

		int texSize = m_GetCubemapTextureSize();
		m_Cubemap = new Cubemap(texSize, TextureFormat.RGB24, false);

		if (m_dstTextureFront != null) {
			m_EnableTextureGetPixel(m_dstTextureFront, true);

			Color [] dstCols = new Color[texSize * texSize];

			int iPos = 0;
			for (int y = 0; y < texSize; y++) {
				Color [] srcLines = m_dstTextureFront.GetPixels(0, texSize - y - 1, texSize, 1);
				for (int x = 0; x < texSize; x++) {
					dstCols[iPos + x] = srcLines[x];
				}
				iPos += texSize;
			}
			m_Cubemap.SetPixels(dstCols, CubemapFace.PositiveZ);

			m_EnableTextureGetPixel(m_dstTextureFront, false);
		}
		if (m_dstTextureBack != null) {
			m_EnableTextureGetPixel(m_dstTextureBack, true);

			Color [] dstCols = new Color[texSize * texSize];
			
			int iPos = 0;
			for (int y = 0; y < texSize; y++) {
				Color [] srcLines = m_dstTextureBack.GetPixels(0, texSize - y - 1, texSize, 1);
				for (int x = 0; x < texSize; x++) {
					dstCols[iPos + x] = srcLines[x];
				}
				iPos += texSize;
			}
			m_Cubemap.SetPixels(dstCols, CubemapFace.NegativeZ);

			m_EnableTextureGetPixel(m_dstTextureBack, false);
		}
		if (m_dstTextureLeft != null) {
			m_EnableTextureGetPixel(m_dstTextureLeft, true);

			Color [] dstCols = new Color[texSize * texSize];
			
			int iPos = 0;
			for (int y = 0; y < texSize; y++) {
				Color [] srcLines = m_dstTextureLeft.GetPixels(0, texSize - y - 1, texSize, 1);
				for (int x = 0; x < texSize; x++) {
					dstCols[iPos + x] = srcLines[x];
				}
				iPos += texSize;
			}
			m_Cubemap.SetPixels(dstCols, CubemapFace.PositiveX);

			m_EnableTextureGetPixel(m_dstTextureLeft, false);
		}
		if (m_dstTextureRight != null) {
			m_EnableTextureGetPixel(m_dstTextureRight, true);

			Color [] dstCols = new Color[texSize * texSize];
			
			int iPos = 0;
			for (int y = 0; y < texSize; y++) {
				Color [] srcLines = m_dstTextureRight.GetPixels(0, texSize - y - 1, texSize, 1);
				for (int x = 0; x < texSize; x++) {
					dstCols[iPos + x] = srcLines[x];
				}
				iPos += texSize;
			}
			m_Cubemap.SetPixels(dstCols, CubemapFace.NegativeX);

			m_EnableTextureGetPixel(m_dstTextureRight, false);
		}
		if (m_dstTextureUp != null) {
			m_EnableTextureGetPixel(m_dstTextureUp, true);

			Color [] dstCols = new Color[texSize * texSize];
			
			int iPos = 0;
			for (int y = 0; y < texSize; y++) {
				Color [] srcLines = m_dstTextureUp.GetPixels(0, texSize - y - 1, texSize, 1);
				for (int x = 0; x < texSize; x++) {
					dstCols[iPos + x] = srcLines[x];
				}
				iPos += texSize;
			}
			m_Cubemap.SetPixels(dstCols, CubemapFace.PositiveY);

			m_EnableTextureGetPixel(m_dstTextureUp, false);
		}
		if (m_dstTextureDown != null) {
			m_EnableTextureGetPixel(m_dstTextureDown, true);

			Color [] dstCols = new Color[texSize * texSize];
			
			int iPos = 0;
			for (int y = 0; y < texSize; y++) {
				Color [] srcLines = m_dstTextureDown.GetPixels(0, texSize - y - 1, texSize, 1);
				for (int x = 0; x < texSize; x++) {
					dstCols[iPos + x] = srcLines[x];
				}
				iPos += texSize;
			}
			m_Cubemap.SetPixels(dstCols, CubemapFace.NegativeY);

			m_EnableTextureGetPixel(m_dstTextureDown, false);
		}
		m_Cubemap.Apply();

		string fileName = outputImageDirectory + "/" + m_srcTexture.name + ".cubemap";
		AssetDatabase.CreateAsset(m_Cubemap, fileName);

		Selection.activeObject = m_Cubemap;
	}
コード例 #17
0
		static public void BuildCubeMap (string name, int [][][] cube) {
			int size = cube.Length;

			Color[] upPixels = new Color [size * size];
			Color[] downPixels = new Color [size * size];
			Color[] rightPixels = new Color [size * size];
			Color[] leftPixels = new Color [size * size];
			Color[] forwardPixels = new Color [size * size];
			Color[] backPixels = new Color [size * size];

			float h = 0;

			for (int i = 0; i < size; i++) {
				for (int j = 0; j < size; j++) {
					h = cube [size - 1 - j][size - 1][size - 1 - i];
					upPixels [size * size - 1 - (j + i * size)] = new Color (h/255f, h/255f, h/255f, 1f);
					
					h = cube [size - 1 - j][0][i];
					downPixels [size * size - 1 - (j + i * size)] = new Color (h/255f, h/255f, h/255f, 1f);
					
					h = cube [size - 1][i][j];
					rightPixels [size * size - 1 - (j + i * size)] = new Color (h/255f, h/255f, h/255f, 1f);
					
					h = cube [0][i][size - 1 - j];
					leftPixels [size * size - 1 - (j + i * size)] = new Color (h/255f, h/255f, h/255f, 1f);
					
					h = cube [size - 1 - j][i][size - 1];
					forwardPixels [size * size - 1 - (j + i * size)] = new Color (h/255f, h/255f, h/255f, 1f);
					
					h = cube [j][i][0];
					backPixels [size * size - 1 - (j + i * size)] = new Color (h/255f, h/255f, h/255f, 1f);
				}
			}

			Cubemap cubeMap = new Cubemap (size, TextureFormat.RGBA32, false);
			cubeMap.SetPixels (upPixels, CubemapFace.PositiveY);
			cubeMap.SetPixels (downPixels, CubemapFace.NegativeY);
			cubeMap.SetPixels (rightPixels, CubemapFace.PositiveX);
			cubeMap.SetPixels (leftPixels, CubemapFace.NegativeX);
			cubeMap.SetPixels (forwardPixels, CubemapFace.PositiveZ);
			cubeMap.SetPixels (backPixels, CubemapFace.NegativeZ);

			AssetDatabase.CreateAsset (cubeMap, "Assets/PlanetBuilder/Resources/CubeMapGenerator/Cubemaps/" + name + ".asset");
		}
コード例 #18
0
ファイル: Util.cs プロジェクト: randydijkstra/Oculus-Reality
 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);
 }
コード例 #19
0
        private void blurCubeCallback(object data)
        {
            Cubemap tempCube = new Cubemap(this.cube.width, TextureFormat.ARGB32, false);
            for(int i=0; i<6; ++i) {
                CubemapFace face = (CubemapFace)i;
                tempCube.SetPixels(this.cube.GetPixels(face), face);
            }
            tempCube.Apply(false);
            mset.AssetUtil.setLinear(new SerializedObject(tempCube), false);

            mset.SkyProbe p = new mset.SkyProbe();
            p.maxExponent = (int)data;
            p.convolutionScale = 1f;
            p.highestMipIsMirror = false;
            p.generateMipChain = false;
            bool linear = UnityEditor.PlayerSettings.colorSpace == ColorSpace.Linear;

            Undo.RegisterCompleteObjectUndo(this.cube, "cubemap blur");
            p.blur(this.cube, tempCube, this.HDR, this.HDR, linear);
            queuedPath = fullPath;
        }
コード例 #20
0
    void Render(GameObject lightShapeObjTemp, GameObject lightShapeObjTempAlt, GameObject groundShapeObjTemp, Material gMat, Material lsMat, Material alsMat )
    {
        if(!LightShapeManager.useAltMethod)
        {
            TurnOffCubes();
            var cubeCamera = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
            cubeCamera.tag = "LightShapeObject";
            var cubeCam = cubeCamera.GetComponent("Camera") as Camera;
            cubeCam.nearClipPlane = 0.001f;
            cubeCam.farClipPlane = 1000f;
            cubeCam.cullingMask = 1 << 0;

            if(!LightShapeManager.worldCamera)
            {
                cubeCam.backgroundColor = BGColor;
            }

            if(LightShapeManager.worldCamera)
            {
                if(!RenderSettings.skybox)
                {
                    if(!overrideCameraColor)
                    {
                        cubeCam.backgroundColor = LightShapeManager.worldCamera.backgroundColor;
                    }

                    if(overrideCameraColor)
                    {
                        cubeCam.backgroundColor = BGColor;
                    }
                }

                if(RenderSettings.skybox)
                {
                    if(!overrideCameraColor)
                    {
                        cubeCam.clearFlags = CameraClearFlags.Skybox;
                    }
                    if(overrideCameraColor)
                    {
                        cubeCam.clearFlags = CameraClearFlags.SolidColor;
                        cubeCam.backgroundColor = BGColor;
                    }
                }
            }

            cubeCamera.transform.position = transform.position;
            cubeCamera.transform.rotation = Quaternion.identity;

            var cubeCamera2 = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
            cubeCamera2.tag = "LightShapeObject";
            var cubeCam2 = cubeCamera2.GetComponent("Camera") as Camera;
            cubeCam2.clearFlags = CameraClearFlags.SolidColor;
            cubeCam2.cullingMask = 2 << 0;

            cubeCam2.backgroundColor = Color.black;

            cubeCamera2.transform.position = cubeCamera.transform.position;
            cubeCamera2.transform.rotation = cubeCamera.transform.rotation;

            var tempFull = new Cubemap (LightShapeManager.CubeMapSize, TextureFormat.RGB24, LightShapeManager.hasMips) as Cubemap;
            cubeCamera.GetComponent<Camera>().RenderToCubemap( tempFull );
            cubeCam2.nearClipPlane = 0.001f;
            var tempFull2 = new Cubemap (LightShapeManager.CubeMapSize, TextureFormat.RGB24, LightShapeManager.hasMips) as Cubemap;
            cubeCamera2.GetComponent<Camera>().RenderToCubemap( tempFull2 );

            CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveY);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.PositiveY);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveY);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeY);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.NegativeY);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeY);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveX);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.PositiveX);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveX);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeX);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.NegativeX);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeX);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveZ);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.PositiveZ);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveZ);
            tempFull.Apply();

            CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeZ);
            CubeMapColors2 = tempFull2.GetPixels(CubemapFace.NegativeZ);

            SetPixels(CubeMapColors, CubeMapColors2);

            tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeZ);
            tempFull.Apply();

            if(lightShapeObjTemp)
            {
                DestroyImmediate(lightShapeObjTemp.gameObject);
                DestroyImmediate(lsMat);
            }

            if(lightShapeObjTempAlt)
            {
                DestroyImmediate(lightShapeObjTempAlt.gameObject);
                DestroyImmediate(alsMat);
            }

            DestroyImmediate( cubeCamera );
            DestroyImmediate( tempFull2 );
            DestroyImmediate( cubeCamera2 );

            if(hasGround)
            {
                var cubeCamera3 = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
                cubeCamera3.tag = "LightShapeObject";
                var cubeCam3 = cubeCamera3.GetComponent("Camera") as Camera;
                cubeCam3.clearFlags = CameraClearFlags.SolidColor;
                cubeCam3.aspect = 1.0f;
                cubeCam3.cullingMask = 2 << 0;
                cubeCam3.nearClipPlane = 0.001f;
                cubeCam3.farClipPlane = 5f;
                cubeCam3.backgroundColor = Color.white;

                cubeCamera3.transform.position = transform.position;
                cubeCamera3.transform.rotation = transform.rotation;
                var tempFull3 = new Cubemap (LightShapeManager.CubeMapSize, TextureFormat.RGB24, false) as Cubemap;
                cubeCamera3.GetComponent<Camera>().RenderToCubemap( tempFull3 );

                //1
                CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveY);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.PositiveY);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveY);
                tempFull.Apply();

                //2
                CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeY);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.NegativeY);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeY);
                tempFull.Apply();

                //3
                CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveX);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.PositiveX);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveX);
                tempFull.Apply();

                //4
                CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeX);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.NegativeX);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeX);
                tempFull.Apply();
                //5
                CubeMapColors = tempFull.GetPixels(CubemapFace.PositiveZ);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.PositiveZ);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.PositiveZ);
                tempFull.Apply();
                //6
                CubeMapColors = tempFull.GetPixels(CubemapFace.NegativeZ);
                CubeMapColors3 = tempFull3.GetPixels(CubemapFace.NegativeZ);

                SetGround(CubeMapColors, CubeMapColors3);

                tempFull.SetPixels(CubeMapColors, CubemapFace.NegativeZ);
                tempFull.Apply();

                //
                DestroyImmediate( tempFull3 );
                DestroyImmediate( cubeCamera3 );
            }

            if(groundShapeObjTemp)
            {
                DestroyImmediate(groundShapeObjTemp.gameObject);
                DestroyImmediate(gMat);
            }

            AssetDatabase.CreateAsset(tempFull, LightShapeManager.savePath + LightShapeManager.folderName + "/Cube_" + LightShapeManager.CubeMapSize + "_" + (myIndex + 1) + ".cubemap");

            myCubeMap = AssetDatabase.LoadAssetAtPath(LightShapeManager.savePath + LightShapeManager.folderName + "/Cube_" + LightShapeManager.CubeMapSize + "_" + (myIndex + 1) + ".cubemap", typeof(Cubemap)) as Cubemap;

            List<Color> oldColors = new List<Color>(CubeMapColors);
            oldColors.Clear();
            CubeMapColors = oldColors.ToArray();
            CubeMapColors2 = oldColors.ToArray();
            CubeMapColors3 = oldColors.ToArray();
            CubeMapColorsR = oldColors.ToArray();

            UpdateCubeMaps();
        }

        if(LightShapeManager.useAltMethod)
        {
            TurnOffCubes();

            if(!LightShapeManager.renderingCubeMaps)
            {
                LightShapeManager.curProbeInt = myIndex;
            }

            AltMethod.StartRender();
        }

        EditorUtility.UnloadUnusedAssets();

        if(!LightShapeManager.renderingCubeMaps)
        {
            Debug.Log(LightShapeManager.rewardStrings[rewardInt] + " CubeMap Rendered!");
        }
    }
コード例 #21
0
ファイル: LuxCubeProcessor.cs プロジェクト: Backman/Hellbound
    //--------------------------------------------------------------------------------------
    // Fixup cube edges

    void FixupCubeEdges (Cubemap CubeMap)
    {
	    int maxMipLevels = (int)(Mathf.Log((float)CubeMap.width, 2.0f)) + 1;
	    int base_Size = CubeMap.width;
	
	    // Do not perform any edge fixed for mip level 0
	    for (int mipLevel = 1; mipLevel < maxMipLevels; mipLevel++)
	    {
		    // declare jagged array for all faces and init its child arrays
		    Color[][] PixelsOfAllFaces = new Color[6][];
		    PixelsOfAllFaces[0] = CubeMap.GetPixels(CubemapFace.PositiveX, mipLevel);
		    PixelsOfAllFaces[1] = CubeMap.GetPixels(CubemapFace.NegativeX, mipLevel);
		    PixelsOfAllFaces[2] = CubeMap.GetPixels(CubemapFace.PositiveY, mipLevel);
		    PixelsOfAllFaces[3] = CubeMap.GetPixels(CubemapFace.NegativeY, mipLevel);
		    PixelsOfAllFaces[4] = CubeMap.GetPixels(CubemapFace.PositiveZ, mipLevel);
		    PixelsOfAllFaces[5] = CubeMap.GetPixels(CubemapFace.NegativeZ, mipLevel);

		    int a_Size = base_Size >> mipLevel;
		    // As we use a_Size as pointer in our arrays we have to lower it by 1
		    a_Size -= 1;


		    int a_FixupWidth = 3;
		    int fixupDist = (int)Mathf.Min( a_FixupWidth, a_Size / 2);

		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[0,0]], PixelsOfAllFaces[sg_CubeCornerList[0,1]], PixelsOfAllFaces[sg_CubeCornerList[0,2]], 0, 0, a_Size, a_Size, a_Size, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[1,0]], PixelsOfAllFaces[sg_CubeCornerList[1,1]], PixelsOfAllFaces[sg_CubeCornerList[1,2]], a_Size, 0, a_Size, 0, 0, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[2,0]], PixelsOfAllFaces[sg_CubeCornerList[2,1]], PixelsOfAllFaces[sg_CubeCornerList[2,2]], 0, a_Size, a_Size, 0, a_Size, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[3,0]], PixelsOfAllFaces[sg_CubeCornerList[3,1]], PixelsOfAllFaces[sg_CubeCornerList[3,2]], a_Size, a_Size, a_Size, a_Size, 0, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[4,0]], PixelsOfAllFaces[sg_CubeCornerList[4,1]], PixelsOfAllFaces[sg_CubeCornerList[4,2]], a_Size, 0, 0, a_Size, 0, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[5,0]], PixelsOfAllFaces[sg_CubeCornerList[5,1]], PixelsOfAllFaces[sg_CubeCornerList[5,2]], 0, 0, 0, 0, a_Size, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[6,0]], PixelsOfAllFaces[sg_CubeCornerList[6,1]], PixelsOfAllFaces[sg_CubeCornerList[6,2]], a_Size, a_Size, 0, 0, 0, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[7,0]], PixelsOfAllFaces[sg_CubeCornerList[7,1]], PixelsOfAllFaces[sg_CubeCornerList[7,2]], 0, a_Size, 0, a_Size, a_Size, a_Size);

		    // Perform 2nd iteration in reverse order

		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[7,0]], PixelsOfAllFaces[sg_CubeCornerList[7,1]], PixelsOfAllFaces[sg_CubeCornerList[7,2]], 0, a_Size, 0, a_Size, a_Size, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[6,0]], PixelsOfAllFaces[sg_CubeCornerList[6,1]], PixelsOfAllFaces[sg_CubeCornerList[6,2]], a_Size, a_Size, 0, 0, 0, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[5,0]], PixelsOfAllFaces[sg_CubeCornerList[5,1]], PixelsOfAllFaces[sg_CubeCornerList[5,2]], 0, 0, 0, 0, a_Size, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[4,0]], PixelsOfAllFaces[sg_CubeCornerList[4,1]], PixelsOfAllFaces[sg_CubeCornerList[4,2]], a_Size, 0, 0, a_Size, 0, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[3,0]], PixelsOfAllFaces[sg_CubeCornerList[3,1]], PixelsOfAllFaces[sg_CubeCornerList[3,2]], a_Size, a_Size, a_Size, a_Size, 0, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[2,0]], PixelsOfAllFaces[sg_CubeCornerList[2,1]], PixelsOfAllFaces[sg_CubeCornerList[2,2]], 0, a_Size, a_Size, 0, a_Size, a_Size);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[1,0]], PixelsOfAllFaces[sg_CubeCornerList[1,1]], PixelsOfAllFaces[sg_CubeCornerList[1,2]], a_Size, 0, a_Size, 0, 0, 0);
		    AverageCorner(a_Size, PixelsOfAllFaces[sg_CubeCornerList[0,0]], PixelsOfAllFaces[sg_CubeCornerList[0,1]], PixelsOfAllFaces[sg_CubeCornerList[0,2]], 0, 0, a_Size, a_Size, a_Size, 0);

	

		    // Average Edges
		    // Note that this loop does not process the corner texels, since they have already been averaged
		    for (int i = 1; i < (a_Size - 1); i++)
		    {
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[0,0]], PixelsOfAllFaces[sg_CubeEdgeList[0,1]], i, 0, a_Size, a_Size - i, fixupDist, new Vector4(0, 1, -1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[1,0]], PixelsOfAllFaces[sg_CubeEdgeList[1,1]], i, a_Size, a_Size, i, fixupDist, new Vector4(0, -1, -1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[2,0]], PixelsOfAllFaces[sg_CubeEdgeList[2,1]], 0, i, a_Size, i, fixupDist, new Vector4(1, 0, -1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[3,0]], PixelsOfAllFaces[sg_CubeEdgeList[3,1]], a_Size, i, 0, i, fixupDist, new Vector4(-1, 0, 1, 0) );
			
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[4,0]], PixelsOfAllFaces[sg_CubeEdgeList[4,1]], i, 0, 0, i, fixupDist, new Vector4(0, 1, 1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[5,0]], PixelsOfAllFaces[sg_CubeEdgeList[5,1]], i, a_Size, 0, a_Size - i, fixupDist, new Vector4(0, -1, 1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[6,0]], PixelsOfAllFaces[sg_CubeEdgeList[6,1]], a_Size, i, 0, i, fixupDist, new Vector4(-1, 0, 1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[7,0]], PixelsOfAllFaces[sg_CubeEdgeList[7,1]], 0, i, a_Size, i, fixupDist, new Vector4(1, 0, -1, 0) );
			
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[8,0]], PixelsOfAllFaces[sg_CubeEdgeList[8,1]], i, a_Size, i, 0, fixupDist, new Vector4(0, -1, 0, 1) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[9,0]], PixelsOfAllFaces[sg_CubeEdgeList[9,1]], i, 0, a_Size - i, 0, fixupDist, new Vector4(0, 1, 0, 1) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[10,0]], PixelsOfAllFaces[sg_CubeEdgeList[10,1]], i, 0, i, a_Size, fixupDist, new Vector4(0, 1, 0, -1) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[11,0]], PixelsOfAllFaces[sg_CubeEdgeList[11,1]], i, a_Size, a_Size - i, a_Size, fixupDist, new Vector4(0, -1, 0, -1) );
		
		    }
		    // Perform 2nd iteration in reverse order
	    /*	for (int i = 0; i < (a_Size); i++)
		    {
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[11,0]], PixelsOfAllFaces[sg_CubeEdgeList[11,1]], i, a_Size, a_Size - i, a_Size, fixupDist, new Vector4(0, -1, 0, -1) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[10,0]], PixelsOfAllFaces[sg_CubeEdgeList[10,1]], i, 0, i, a_Size, fixupDist, new Vector4(0, 1, 0, -1) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[9,0]], PixelsOfAllFaces[sg_CubeEdgeList[9,1]], i, 0, a_Size - i, 0, fixupDist, new Vector4(0, 1, 0, 1) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[8,0]], PixelsOfAllFaces[sg_CubeEdgeList[8,1]], i, a_Size, i, 0, fixupDist, new Vector4(0, -1, 0, 1) );
			
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[7,0]], PixelsOfAllFaces[sg_CubeEdgeList[7,1]], 0, i, a_Size, i, fixupDist, new Vector4(1, 0, -1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[6,0]], PixelsOfAllFaces[sg_CubeEdgeList[6,1]], a_Size, i, 0, i, fixupDist, new Vector4(-1, 0, 1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[5,0]], PixelsOfAllFaces[sg_CubeEdgeList[5,1]], i, a_Size, 0, a_Size - i, fixupDist, new Vector4(0, -1, 1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[4,0]], PixelsOfAllFaces[sg_CubeEdgeList[4,1]], i, 0, 0, i, fixupDist, new Vector4(0, 1, 1, 0) );	
			
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[3,0]], PixelsOfAllFaces[sg_CubeEdgeList[3,1]], a_Size, i, 0, i, fixupDist, new Vector4(-1, 0, 1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[2,0]], PixelsOfAllFaces[sg_CubeEdgeList[2,1]], 0, i, a_Size, i, fixupDist, new Vector4(1, 0, -1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[1,0]], PixelsOfAllFaces[sg_CubeEdgeList[1,1]], i, a_Size, a_Size, i, fixupDist, new Vector4(0, -1, -1, 0) );
			    AverageEdge(a_Size, PixelsOfAllFaces[sg_CubeEdgeList[0,0]], PixelsOfAllFaces[sg_CubeEdgeList[0,1]], i, 0, a_Size, a_Size - i, fixupDist, new Vector4(0, 1, -1, 0) );
		    } */

		

		    // Write Pixel from the jagged array back to the cubemap faces
		    for (int writeFace = 0; writeFace < 6; writeFace++ ) {
			    Color[] tempColors = PixelsOfAllFaces[writeFace];
			    CubeMap.SetPixels(tempColors, (CubemapFace)writeFace, mipLevel);
		    }
	    }
	    CubeMap.Apply(false); 
    }
コード例 #22
0
ファイル: LuxCubeProcessor.cs プロジェクト: Backman/Hellbound
    //--------------------------------------------------------------------------------------
    // 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");
    }
コード例 #23
0
        /**
         * Post-load initialisation.
         */
        public void load()
        {
            Texture2D[] envMapFaces = new Texture2D[6];

              foreach (GameDatabase.TextureInfo texInfo in GameDatabase.Instance.databaseTexture)
              {
            Texture2D texture = texInfo.texture;
            if (texture == null || !texture.name.StartsWith(DIR_ENVMAP, System.StringComparison.Ordinal))
              continue;

            string originalName = texture.name.Substring(DIR_ENVMAP.Length);

            switch (originalName)
            {
              case "PositiveX":
            envMapFaces[0] = texture;
            break;
              case "NegativeX":
            envMapFaces[1] = texture;
            break;
              case "PositiveY":
            envMapFaces[2] = texture;
            break;
              case "NegativeY":
            envMapFaces[3] = texture;
            break;
              case "PositiveZ":
            envMapFaces[4] = texture;
            break;
              case "NegativeZ":
            envMapFaces[5] = texture;
            break;
              default:
            Util.log("Invalid enironment map texture name {0}", texture.name);
            break;
            }
              }

              // Generate generic reflection cube map texture.
              if (envMapFaces.Any(t => t == null))
              {
            Util.log("Some environment map faces are missing. Static reflections disabled.");
              }
              else
              {
            int envMapSize = envMapFaces[0].width;

            if (envMapFaces.Any(t => t.width != envMapSize || t.height != envMapSize)
            || envMapFaces.Any(t => !Util.isPow2(t.width) || !Util.isPow2(t.height)))
            {
              Util.log("Invalid environment map faces. Static reflections disabled.");
            }
            else
            {
              try
              {
            staticEnvMap = new Cubemap(envMapSize, TextureFormat.RGB24, true);
            staticEnvMap.hideFlags = HideFlags.HideAndDontSave;
            staticEnvMap.wrapMode = TextureWrapMode.Clamp;
            staticEnvMap.SetPixels(envMapFaces[0].GetPixels(), CubemapFace.PositiveX);
            staticEnvMap.SetPixels(envMapFaces[1].GetPixels(), CubemapFace.NegativeX);
            staticEnvMap.SetPixels(envMapFaces[2].GetPixels(), CubemapFace.PositiveY);
            staticEnvMap.SetPixels(envMapFaces[3].GetPixels(), CubemapFace.NegativeY);
            staticEnvMap.SetPixels(envMapFaces[4].GetPixels(), CubemapFace.PositiveZ);
            staticEnvMap.SetPixels(envMapFaces[5].GetPixels(), CubemapFace.NegativeZ);
            staticEnvMap.Apply(true, false);

            Util.log("Static environment map cube texture generated.");
              }
              catch (UnityException)
              {
            if (staticEnvMap != null)
              Object.DestroyImmediate(staticEnvMap);

            staticEnvMap = null;

            Util.log("Failed to set up static reflections. Textures not readable?");
              }
            }
              }

              try
              {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Stream stream = assembly.GetManifestResourceStream("TextureReplacer.Visor-compiled.shader");
            StreamReader reader = new StreamReader(stream);

            shaderMaterial = new Material(reader.ReadToEnd());
            visorShader = shaderMaterial.shader;

            Util.log("Visor shader sucessfully compiled.");
              }
              catch
              {
            isVisorReflectionEnabled = false;
            Util.log("Visor shader loading failed. Visor reflections disabled.");
              }

              for (int i = 0; i < SHADER_MAP.GetLength(0); ++i)
              {
            Shader original = Shader.Find(SHADER_MAP[i, 0]);
            Shader reflective = SHADER_MAP[i, 1] == visorShader.name ?
                            visorShader : Shader.Find(SHADER_MAP[i, 1]);

            if (original == null)
              Util.log("Shader \"{0}\" missing", SHADER_MAP[i, 0]);
            else if (reflective == null)
              Util.log("Shader \"{0}\" missing", SHADER_MAP[i, 1]);
            else
              shaderMap.Add(original, reflective);
              }

              setReflectionType(reflectionType);
        }
コード例 #24
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);
	}
コード例 #25
0
ファイル: CubemapProbe.cs プロジェクト: darargon/Gravity-VR
    // This is the coroutine that creates the cubemap images
    IEnumerator CreateCubeMap()
    {
        // Initialise a new cubemap
        Cubemap cm = new Cubemap(resolution, TextureFormat.RGB24, true);
        var renderer = gameObject.GetComponent<Renderer>();

        // Disable any renderers attached to this object which may get in the way of our camera
        if (renderer)
        {
            renderer.enabled = false;
        }

        // Face render order: Top, Right, Front, Bottom, Left, Back
        Quaternion[] rotations = { Quaternion.Euler(-90, 0, 0), Quaternion.Euler(0, 90, 0), Quaternion.Euler(0, 0, 0), Quaternion.Euler(90, 0, 0), Quaternion.Euler(0, -90, 0), Quaternion.Euler(0, 180, 0) };
        CubemapFace[] faces = { CubemapFace.PositiveY, CubemapFace.PositiveX, CubemapFace.PositiveZ, CubemapFace.NegativeY, CubemapFace.NegativeX, CubemapFace.NegativeZ };

        // Create a single face matching the settings of the cubemap itself
        Texture2D face = new Texture2D(resolution, resolution, TextureFormat.RGB24, true);

        // Use this to prevent white borders around edge of texture
        face.wrapMode = TextureWrapMode.Clamp;

        // Create a camera that will be used to render the faces
        GameObject go = new GameObject("CubemapCamera", typeof(Camera));

        // Place the camera on this object
        go.transform.position = transform.position;

        // Initialise the rotation - this will be changed for each texture grab
        go.transform.rotation = Quaternion.identity;

        // We need each face of the cube to cover exactly 90 degree FoV
        Camera camera = go.GetComponent<Camera>();

        camera.fieldOfView = 90;

        // Ensure this camera renders above all others
        camera.depth = float.MaxValue;

        // Loop through and create each face
        for (int i = 0; i < 6; i++)
        {
            // Set the camera direction
            go.transform.rotation = rotations[i];
            // Important - wait the frame to be fully rendered before capturing
            // See http://answers.unity3d.com/questions/326384/texture2dreadpixels-unknown-error-not-inside-drawi.html
            yield return new WaitForEndOfFrame();
            // Capture the pixels to the texture
            face = CaptureScreen();
            // Resize to the chosen resolution - cubemap faces must be square!
            face = Resize(face, resolution, resolution);
            // Flip the image across the x axis
            face = Flip(face);
            // Retrieve the pixelarray of colours for the current face
            Color[] faceColours = face.GetPixels();
            // Set the current cubemap face
            cm.SetPixels(faceColours, faces[i], 0);
            // Save the texture
            SaveTextureToFile(face, gameObject.name + "_" + faces[i].ToString() + ".png");
        }

        // Apply the SetPixel changes to the cubemap faces to make them take effect
        cm.Apply();

        // Assign the cubemap to the _Cube texture of this object's material
        if (renderer.material.HasProperty("_Cube"))
        {
            renderer.material.SetTexture("_Cube", cm);
        }

        // Cleanup
        DestroyImmediate(face);
        DestroyImmediate(go);

        // Re-enable the renderer
        if (renderer)
        {
            renderer.enabled = true;
        }
    }
コード例 #26
0
    private void CopyCubemapFace(CubemapFace face, Cubemap source, ref Cubemap target)
    {
        //Create the blank texture container
        Texture2D snapshot = new Texture2D(source.width, source.height, source.format, m_useMipMaps, false);
        snapshot.wrapMode = TextureWrapMode.Clamp;

        // Read Face Pixels into the Texture
        snapshot.SetPixels(source.GetPixels(face), 0);

        // Resize to new size
        snapshot = Scale(snapshot, m_resolution, m_resolution);

        // Finally write the contents to the new Cubemap
        target.SetPixels(snapshot.GetPixels(), face, 0);
        target.Apply();
    }
コード例 #27
0
    public static void RenderIntoCubemap(Camera ownerCamera, Cubemap outCubemap)
    {
        int width = (int)outCubemap.width;
        int height = (int)outCubemap.height;

        CubemapFace[] faces = new CubemapFace[] { CubemapFace.PositiveX, CubemapFace.NegativeX, CubemapFace.PositiveY, CubemapFace.NegativeY, CubemapFace.PositiveZ, CubemapFace.NegativeZ };
        Vector3[] faceAngles = new Vector3[] { new Vector3(0.0f, 90.0f, 0.0f), new Vector3(0.0f, -90.0f, 0.0f), new Vector3(-90.0f, 0.0f, 0.0f), new Vector3(90.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 180.0f, 0.0f) };

        // Backup states
        RenderTexture backupRenderTex = RenderTexture.active;
        float backupFieldOfView = ownerCamera.fieldOfView;
        float backupAspect = ownerCamera.aspect;
        Quaternion backupRot = ownerCamera.transform.rotation;
        //RenderTexture backupRT = ownerCamera.targetTexture;

        // Enable 8X MSAA
        RenderTexture faceTexture = new RenderTexture(width, height, 24);
        faceTexture.antiAliasing = 8;
        #if !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3)
        faceTexture.dimension = UnityEngine.Rendering.TextureDimension.Tex2D;
        #endif
        faceTexture.hideFlags = HideFlags.HideAndDontSave;

        // For intermediate saving
        Texture2D swapTex = new Texture2D(width, height, TextureFormat.RGB24, false);
        swapTex.hideFlags = HideFlags.HideAndDontSave;

        // Capture 6 Directions
        ownerCamera.targetTexture = faceTexture;
        ownerCamera.fieldOfView = 90;
        ownerCamera.aspect = 1.0f;

        Color[] mirroredPixels = new Color[swapTex.height * swapTex.width];
        for (int i = 0; i < faces.Length; i++)
        {
            ownerCamera.transform.eulerAngles = faceAngles[i];
            ownerCamera.Render();
            RenderTexture.active = faceTexture;
            swapTex.ReadPixels(new Rect(0, 0, width, height), 0, 0);

            // Mirror vertically to meet the standard of unity cubemap
            Color[] OrignalPixels = swapTex.GetPixels();
            for (int y1 = 0; y1 < height; y1++)
            {
                for (int x1 = 0; x1 < width; x1++)
                {
                    mirroredPixels[y1 * width + x1] = OrignalPixels[((height - 1 - y1) * width) + x1];
                }
            };
            outCubemap.SetPixels(mirroredPixels, faces[i]);
        }

        outCubemap.SmoothEdges();

        // Restore states
        RenderTexture.active = backupRenderTex;
        ownerCamera.fieldOfView = backupFieldOfView;
        ownerCamera.aspect = backupAspect;
        ownerCamera.transform.rotation = backupRot;
        ownerCamera.targetTexture = backupRenderTex;

        DestroyImmediate(swapTex);
        DestroyImmediate(faceTexture);
    }
コード例 #28
0
    public static void TestCubemap()
    {
        int faceSize = 8;
        Cubemap cube = new Cubemap(faceSize, TextureFormat.RGB24, false);

        // For each side
        foreach (CubemapFace face in System.Enum.GetValues(typeof(CubemapFace))) {
            Color color = FaceToColor(face);
            Color[] pixels = new Color[faceSize * faceSize];
            for (int i = 0; i < faceSize * faceSize; ++i)
                pixels[i] = color;

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

        AssetDatabase.CreateAsset(cube, "Assets/BiasedPhysics/TestCubemap.cubemap");
        Debug.Log("Generated /BiasedPhysics/TestCubemap.cubemap");
    }
コード例 #29
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;
	}