Apply() private method

private Apply ( ) : void
return void
    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");
    }
Example #2
0
 public void capture(ref Cubemap targetCube, Transform at, bool HDR)
 {
     if( targetCube == null ) return;
     GameObject go = new GameObject("_temp_probe");
     go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
     go.SetActive(true);
     Camera cam = go.AddComponent<Camera>();
     if( at != null ) {
         go.transform.position = at.position;
     }
     if(HDR) {
         Shader.EnableKeyword("MARMO_RGBM");
         Shader.DisableKeyword("MARMO_RGBA");
         Shader.SetGlobalFloat("_GlowStrength", 0f);
         Shader.SetGlobalFloat("_EmissionLM", 0f);
         cam.SetReplacementShader(Shader.Find("Hidden/Marmoset/RGBM Replacement"),"RenderType");
     }
     cam.RenderToCubemap(targetCube);
     targetCube.Apply(false);
     if(HDR) {
         cam.ResetReplacementShader();
         Shader.DisableKeyword("MARMO_RGBM");
         Shader.EnableKeyword("MARMO_RGBA");
     }
     GameObject.DestroyImmediate(go);
 }
 static public int Apply(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(bool), typeof(bool)))
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             System.Boolean      a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             self.Apply(a1, a2);
             return(0);
         }
         else if (matchType(l, 2, typeof(bool)))
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             System.Boolean      a1;
             checkType(l, 2, out a1);
             self.Apply(a1);
             return(0);
         }
         else if (matchType(l, 2))
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             self.Apply();
             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);
     }
 }
Example #4
0
 static public int Apply(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 == 1)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             self.Apply();
             pushValue(l, true);
             return(1);
         }
         else if (argc == 2)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             System.Boolean      a1;
             checkType(l, 2, out a1);
             self.Apply(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             System.Boolean      a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             self.Apply(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function Apply 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
 }
 void createPlaceHolderCube()
 {
     if( PlaceHolderCube == null ) {
         PlaceHolderCube = new Cubemap(16,TextureFormat.ARGB32,true);
         for(int face = 0; face < 6; face++) {
             for(int x = 0; x < 16; x++) {
                 for(int y = 0; y < 16; y++) {
                     PlaceHolderCube.SetPixel((CubemapFace)face, x, y, Color.black);
                 }
             }
         }
         PlaceHolderCube.Apply(true);
     }
 }
Example #6
0
        public void capture(ref Cubemap targetCube, Transform at)
        {
            if( targetCube == null ) return;
            GameObject go = new GameObject("_temp_probe");
            go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
            go.SetActive(true);
            Camera cam = go.AddComponent<Camera>();
            if( at != null ) {
                go.transform.position = at.position;
            }

            cam.RenderToCubemap(targetCube);
            targetCube.Apply(false);

            GameObject.DestroyImmediate(go);
        }
        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();
        }
        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();
        }
    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();
    }
 static public int Apply(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             self.Apply();
             pushValue(l, true);
             return(1);
         }
         else if (argc == 2)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             System.Boolean      a1;
             checkType(l, 2, out a1);
             self.Apply(a1);
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l);
             System.Boolean      a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             self.Apply(a1, a2);
             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));
     }
 }
Example #11
0
    //--------------------------------------------------------------------------------------
    // Builds a normalizer cubemap, with the texels solid angle stored in the fourth component

    void BuildNormalizerSolidAngleCubemap(int a_Size, Cubemap a_Surface)
    {
	    //a_Size = a_Surface.width;
	    int iCubeFace, u, v;
	    Vector3 a_XYZ = new Vector3(0,0,0);
	    Color[] i_CubeMapColors = new Color[a_Size*a_Size];
	    //
	    float weight = 0.0f;
	    //iterate over cube faces
	    for(iCubeFace=0; iCubeFace<6; iCubeFace++)
	    {
		    for(v=0; v< a_Size; v++)
		    {
			    for(u=0; u < a_Size; u++)
			    {
            	    // calc TexelToVect in a_XYZ
				    a_XYZ = TexelToVect(iCubeFace, (float)u, (float)v, a_Size);
				    // calc weight
        		    weight = TexelCoordSolidAngle(iCubeFace, (float)u, (float)v, a_Size);
				    // Compress a_XYZ to fit into Color
				    i_CubeMapColors[v * a_Size + u] = new Color ((a_XYZ[0]+1.0f)/2.0f, (a_XYZ[1]+1.0f)/2.0f, (a_XYZ[2]+1.0f)/2.0f, weight);
			    }         
		    }
		    // set CubemapFace
		    a_Surface.SetPixels(i_CubeMapColors, (CubemapFace)iCubeFace);
	    }
	    // set cubeMap
	    a_Surface.Apply(true);
	    // Debug.Log ("BuildNormalizerSolidAngleCubemap finished");
    }
Example #12
0
    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);
    }
Example #13
0
    //--------------------------------------------------------------------------------------
    // Irridiance Convolution based on SH

    void ConvolveIrradianceEnvironmentMap(Cubemap irrCubeMap)
    {
	    int a_Size = irrCubeMap.width;

	    Vector4[] m_NormCubeMapArray = new Vector4[a_Size*a_Size*6];
	    BuildNormalizerSolidAngleArray(a_Size, ref m_NormCubeMapArray);

	    //This is a custom implementation of D3DXSHProjectCubeMap to avoid to deal with LPDIRECT3DSURFACE9 pointer
	    //Use Sh order 2 for a total of 9 coefficient as describe in http://www.cs.berkeley.edu/~ravir/papers/envmap/
	    //accumulators are 64-bit floats in order to have the precision needed 
	    //over a summation of a large number of pixels 
	    double[] SHr = new double[25]; // NUM_SH_COEFFICIENT
	    double[] SHg = new double[25];
	    double[] SHb = new double[25];
	    double[] SHdir = new double[25];

	    double weightAccum = 0.0;
	    double weight = 0.0;

	    int startFacePtr = 0;

	    for (int iFaceIdx = 0; iFaceIdx < 6; iFaceIdx++) {

		    // read pixels of m_NormCubeMap
		    //var m_NormCubeMap_pixels  = new Color[m_NormCubeMap.width*m_NormCubeMap.height];
		    //m_NormCubeMap_pixels = m_NormCubeMap.GetPixels((CubemapFace)iFaceIdx);

		    // Pointer to the start of the given face in m_NormCubeMapArray 
		    startFacePtr = a_Size*a_Size*iFaceIdx;

		    // read all pixels of irrCubeMap
            var cubeMap_pixels = new Color[irrCubeMap.width * irrCubeMap.height];
		    cubeMap_pixels = irrCubeMap.GetPixels((CubemapFace)iFaceIdx);


			    for (int y = 0; y < a_Size; y++) {
				    for (int x = 0; x < a_Size; x++) {

					    // read normalCube single pixel
					    Vector4 m_NormCubeMap_pixel = m_NormCubeMapArray[startFacePtr + y*a_Size + x];

					    // read originalCube single pixel
					    Color cubeMap_pixel = cubeMap_pixels[y*a_Size + x];

					    // solid angle stored in 4th channel of normalizer/solid angle cube map
					    weight = m_NormCubeMap_pixel[3];
					    //weight = TexelCoordSolidAngle(iFaceIdx, (float)x, (float)y, a_Size);

					    // pointer to direction and solid angle in cube map associated with texel
					    Vector3 texelVect;
					    texelVect.x = m_NormCubeMap_pixel[0];
					    texelVect.y = m_NormCubeMap_pixel[1];
					    texelVect.z = m_NormCubeMap_pixel[2];
					    //texelVect = TexelToVect(iFaceIdx, (float)x, (float)y, a_Size);
	
					    EvalSHBasis(texelVect, ref SHdir);

					    // read original colors and convert to float64
					    double R = cubeMap_pixel[0];
					    double G = cubeMap_pixel[1];
					    double B = cubeMap_pixel[2];

					    for (int i = 0; i < 25; i++)
					    {
						    SHr[i] += R * SHdir[i] * weight;
						    SHg[i] += G * SHdir[i] * weight;
						    SHb[i] += B * SHdir[i] * weight;
					    }
					    weightAccum += weight;
			    }
		    }
	    }
	    // Normalization - The sum of solid angle should be equal to the solid angle of the sphere (4 PI), so
	    // Normalize in order our weightAccum exactly match 4 PI.
	    for (int i = 0; i < 25; ++i)
	    {
		    SHr[i] *= 4.0 * CP_PI / weightAccum;
		    SHg[i] *= 4.0 * CP_PI / weightAccum;
		    SHb[i] *= 4.0 * CP_PI / weightAccum;
	    }

	    // Second step - Generate cubemap from SH coefficient

	    // Normalized vectors per cubeface and per-texel solid angle
	    // Why do we do it a 2nd time????
	    BuildNormalizerSolidAngleArray(a_Size, ref m_NormCubeMapArray);

	    for (int iFaceIdx = 0; iFaceIdx < 6; iFaceIdx++) {

		    // Pointer to the start of the given face in m_NormCubeMapArray 
		    startFacePtr = a_Size*a_Size*iFaceIdx;

		    for (int y = 0; y < a_Size; y++) {
			    for (int x = 0; x < a_Size; x++) {
				    // read normalCube pixel
				    Vector4 m_NormCubeMap_pixel = m_NormCubeMapArray[startFacePtr + y*a_Size + x];

				    // read normalvector and pass it to EvalSHBasis to get SHdir
				    Vector3 texelVect;
				    texelVect.x = m_NormCubeMap_pixel[0];
				    texelVect.y = m_NormCubeMap_pixel[1];
				    texelVect.z = m_NormCubeMap_pixel[2];
				    //texelVect = TexelToVect(iFaceIdx, (float)x, (float)y, a_Size);

				    EvalSHBasis( texelVect, ref SHdir);

				    // set color values
				    double R = 0.0;
				    double G = 0.0;
				    double B = 0.0;
				
				    for (int i = 0; i < 25; ++i)
				    {
					    R += (SHr[i] * SHdir[i] * SHBandFactor[i]);
					    G += (SHg[i] * SHdir[i] * SHBandFactor[i]);
					    B += (SHb[i] * SHdir[i] * SHBandFactor[i]);
				    }
				    // Lux needs alpha!
				    irrCubeMap.SetPixel((CubemapFace)iFaceIdx, x, y, new Color((float)R,(float)G,(float)B, 1.0f ));
			    }
		    }
	    }
	    irrCubeMap.Apply();
    }
Example #14
0
    //--------------------------------------------------------------------------------------
    // 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); 
    }
Example #15
0
	// This is the coroutine that creates the cubemap images
	IEnumerator CreateCubeMap(bool diffuse)
	{

		int size;
		if(diffuse == true)
		{
			size = CubeSizeSetup(true);
		}
		else
		{
			size = CubeSizeSetup(false);
		}

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

		if( hasPro == false )
		{		
			cubeCamera.RenderToCubemap(tempCube);
		}
		else
		{
			yield return StartCoroutine(Capture(tempCube, CubemapFace.PositiveZ, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.PositiveX, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.NegativeX, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.NegativeZ, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.PositiveY, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.NegativeY, cubeCamera));
		}

		// 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();

		if(diffuse == true)
		{
			diffuseCube = tempCube;

			string diffusePath = GetOutPutPath(diffuseCube,true);

			AssetDatabase.CreateAsset(diffuseCube, diffusePath);
			SerializedObject serializedCubemap = new SerializedObject(diffuseCube);
			SetLinearSpace(ref serializedCubemap, false);
		}
		else
		{
			specularCube = tempCube;

			string specularPath = GetOutPutPath(specularCube,false);

			AssetDatabase.CreateAsset(specularCube, specularPath);
			SerializedObject serializedCubemap = new SerializedObject(specularCube);
			SetLinearSpace(ref serializedCubemap, false);
		}
		/*
		// Re-enable the renderer
		if(renderer) 
		{
			renderer.enabled = true;
		}
*/
		yield return StartCoroutine(CaptureFinished());
	}
Example #16
0
    private void RemakeCubemap(ref Cubemap originalCubemap)
    {
        Cubemap c = new Cubemap(m_resolution, originalCubemap.format, m_useMipMaps);

        CubemapFace face = CubemapFace.PositiveX;
        for (int i = 0; i < 6; i++)
        {
            switch (i)
            {
                case 0: face = CubemapFace.PositiveX; break;
                case 1: face = CubemapFace.PositiveY; break;
                case 2: face = CubemapFace.PositiveZ; break;
                case 3: face = CubemapFace.NegativeX; break;
                case 4: face = CubemapFace.NegativeY; break;
                case 5: face = CubemapFace.NegativeZ; break;
            }

            CopyCubemapFace(face, originalCubemap, ref c);
        }

        c.mipMapBias = originalCubemap.mipMapBias;
        c.Apply();

        string pathToOriginalCubemap = AssetDatabase.GetAssetPath(originalCubemap);
        AssetDatabase.CreateAsset(c, pathToOriginalCubemap);
        AssetDatabase.Refresh();

        // Assign the new Cubemap again for User convience
        m_Cubemap = c; 

        // Linear Space if wanted
        SerializedObject serializedCubemap = new SerializedObject(m_Cubemap);
        CubemapHelpers.setLinear(ref serializedCubemap, m_useLinearSpace);
    }
Example #17
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);
            }
        }
    }
Example #18
0
	IEnumerator ConvolveDiffuseCubeMap()
	{
		int size = 0;
		int samples = 0;
		size = CubeSizeSetup(true);
		samples = qualitySetup(true);

		if(irradianceModel == irradianceEnum.SphereUniform)
		{
			convolveDiffuseSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Irradiance/Sphere"));
		}
		if(irradianceModel == irradianceEnum.HemisphereUniform)
		{
			convolveDiffuseSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Irradiance/Hemisphere"));
		}
		if(irradianceModel == irradianceEnum.HemisphereCosine)
		{
			convolveDiffuseSkybox = new Material(Shader.Find("Hidden/Antonov Suit/Irradiance/Cosine"));
		}

		convolveDiffuseSkybox.SetInt("_diffSamples",samples);
		convolveDiffuseSkybox.SetInt("_diffuseSize", size);
		convolveDiffuseSkybox.SetTexture("_DiffCubeIBL", diffuseCube);

		UnityEngine.RenderSettings.skybox = convolveDiffuseSkybox;
			
		Cubemap tempCube = new Cubemap(size, TextureFormat.ARGB32, false);

		if( hasPro == true )
		{		
			cubeCamera.RenderToCubemap(tempCube);
		}
		else
		{
			yield return StartCoroutine(Capture(tempCube, CubemapFace.PositiveZ, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.PositiveX, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.NegativeX, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.NegativeZ, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.PositiveY, cubeCamera));
			yield return StartCoroutine(Capture(tempCube, CubemapFace.NegativeY, cubeCamera));
		}

		tempCube.Apply();

		diffuseCube = tempCube;

		string convolvedDiffusePath = GetOutPutPath(diffuseCube,true);
			
		AssetDatabase.CreateAsset(diffuseCube, convolvedDiffusePath);
		SerializedObject serializedCubemap = new SerializedObject(diffuseCube);
		SetLinearSpace(ref serializedCubemap, false);

		yield return StartCoroutine(CaptureFinished());
	}
Example #19
0
	IEnumerator ScreenCapture()
	{
		Transform cam = camera.transform;
		
		while(isTakingScreenshots)
		{
			// Loop through each node
			for(int a=0; a<nodes.Length; a++)
			{
				// Make sure this Node is set to allow generation of either cubemaps or PNGs
				// Ignore the Allow parameter if we have no cubemap assigned yet at all
				if(nodes[a].allowCubemapGeneration || nodes[a].allowGeneratePNG || (!nodes[a].allowCubemapGeneration && nodes[a].cubemap == null) )
				{					
					// Set Camera
					cam.position = nodes[a].transform.position;				
					cam.rotation = Quaternion.identity;
					
					// Set resolution because Node may override
					SetNodeResolution(nodes[a]);
					
					// Make cubemap
					Cubemap cubemap = new Cubemap(nodeResolution, textureFormat, useMipMaps);
                    cubemap.mipMapBias = mipMapBias;

					// Loop through all Directions to take screenshots for this node
					for(int b=0; b<6; b++)
					{
						//Debug.Log("Processing Node " + nodes[a].name + " in Direction " + currentDir);
						
						switch(currentDir)
						{
							case DIR.Right:
								cam.rotation = Quaternion.Euler(0, 90, 0);						
								yield return StartCoroutine(MakeSnapshot(cubemap, CubemapFace.PositiveX, nodes[a]));
								currentDir = DIR.Left;
								break;
							
							case DIR.Left:
								cam.rotation = Quaternion.Euler(0, -90, 0);
								yield return StartCoroutine(MakeSnapshot(cubemap, CubemapFace.NegativeX, nodes[a]));
								currentDir = DIR.Top;
								break;
							
							case DIR.Top:
								cam.rotation = Quaternion.Euler(-90, 0, 0);
								yield return StartCoroutine(MakeSnapshot(cubemap, CubemapFace.PositiveY, nodes[a]));
								currentDir = DIR.Bottom;
								break;
							
							case DIR.Bottom:
								cam.rotation = Quaternion.Euler(90, 0, 0);
								yield return StartCoroutine(MakeSnapshot(cubemap, CubemapFace.NegativeY, nodes[a]));
								currentDir = DIR.Front;
								break;
							
							case DIR.Front:
								cam.rotation = Quaternion.Euler(0, 0, 0);
								yield return StartCoroutine(MakeSnapshot(cubemap, CubemapFace.PositiveZ, nodes[a]));
								currentDir = DIR.Back;
								break;
							
							case DIR.Back:
								cam.rotation = Quaternion.Euler(0, 180, 0);
								yield return StartCoroutine(MakeSnapshot(cubemap, CubemapFace.NegativeZ, nodes[a]));
								currentDir = DIR.Right; // back to the beginning (or else it gets stuck)
								break;
						}
                    }

#if !UNITY_2_6 && !UNITY_2_6_1 && !UNITY_3_0 && !UNITY_3_0_0 && !UNITY_3_1 && !UNITY_3_2 && !UNITY_3_3 && !UNITY_3_4 && !UNITY_3_5
                    // Smooth Edges on Unity 4+
                    if (smoothEdges)
                    {
                        cubemap.SmoothEdges(smoothEdgesWidth);
                        cubemap.Apply();
                    }
#endif											
			
					// Create Cubemap, but only if we are allowed to (unless there is no cubemap on the node yet)
                    if (nodes[a].allowCubemapGeneration || (!nodes[a].allowCubemapGeneration && nodes[a].cubemap == null))
                    {
                        string finalCubemapPath = pathCubemaps + "/" + sceneName + "_" + nodes[a].name + ".cubemap";
                        if (finalCubemapPath.Contains("//"))
                            finalCubemapPath = finalCubemapPath.Replace("//", "/");

                        AssetDatabase.CreateAsset(cubemap, finalCubemapPath);
                    }

                    // Set Linear Space if wanted
                    SerializedObject serializedCubemap = new SerializedObject(cubemap);
                    SetLinearSpace(ref serializedCubemap, useLinearSpace);
	
					// Free up memory to prevent memory leak
					Resources.UnloadUnusedAssets();
				}
			}
				
			AssetDatabase.Refresh();
			
			isTakingScreenshots = false;
			completedTakingScreenshots = true;
		}
		
		Debug.Log("CUBEMAPS GENERATED!");
	}
Example #20
0
	IEnumerator MakeSnapshot(Cubemap c, CubemapFace face, CubemapNode node)
	{
		// We should only read the screen buffer after rendering is complete
		yield return new WaitForEndOfFrame();

		int width = Screen.width;
		int height = Screen.height;
	
		//Create the blank texture container
		Texture2D snapshot = new Texture2D(width, height, textureFormat, useMipMaps);
		snapshot.wrapMode = TextureWrapMode.Clamp;
	
		// Rectangle Area from the Camera
		Rect copyRect = new Rect((camera.pixelWidth * 0.5f) - (snapshot.width * 0.5f), (camera.pixelHeight * 0.5f) - (snapshot.height * 0.5f), snapshot.width, snapshot.height);
		
		//Read the current render into the texture container, snapshot
		snapshot.ReadPixels(copyRect, 0, 0, false);
		
		yield return null;
		
		snapshot.Apply();
		
		// Resize our Texture
		snapshot = Scale(snapshot, nodeResolution, nodeResolution);
		
		// Write mirrored pixels from our Texture to Cubemap
		Color cubemapColor;
		for (int y = 0; y<nodeResolution; y++)
        {
            for (int x = 0; x<nodeResolution; x++)
            {
				cubemapColor = snapshot.GetPixel(nodeResolution + x, (nodeResolution-1) - y);
				c.SetPixel(face, x, y, cubemapColor);
            }
        }
        c.Apply();	 
		 
		// Optional PNG generation. Double-check it with overriding Node setting
		if(makePNG && node.allowGeneratePNG)
		{
			// Mirror the snapshot image for our PNG in order to be identical with the cubemap faces
			snapshot.SetPixels32( MirrorColor32( c.GetPixels(face) ) );
			snapshot.Apply();
			
			// Convert to PNG file
			byte[] bytes = snapshot.EncodeToPNG();
			
			// Save the file			
			string path = Application.dataPath + "/" + pathCubemapPNG + "/" + sceneName + "_" + node.name + "_" + face.ToString() + ".png";
			//System.IO.File.WriteAllBytes(path, bytes); // deprecated because not available on Webplayer
			System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
			System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
			bw.Write(bytes);
			bw.Close();
			fs.Close();

            // Fix compression state
            string finalImagePath = "Assets/" + pathCubemapPNG + "/" + sceneName + "_" + node.name + "_" + face.ToString() + ".png";
            if (finalImagePath.Contains("//"))
                finalImagePath = finalImagePath.Replace("//", "/");

            AssetDatabase.Refresh(); // refresh necessary before we can use the textureimporter

            TextureImporter textureImporter = AssetImporter.GetAtPath(finalImagePath) as TextureImporter;
            if (textureImporter != null)
            {
                textureImporter.textureFormat = TextureImporterFormat.RGB24;
                AssetDatabase.ImportAsset(finalImagePath);
            }
		}
		
		// Delete our screenshot texture as clean up
		DestroyImmediate(snapshot);
		
		yield return null;
	}
	// This function computes a diffuse environment map in 
	// "filteredCubemap" of the same dimensions as "originalCubemap"
	// by integrating -- for each texel of "filteredCubemap" -- 
	// the diffuse illumination from all texels of "originalCubemap" 
	// for the surface normal vector corresponding to the direction 
	// of each texel of "filteredCubemap".
	private Cubemap computeFilteredCubeMap()
	{
		Cubemap filteredCubeMap = new Cubemap(originalCubeMap.width, 
		                                      originalCubeMap.format, true);
		
		int filteredSize = filteredCubeMap.width;
		int originalSize = originalCubeMap.width;
		
		// Compute all texels of the diffuse environment cube map 
		// by itterating over all of them
		for (int filteredFace = 0; filteredFace < 6; filteredFace++) 
			// the six sides of the cube
		{
			for (int filteredI = 0; filteredI < filteredSize; filteredI++)
			{
				for (int filteredJ = 0; filteredJ < filteredSize; filteredJ++)
				{
					Vector3 filteredDirection = 
						getDirection(filteredFace, 
						             filteredI, filteredJ, filteredSize).normalized;
					float totalWeight = 0.0f;
					Vector3 originalDirection;
					Vector3 originalFaceDirection;
					float weight;
					Color filteredColor = new Color(0.0f, 0.0f, 0.0f);
					
					// sum (i.e. integrate) the diffuse illumination 
					// by all texels in the original environment map
					for (int originalFace = 0; originalFace < 6; originalFace++)
					{
						originalFaceDirection = getDirection(
							originalFace, 1, 1, 3).normalized; 
						//the normal vector of the face
						
						for (int originalI = 0; originalI < originalSize; originalI++)
						{
							for (int originalJ = 0; originalJ < originalSize; originalJ++)
							{
								originalDirection = getDirection(
									originalFace, originalI, 
									originalJ, originalSize); 
								// direction to the texel 
								// (i.e. light source)
								weight = 1.0f 
									/ originalDirection.sqrMagnitude; 
								// take smaller size of more 
								// distant texels into account
								originalDirection = 
									originalDirection.normalized;
								weight = weight * Vector3.Dot(
									originalFaceDirection, 
									originalDirection); 
								// take tilt of texel compared 
								// to face into account
//								weight = weight * Mathf.Max(0.0f, 
//								                            Vector3.Dot(filteredDirection, 
//								            originalDirection)); 
								// directional filter 
								// for diffuse illumination
								weight = weight * Mathf.Pow(Mathf.Max(0.0f, 
								                                      Vector3.Dot(filteredDirection, originalDirection)), 50.0f); 
								//directional filter for specular illumination
								totalWeight = totalWeight + weight; 
								// instead of analytically 
								// normalization, we just normalize 
								// to the potential max illumination
								filteredColor = filteredColor + weight 
									* originalCubeMap.GetPixel(
										(CubemapFace)originalFace, 
										originalI, originalJ); // add the 
								// illumination by this texel 
							}
						}
					}
					filteredCubeMap.SetPixel(
						(CubemapFace)filteredFace, filteredI, 
						filteredJ, filteredColor / totalWeight); 
					// store the diffuse illumination of this texel
				}
			}
		}
		
		// Avoid seams between cube faces: average edge texels 
		// to the same color on each side of the seam
		int maxI = filteredCubeMap.width - 1;
		for (int i = 0; i < maxI; i++)
		{
			setFaceAverage(ref filteredCubeMap, 
			               0, i, 0, 2, maxI, maxI - i);
			setFaceAverage(ref filteredCubeMap, 
			               0, 0, i, 4, maxI, i);
			setFaceAverage(ref filteredCubeMap, 
			               0, i, maxI, 3, maxI, i);
			setFaceAverage(ref filteredCubeMap, 
			               0, maxI, i, 5, 0, i);
			
			setFaceAverage(ref filteredCubeMap, 
			               1, i, 0, 2, 0, i);
			setFaceAverage(ref filteredCubeMap, 
			               1, 0, i, 5, maxI, i);
			setFaceAverage(ref filteredCubeMap, 
			               1, i, maxI, 3, 0, maxI - i);
			setFaceAverage(ref filteredCubeMap, 
			               1, maxI, i, 4, 0, i);
			
			setFaceAverage(ref filteredCubeMap, 
			               2, i, 0, 5, maxI - i, 0);
			setFaceAverage(ref filteredCubeMap, 
			               2, i, maxI, 4, i, 0);
			setFaceAverage(ref filteredCubeMap, 
			               3, i, 0, 4, i, maxI);
			setFaceAverage(ref filteredCubeMap, 
			               3, i, maxI, 5, maxI - i, maxI);
		}
		
		// Avoid seams between cube faces: 
		// average corner texels to the same color 
		// on all three faces meeting in one corner
		setCornerAverage(ref filteredCubeMap, 
		                 0, 0, 0, 2, maxI, maxI, 4, maxI, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 0, maxI, 0, 2, maxI, 0, 5, 0, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 0, 0, maxI, 3, maxI, 0, 4, maxI, maxI);
		setCornerAverage(ref filteredCubeMap, 
		                 0, maxI, maxI, 3, maxI, maxI, 5, 0, maxI);
		setCornerAverage(ref filteredCubeMap, 
		                 1, 0, 0, 2, 0, 0, 5, maxI, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 1, maxI, 0, 2, 0, maxI, 4, 0, 0);
		setCornerAverage(ref filteredCubeMap, 
		                 1, 0, maxI, 3, 0, maxI, 5, maxI, maxI);
		setCornerAverage(ref filteredCubeMap, 
		                 1, maxI, maxI, 3, 0, 0, 4, 0, maxI);
		
		filteredCubeMap.Apply(); //apply all SetPixel(..) commands
		
		return filteredCubeMap;
	}
Example #22
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();
    }
Example #23
0
	private void OnGUI()
	{		
		m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos);

        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(325));
            EditorGUILayout.HelpBox("This tool aims to help you when you want to change properties that are not covered by the standard Unity Inspector for Cubemaps, e.g. Mip Map Bias and Unity 4 Smooth Edges. This tool is experimental and should be used with care. I do not take responsibility if something goes wrong or produces undesirable results.", MessageType.Info);
        EditorGUILayout.EndHorizontal();

		GUILayout.Label("1. Define Cubemap", EditorStyles.boldLabel);			
		m_Cubemap = EditorGUILayout.ObjectField(m_Cubemap, typeof(Cubemap), false, GUILayout.Height(70), GUILayout.Width(70)) as Cubemap;	

		if(m_Cubemap != null)
        {
            // Serialization helps determine and set Linear and Mip Map values
            SerializedObject serializedCubemap = new SerializedObject(m_Cubemap);

            // Display Name of the current Cubemap
            GUILayout.Label(m_Cubemap.name);

            GUILayout.Space(15);

            GUILayout.Label("2. Modify Settings", EditorStyles.boldLabel);

            EditorGUIUtility.LookLikeControls(125f);

            // SETTINGS VERTICAL AREA
            EditorGUILayout.BeginVertical(GUILayout.MaxWidth(325));
            {
                EditorGUILayout.HelpBox("Some settings require the Cubemap to be rebuilt, which means you need to re-assign it to your objects.", MessageType.Warning);

                // SETTINGS START HERE
                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(300));
                {
                    EditorGUILayout.BeginVertical(GUILayout.Width(250));
                    {
                        m_resolution = EditorGUILayout.IntPopup("New Resolution:", m_resolution, m_resolutions, m_resSizes);
                        EditorGUILayout.LabelField("Currently:", m_Cubemap.height.ToString() + "x" + m_Cubemap.width.ToString());
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical(GUILayout.MaxWidth(50));
                    {
                        GUI.backgroundColor = CubemapHelpers.ColorGreen;
                        if (GUILayout.Button("Apply", GUILayout.Width(50), GUILayout.Height(20)))
                        {
                            RemakeCubemap(ref m_Cubemap);
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
                
                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(300));
                {
                    EditorGUILayout.BeginVertical(GUILayout.Width(250));
                    {
                        m_useLinearSpace = EditorGUILayout.Toggle("Linear Space:", m_useLinearSpace);
                        EditorGUILayout.LabelField("Currently: " + (CubemapHelpers.isLinear(serializedCubemap) ? "Yes":"No"));
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical(GUILayout.MaxWidth(50));
                    {
                        GUI.backgroundColor = CubemapHelpers.ColorGreen;
                        if (GUILayout.Button("Apply", GUILayout.Width(50), GUILayout.Height(20)))
                        {
                            CubemapHelpers.setLinear(ref serializedCubemap, m_useLinearSpace);
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();

                EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(300));
                {
                    EditorGUILayout.BeginVertical(GUILayout.Width(250));
                    {
                        m_useMipMaps = EditorGUILayout.Toggle("Mip Maps:", m_useMipMaps);
                        EditorGUILayout.LabelField("Currently: " + (CubemapHelpers.usingMipMap(serializedCubemap) ? "Yes" : "No"));
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical(GUILayout.MaxWidth(50));
                    {
                        GUI.backgroundColor = CubemapHelpers.ColorGreen;
                        if (GUILayout.Button("Apply", GUILayout.Width(50), GUILayout.Height(20)))
                        {
                            CubemapHelpers.setMipMap(ref serializedCubemap, m_useMipMaps);
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();

                EditorGUILayout.BeginHorizontal(GUILayout.Width(300));
                {
                    EditorGUILayout.BeginVertical(GUILayout.Width(250));
                    {
                        m_mipmapBias = EditorGUILayout.Slider("Mip Map Bias:", m_mipmapBias, -10f, 10f);
                        EditorGUILayout.LabelField("Currently:", m_Cubemap.mipMapBias.ToString());
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical(GUILayout.MaxWidth(50f));
                    {
                        GUI.backgroundColor = CubemapHelpers.ColorGreen;
                        if (GUILayout.Button("Apply", GUILayout.Width(50), GUILayout.Height(20)))
                        {
                            m_Cubemap.mipMapBias = m_mipmapBias;
                            m_Cubemap.Apply();
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();
            
                EditorGUILayout.Space();

#if !UNITY_2_6 && !UNITY_2_6_1 && !UNITY_3_0 && !UNITY_3_0_0 && !UNITY_3_1 && !UNITY_3_2 && !UNITY_3_3 && !UNITY_3_4 && !UNITY_3_5
                m_smoothEdges = EditorGUILayout.Toggle("Smooth Edges?", m_smoothEdges);
                if (m_smoothEdges)
                {
                    EditorGUILayout.HelpBox("CAREFUL: This effect can't be undone!", MessageType.Warning);

                    EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(300));
                    {
                        EditorGUILayout.BeginVertical(GUILayout.Width(250));
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                EditorGUILayout.BeginVertical(GUILayout.Width(150));
                                {
                                    EditorGUILayout.LabelField("Edge Smooth Width:", GUILayout.Width(150));
                                }
                                EditorGUILayout.EndVertical();

                                EditorGUILayout.BeginVertical(GUILayout.Width(30));
                                {
                                    m_smoothEdgeWidth = EditorGUILayout.IntField(m_smoothEdgeWidth, GUILayout.Width(30));
                                }
                                EditorGUILayout.EndVertical();

                                EditorGUILayout.BeginVertical(GUILayout.Width(30));
                                {
                                    EditorGUILayout.LabelField("px", GUILayout.Width(30));
                                }
                                EditorGUILayout.EndVertical();
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndVertical();
                        EditorGUILayout.BeginVertical(GUILayout.MaxWidth(50f));
                        {
                            GUI.backgroundColor = CubemapHelpers.ColorGreen;
                            if (GUILayout.Button("Apply", GUILayout.Width(50), GUILayout.Height(20)))
                            {
                                m_Cubemap.SmoothEdges(m_smoothEdgeWidth);
                                m_Cubemap.Apply();
                            }
                            GUI.backgroundColor = Color.white;
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();
                }
#endif
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            GUI.backgroundColor = CubemapHelpers.ColorGreen;
            if (GUILayout.Button("Apply ALL (use carefully!)", GUILayout.Width(200), GUILayout.Height(40)))
            {
                ApplyChanges(m_Cubemap);
            }
            GUI.backgroundColor = Color.white;
        }
		
		EditorGUILayout.EndScrollView();
		
		Repaint();
	}
Example #24
0
	IEnumerator Capture(Cubemap cubemap,CubemapFace face,Camera cam)
	{
		var width = Screen.width;
		var height = Screen.height;

		Texture2D tex = new Texture2D(height, height, TextureFormat.ARGB32, false);
		int cubeSize = cubemap.height;
		
		cam.transform.localRotation = Rotation(face);
		
		yield return new WaitForEndOfFrame();

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

		Color cubeCol;
		for (int y = 0; y < cubeSize; y++)
		{
			for (int x = 0; x < cubeSize; x++)
			{

				cubeCol = tex.GetPixel(cubeSize + x, (cubeSize - 1) - y);

				cubemap.SetPixel(face, x, y, cubeCol);

			}
		}

		cubemap.Apply();

		DestroyImmediate(tex);
	}
Example #25
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;
        }
    }
Example #26
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);
	}
Example #27
0
	/**
	 * キューブマップの作成.
	 */
	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;
	}
Example #28
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());
	}
    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");
    }
Example #30
0
    IEnumerator RenderCubeFaces(Cubemap cube, bool irradiance)
    {
        if (irradiance)
        {
            size = (int)DiffSize;
            mipmap = false;
        }
        else
        {
            size = (int)SpecSize;
            mipmap = true;
        }

        cube = new Cubemap((int)size, texFor, mipmap);
        yield return StartCoroutine(Capture(cube, CubemapFace.PositiveZ, CubeCamera));
        yield return StartCoroutine(Capture(cube, CubemapFace.PositiveX, CubeCamera));
        yield return StartCoroutine(Capture(cube, CubemapFace.NegativeX, CubeCamera));
        yield return StartCoroutine(Capture(cube, CubemapFace.NegativeZ, CubeCamera));
        yield return StartCoroutine(Capture(cube, CubemapFace.PositiveY, CubeCamera));
        yield return StartCoroutine(Capture(cube, CubemapFace.NegativeY, CubeCamera));
        cube.Apply(mipmap);
        if (irradiance)
        {
            Cubemap diffCube = cube;
            diffCube.name = cubeName;
            if (SmoothEdges)
            {
                diffCube.SmoothEdges(SmoothEdgePixel);
            }

            diffCube.wrapMode = TextureWrapMode.Clamp;
            string finalDiffPath = diffCube.name + "DIFF.cubemap";

            AssetDatabase.CreateAsset(diffCube, finalDiffPath);
            SerializedObject serializedCubemap = new SerializedObject(diffCube);
            SetLinearSpace(ref serializedCubemap, true);
            DIFFCube = diffCube;
        }
        else
        {
            Cubemap specCube = cube;
            specCube.name = cubeName;
            if (SmoothEdges)
            {
                specCube.SmoothEdges(SmoothEdgePixel);
            }

            specCube.wrapMode = TextureWrapMode.Clamp;
            string finalSpecPath = specCube.name + "SPEC.cubemap";

            AssetDatabase.CreateAsset(specCube, finalSpecPath);

            SerializedObject serializedCubemap = new SerializedObject(specCube);
            SetLinearSpace(ref serializedCubemap, true);
            SPECCube = specCube;
        }
        yield return StartCoroutine(Finished());
    }
Example #31
0
    private void ApplyChanges(Cubemap cubemap)
    {
        if (cubemap.height != m_resolution)
            RemakeCubemap(ref cubemap);
        else
        {
            cubemap.mipMapBias = m_mipmapBias;

#if !UNITY_2_6 && !UNITY_2_6_1 && !UNITY_3_0 && !UNITY_3_0_0 && !UNITY_3_1 && !UNITY_3_2 && !UNITY_3_3 && !UNITY_3_4 && !UNITY_3_5
            if (m_smoothEdges)
                cubemap.SmoothEdges(m_smoothEdgeWidth);
#endif

            cubemap.Apply();

            SerializedObject serializedCubemap = new SerializedObject(cubemap);
            CubemapHelpers.setMipMap(ref serializedCubemap, m_useMipMaps);
            CubemapHelpers.setLinear(ref serializedCubemap, m_useLinearSpace);
        }
    }
Example #32
0
    void RenderToCubeMap(Cubemap dest, Camera cam)
    {
        // get MIP level 0 to be pure reflection
        /*
        for (int i=0;i<6;i++)
        {
            BeginCubeFaceRender(dest, (CubemapFace)i, 0, cam);
            cam.Render();
            EndCubeFaceRender(dest, (CubemapFace)i, 0, cam, false);
        }*/

        dest.Apply(false);

        // blur each mip level
        Material blurMaterial = new Material(Shader.Find("Custom/MirrorBlurCubemap"));
        blurMaterial.SetTexture("MyCube", dest);
        for (int mip=1; (dest.width>>mip)>0;mip++)
        {
            //specular[mip]
            //			blurMaterial.SetFloat("_SpecPwr", specular[mip]); // FIXME what is specular[mip]?
            blurMaterial.SetFloat("_SpecPwr", mip*8);

            // blur each face by rendering a cube that does a tons of samples
            for (int i=0; i<6; i++)
            {
                BeginCubeFaceRender(dest, (CubemapFace)i, mip, cam);
                // FIXME: what is outsideCubeMesh?
                Graphics.DrawMesh(outsideCubeMesh, cam.transform.position, Quaternion.identity, blurMaterial, 1, cam, 0);
                cam.Render();
                EndCubeFaceRender(dest, (CubemapFace)i, mip, cam, false);
            }
        }

        // upload final version
        dest.Apply(false);
    }
Example #33
0
    //[MenuItem ("Lux Cubemapper/Cubemapper")]
    //static void CreateWizard () {
    //    ScriptableWizard.DisplayWizard<LuxCubeMapper>("Convolve cubemap", "Go");
    //}

    //void OnWizardCreate () {
    //    if (TakeNewProbe) RenderToCubeMap(cubeMap,probe);


    //    //	diffuse	
    //    if (ConvolutionMode == ConvoModes.Diffuse) {
    //        ConvolveIrradianceEnvironmentMap (cubeMap);
    //        if (PullHDR) FakeHDR(cubeMap, false);
    //    }

    //    if (ConvolutionMode == ConvoModes.Specular) {
    //        ConvolveRadianceEnvironmentMap (cubeMap);
    //        FixupCubeEdges(cubeMap);
    //        if (PullHDR) FakeHDR(cubeMap, true);
    //        cubeMap.filterMode = FilterMode.Trilinear;
    //        cubeMap.mipMapBias = 0.5f;
    //    }
    //}  


    //void OnWizardUpdate () {
    //}   

    //void RenderToCubeMap(Cubemap dest, GameObject probe) {
    //    var cubeCamera = new GameObject( "CubemapCamera", typeof(Camera) ) as GameObject;
    ////	cubeCamera.hideFlags = HideFlags.HideInHierarchy;
    //    var cubeCam = cubeCamera.GetComponent("Camera") as Camera;
    //    cubeCam.nearClipPlane = 0.001f;
    //    cubeCam.farClipPlane = 1000.0f;
    //    cubeCam.aspect = 1.0f;
    ////	cubeCam.hdr = true;
    //    cubeCam.cullingMask = 1 << 0;		
    //    cubeCamera.transform.position = probe.transform.position;
    //    cubeCam.RenderToCubemap(dest);
    //    GameObject.DestroyImmediate(cubeCamera);
    //}



//--------------------------------------------------------------------------------------
// ConvolveRadianceEnvironmentMap

    void ConvolveRadianceEnvironmentMap (Cubemap RadianceCube) {
	    int a_Size = RadianceCube.width;
	    int n_Size = a_Size;
	    int startMipLevel = 0;
	    float specularPower;
	    float[] specPowr = new float [] {
		    SpecularPower, SpecularPower/2.0f, SpecularPower/4.0f, SpecularPower/8.0f, SpecularPower/16.0f, SpecularPower/32.0f, SpecularPower/64.0f, SpecularPower/128.0f, SpecularPower/256.0f, SpecularPower/512.0f
	    };

	    // Calculate maxmiplevels
	    int maxMipLevels = (int)Mathf.Log(a_Size, 2) + 1;
    //
        float mytime = Time.realtimeSinceStartup;
	
	    // if HighestMipIsReflection == true then skip processing of the highest mip level
	    if (HighestMipIsReflection) {
		    startMipLevel = 1;
		    n_Size = n_Size >> 1;		
	    } 

	    for (int mipLevel = startMipLevel; mipLevel < maxMipLevels; mipLevel++)
	    {
		    Vector4[] m_NormCubeMapArray = new Vector4[n_Size*n_Size*6];
		    BuildNormalizerSolidAngleArray(n_Size, ref m_NormCubeMapArray);

		    specularPower = specPowr[mipLevel];
		    float Angle;
		    // If we use SpecularPower, automatically calculate the a_BaseFilterAngle required, this will speed the process
		    Angle = GetBaseFilterAngle(specularPower);
		    // Go for it:
		    FilterCubefaces(RadianceCube, m_NormCubeMapArray, mipLevel, Angle, specularPower);
    //		FilterCubefacesBF(RadianceCube, mipLevel, Angle, specularPower);
		    n_Size = n_Size >> 1;
	    }
    //
        Debug.Log(Time.realtimeSinceStartup - mytime);

	    RadianceCube.Apply(false);
	
    }