Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Save2()
- {
- // Create a temporary render texture
- RenderTexture temp =
- RenderTexture.GetTemporary(TextureLength, TextureLength, 0, RenderTextureFormat.ARGB32);
- // Draw to the RT (Texture2D.whiteTexture is just a dummy src)
- // mat is a material with the Turbulence Shader applied to it
- Graphics.Blit(Texture2D.whiteTexture, temp, m_renderer.material);
- // Copy the rendertexture to a regular texture
- Texture2D tex = new Texture2D(TextureLength, TextureLength);
- tex.ReadPixels(new Rect(0, 0, TextureLength, TextureLength), 0, 0, false);
- tex.Apply();
- byte[] bytes = tex.EncodeToPNG();
- File.WriteAllBytes(Application.dataPath + "/Temp/test.png", bytes);
- }
- public void Save()
- {
- RenderTexture buffer = new RenderTexture(
- TextureLength,
- TextureLength,
- 0, // No depth/stencil buffer
- RenderTextureFormat.ARGB32, // Standard colour format
- RenderTextureReadWrite.Linear
- );
- /*
- RenderTexture buffer = new RenderTexture(
- TextureLength,
- TextureLength,
- 0, // No depth/stencil buffer
- RenderTextureFormat.ARGB32, // Standard colour format
- RenderTextureReadWrite.sRGB // No sRGB conversions
- );
- */
- buffer.DiscardContents();
- texture = new Texture2D(TextureLength, TextureLength, TextureFormat.ARGB32, true);
- //MeshRenderer render = GetComponent<MeshRenderer>();
- //texture = render.sharedMaterial.GetTexture("_MainTex") as Texture2D;
- Material material = m_renderer.material;
- Graphics.Blit(null, buffer, material);
- RenderTexture.active = buffer; // If not using a scene camera
- texture.ReadPixels(
- new Rect(0, 0, TextureLength, TextureLength), // Capture the whole texture
- 0, 0, // Write starting at the top-left texel
- false); // No mipmaps
- texture.Apply();
- RenderTexture.active = null;
- buffer.Release();
- byte[] bytes = texture.EncodeToPNG();
- File.WriteAllBytes(Application.dataPath + "/Temp/test.png", bytes);
- // texture.Save();
- }
Advertisement
Add Comment
Please, Sign In to add comment