I would like to export my grid created in Shader Graph as a texture, but the exported png file doesn’t contain any graphics.
public int size = 900;
public Material material;
public void ExportAsPng()
{
// Create a temporary RenderTexture of the same size as the texture
RenderTexture tmp = RenderTexture.GetTemporary(
size,
size,
0,
RenderTextureFormat.Default,
RenderTextureReadWrite.Linear);
// Blit the pixels on texture to the RenderTexture
Graphics.Blit(null, tmp, material);
// Backup the currently set RenderTexture
RenderTexture previous = RenderTexture.active;
// Set the current RenderTexture to the temporary one we created
RenderTexture.active = tmp;
// Create a new readable Texture2D to copy the pixels to it
Texture2D myTexture2D = new Texture2D(size, size);
// Copy the pixels from the RenderTexture to the new Texture
myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
myTexture2D.Apply();
// Reset the active RenderTexture
RenderTexture.active = previous;
// Release the temporary RenderTexture
RenderTexture.ReleaseTemporary(tmp);
#if UNITY_EDITOR
string folder = $"{Directory.GetParent(Application.dataPath)}/Images";
#else
string folder = $"{Application.dataPath}/Images";
#endif
string path = Path.Combine(folder, "Test.png");
byte[] bytes = myTexture2D.EncodeToPNG();
File.WriteAllBytes(path, bytes);
}


