本文整理汇总了C#中UnityEngine.Cubemap.SmoothEdges方法的典型用法代码示例。如果您正苦于以下问题:C# Cubemap.SmoothEdges方法的具体用法?C# Cubemap.SmoothEdges怎么用?C# Cubemap.SmoothEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Cubemap
的用法示例。
在下文中一共展示了Cubemap.SmoothEdges方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
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();
}
示例2: CreateCubeMap
// 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());
}
示例3: ConvolveSpecularCubeMap
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);
//.........这里部分代码省略.........
示例4: OnGUI
//.........这里部分代码省略.........
{
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();
}
示例5: ApplyChanges
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);
}
}
示例6: ScreenCapture
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;
//.........这里部分代码省略.........
示例7: RenderIntoCubemap
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);
}
示例8: CreateCubemapWithPro
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!");
}