ProceduralTexture -> Texture2D

How can i convert ProceduralTexture to Texture2D ?

Hi,

I am also looking for a way to convert ProceduralTexture into Texture2D.
In the end I want to save the contents of the ProceduralTexture as PNG.

And I want to feed to result to Texture2D.PackTextures().

I found a solution.
You have to update Unity to Version 4.1. With this Version ProceduralTexture.GetPixels32 was introduced.

In your ProceduralMaterial xou have to set the output texture format to RAW. If not set to RAW you will only get black pixels.

var tex = new Texture2D(proceduralTexture.with, proceduralTexture.height); tex.SetPixels32(proceduralTexture.GetPixels32()); tex.Apply(); File.WriteAllBytes(path, tex.EncodeToPNG());

themipper

This call never works for me:

ProceduralTexture.GetPixels32(0, 0, tex.width, tex.height)

I always get zeroed color structs, nothing else. I’ve set the output to RAW and set the isReadable property to true; on the ProceduralMaterial. I can get the pixels with a RenderTexture, but that’s suboptimal at best. Here is my test method:

	Texture2D MakeTexture(ProceduralMaterial material)
	{
		Texture[] texList = material.GetGeneratedTextures();
		ProceduralTexture tex = texList[0] as ProceduralTexture;
		Texture2D tex2D = new Texture2D(tex.width, tex.height);
		
		#region GetPixels32 -- this doesn't work
//		UnityEngine.Color32[] pixels = tex.GetPixels32(0, 0, tex.width, tex.height);
//		tex2D.SetPixels32(pixels);
//		tex2D.Apply();
		#endregion
		
		#region RenderTexture -- this works
		_RenderCamera.guiTexture.texture = tex;
		_RenderCamera.camera.enabled = true;
		RenderTexture rt = RenderTexture.GetTemporary(tex.width, tex.height, 24, RenderTextureFormat.ARGB32);
		_RenderCamera.camera.targetTexture = rt; 
		_RenderCamera.camera.Render(); 
		RenderTexture.active = rt;
		tex2D.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
		RenderTexture.active = null; 
		RenderTexture.ReleaseTemporary(rt);
		_RenderCamera.camera.enabled = false;
		#endregion
		
		return tex2D;
	}