public TextureSpaceData(string objName, GBufferResolution resolution) { textureSpaceMesh = new Mesh(); textureSpaceVertices = new List <Vector3>(); textureSpaceUVs = new List <Vector2>(); textureSpaceIndices = new List <int>(); albedoTexture = new RenderTexture((int)resolution, (int)resolution, 0, RenderTextureFormat.ARGB32); }
// Public Class Methods. // --------------------------------------------------------------- public bool SaveGBufferToFile(string fileName, bool isFullPath = false, GBufferResolution gBufferResolution = GBufferResolution.High) { if (!isGBufferReady) { Debug.LogError("[GBufferGenerator::SaveGBufferToFile] Sorry ... The GBuffer is not ready yet ... "); return(false); } Debug.Log("[GBufferGenerator::SaveGBufferToFile] Save GBuffer ..."); TextureFormat format = (gBufferFormat == GBufferFormat.Half) ? TextureFormat.RGBAHalf : TextureFormat.RGBAFloat; // Read buffer from GPU. Texture2D positionTex = FileUtil.RenderTextureToTexture2D(positionMap, format); Texture2D normalTex = FileUtil.RenderTextureToTexture2D(normalMap, format); // Prepare data for serization. GBufferTexData gBuffer = new GBufferTexData(); gBuffer.size = GetGBufferSize(gBufferResolution); FileUtil.ColorArrayToFloatArray(positionTex.GetPixels(), out gBuffer.positionData); FileUtil.ColorArrayToFloatArray(normalTex.GetPixels(), out gBuffer.normalData); // Save GBuffer data to file. string path; if (isFullPath) { path = fileName; } else { path = Application.dataPath + "/" + fileName + ".gbuf"; } BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream fileStream = File.Create(path); binaryFormatter.Serialize(fileStream, gBuffer); fileStream.Close(); Debug.Log("Save GBuffer To Path: " + path + " Finished!"); return(true); }
public static int GetGBufferSize(GBufferResolution resolution) { switch (resolution) { case GBufferResolution.Low: return(512); case GBufferResolution.Medium: return(1024); case GBufferResolution.High: return(2048); case GBufferResolution.VeryHigh: return(4096); default: return(1024); } }