static public int SmoothEdges(IntPtr l) { try{ if (matchType(l, 2, typeof(int))) { UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); self.SmoothEdges(a1); return(0); } else if (matchType(l, 2)) { UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l); self.SmoothEdges(); 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); } }
static public int SmoothEdges(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 1) { UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l); self.SmoothEdges(); pushValue(l, true); return(1); } else if (argc == 2) { UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); self.SmoothEdges(a1); 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)); } }
static public int SmoothEdges(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.SmoothEdges(); pushValue(l, true); return(1); } else if (argc == 2) { UnityEngine.Cubemap self = (UnityEngine.Cubemap)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); self.SmoothEdges(a1); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function SmoothEdges 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 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(); }
// 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()); }
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()); }
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(); }
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); } }
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!"); }
public static void RenderIntoCubemap(Camera ownerCamera, Cubemap outCubemap) { int width = (int)outCubemap.width; int height = (int)outCubemap.height; CubemapFace[] faces = new CubemapFace[] { CubemapFace.PositiveX, CubemapFace.NegativeX, CubemapFace.PositiveY, CubemapFace.NegativeY, CubemapFace.PositiveZ, CubemapFace.NegativeZ }; Vector3[] faceAngles = new Vector3[] { new Vector3(0.0f, 90.0f, 0.0f), new Vector3(0.0f, -90.0f, 0.0f), new Vector3(-90.0f, 0.0f, 0.0f), new Vector3(90.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 180.0f, 0.0f) }; // Backup states RenderTexture backupRenderTex = RenderTexture.active; float backupFieldOfView = ownerCamera.fieldOfView; float backupAspect = ownerCamera.aspect; Quaternion backupRot = ownerCamera.transform.rotation; //RenderTexture backupRT = ownerCamera.targetTexture; // Enable 8X MSAA RenderTexture faceTexture = new RenderTexture(width, height, 24); faceTexture.antiAliasing = 8; #if !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3) faceTexture.dimension = UnityEngine.Rendering.TextureDimension.Tex2D; #endif faceTexture.hideFlags = HideFlags.HideAndDontSave; // For intermediate saving Texture2D swapTex = new Texture2D(width, height, TextureFormat.RGB24, false); swapTex.hideFlags = HideFlags.HideAndDontSave; // Capture 6 Directions ownerCamera.targetTexture = faceTexture; ownerCamera.fieldOfView = 90; ownerCamera.aspect = 1.0f; Color[] mirroredPixels = new Color[swapTex.height * swapTex.width]; for (int i = 0; i < faces.Length; i++) { ownerCamera.transform.eulerAngles = faceAngles[i]; ownerCamera.Render(); RenderTexture.active = faceTexture; swapTex.ReadPixels(new Rect(0, 0, width, height), 0, 0); // Mirror vertically to meet the standard of unity cubemap Color[] OrignalPixels = swapTex.GetPixels(); for (int y1 = 0; y1 < height; y1++) { for (int x1 = 0; x1 < width; x1++) { mirroredPixels[y1 * width + x1] = OrignalPixels[((height - 1 - y1) * width) + x1]; } }; outCubemap.SetPixels(mirroredPixels, faces[i]); } outCubemap.SmoothEdges(); // Restore states RenderTexture.active = backupRenderTex; ownerCamera.fieldOfView = backupFieldOfView; ownerCamera.aspect = backupAspect; ownerCamera.transform.rotation = backupRot; ownerCamera.targetTexture = backupRenderTex; DestroyImmediate(swapTex); DestroyImmediate(faceTexture); }
static public void CreateCubemapWithPro(int resolution, TextureFormat textureFormat, bool useLinearSpace, bool useMipMaps, float mipMapBias, string outputPathCubemap, bool makePNG, string outputPathPNG, CameraClearFlags camClearFlags, Color camBGColor, float camFarClipPlane, int camCullingMask, bool smoothEdges, int smoothEdgeWidth) { CubemapNode[] nodes = FindObjectsOfType(typeof(CubemapNode)) as CubemapNode[]; 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].allowCubemapGeneration && nodes[a].cubemap == null)) { // Create our Cubemap File that we will render into Cubemap cubemap = new Cubemap(resolution, textureFormat, useMipMaps); cubemap.mipMapBias = mipMapBias; string finalCubemapPath = outputPathCubemap + "/" + Application.loadedLevelName + "_" + nodes[a].name + ".cubemap"; if (finalCubemapPath.Contains("//")) finalCubemapPath = finalCubemapPath.Replace("//", "/"); AssetDatabase.CreateAsset(cubemap, finalCubemapPath); // create and position temporary camera for rendering var go = new GameObject("CubemapCamera", typeof(Camera)); go.transform.position = nodes[a].transform.position; go.transform.rotation = Quaternion.identity; // Camera setup var cam = go.GetComponent<Camera>(); cam.clearFlags = camClearFlags; cam.backgroundColor = camBGColor; cam.farClipPlane = camFarClipPlane; cam.cullingMask = camCullingMask; // render into cubemap cam.RenderToCubemap(cubemap); #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.0+ if (smoothEdges) { cubemap.SmoothEdges(smoothEdgeWidth); cubemap.Apply(); } #endif // Use Linear Space? SerializedObject serializedCubemap = new SerializedObject(cubemap); CubemapHelpers.setLinear(ref serializedCubemap, useLinearSpace); // Destroy temp camera DestroyImmediate(go); // Extract PNG if Allowed if (makePNG && nodes[a].allowGeneratePNG) { CubemapHelpers.CubemapToPNG(cubemap, outputPathPNG); } AssetDatabase.Refresh(); Selection.activeObject = cubemap; } } Debug.Log("CUBEMAPS GENERATED!"); EditorUtility.DisplayDialog("Cubemaps generated!", "You can now proceed assigning your cubemaps to your objects.", "Yay!"); }