UnityEngine.Cubemap.SetPixels(UnityEngine.Color[], UnityEngine.CubemapFace)

Here are the examples of the csharp api UnityEngine.Cubemap.SetPixels(UnityEngine.Color[], UnityEngine.CubemapFace) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : OVRCubemapCapture.cs
with MIT License
from Tobbse

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;
		faceTexture.dimension = UnityEngine.Rendering.TextureDimension.Tex2D;
		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);

		}