private void Awake()
        {
            if (singleton)
            {
                Debug.LogError("Render Pipeline should be Singleton!");
                DestroyImmediate(gameObject);
                return;
            }
            data.buffer = new CommandBuffer();
            DontDestroyOnLoad(this);
            singleton            = this;
            data.arrayCollection = new RenderArray(true);
            clusterResources     = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i.name, i.clusterCount));
            }
            PipelineFunctions.InitBaseBuffer(ref data.baseBuffer, clusterResources, mapResources, clusterCount);
            allEvents = new List <PipelineEvent>(GetComponentsInChildren <PipelineEvent>());
            foreach (var i in allEvents)
            {
                i.InitEvent(resources);
            }
            SceneStreaming.pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
            SceneStreaming.commandQueue     = new LoadingCommandQueue();
        }
        private void Awake()
        {
            if (initialized)
            {
                Debug.LogError("Should Be Singleton!");
                Destroy(gameObject);
                return;
            }
            initialized      = true;
            nullValue        = current;
            current          = this;
            baseBuffer       = new PipelineBaseBuffer();
            clusterResources = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i.name, i.clusterCount));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            SceneStreaming.pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
            SceneStreaming.commandQueue     = new LoadingCommandQueue();
        }
Example #3
0
 public void Init(int propertyCount, MStringBuilder msb, ClusterMatResources resources)
 {
     this.resources     = resources;
     sb                 = msb;
     this.propertyCount = propertyCount;
     state              = State.Unloaded;
 }
        public static void Awake(PipelineResources resources, int resolution, int texArrayCapacity, int propertyCapacity, string mapResources)
        {
            SceneController.resolution = resolution;
            singletonReady = true;
            SceneController.resources = resources;
            addList = new NativeList<ulong>(10, Allocator.Persistent);
            baseBuffer = new PipelineBaseBuffer();
            clusterResources = Resources.Load<ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;
            allScenes = new List<SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            pointerContainer = new NativeList<ulong>(clusterCount, Allocator.Persistent);
            commandQueue = new LoadingCommandQueue();
            RenderTextureDescriptor desc = new RenderTextureDescriptor
            {
                autoGenerateMips = false,
                bindMS = false,
                colorFormat = RenderTextureFormat.ARGB32,
                depthBufferBits = 0,
                dimension = TextureDimension.Tex2DArray,
                enableRandomWrite = false,
                height = resolution,
                width = resolution,
                memoryless = RenderTextureMemoryless.None,
                msaaSamples = 1,
                vrUsage = VRTextureUsage.None,
                volumeDepth = texArrayCapacity,
                shadowSamplingMode = ShadowSamplingMode.None,
                sRGB = false,
                useMipMap = false
            };
            commonData = new SceneCommonData
            {
                texDict = new Dictionary<string, SceneCommonData.TextureIdentifier>(),
                avaiableProperties = new NativeList<int>(propertyCapacity, Allocator.Persistent),
                avaiableTexs = new NativeList<int>(texArrayCapacity, Allocator.Persistent),
                texCopyBuffer = new ComputeBuffer(resolution * resolution, sizeof(int)),
                propertyBuffer = new ComputeBuffer(propertyCapacity, sizeof(PropertyValue)),
                copyTextureMat = new Material(resources.shaders.copyShader),
                texArray = new RenderTexture(desc),
                clusterMaterial = new Material(resources.shaders.clusterRenderShader),
                terrainMaterial = new Material(resources.shaders.terrainShader),
                terrainDrawStreaming = new TerrainDrawStreaming(100, 16, resources.shaders.terrainCompute)
            };

            for (int i = 0; i < propertyCapacity; ++i)
            {
                commonData.avaiableProperties.Add(i);
            }
            for (int i = 0; i < texArrayCapacity; ++i)
            {
                commonData.avaiableTexs.Add(i);
            }
        }
Example #5
0
        public void TryThis()
        {
            bool save = false;

            if (res == null)
            {
                save     = true;
                res      = ScriptableObject.CreateInstance <ClusterMatResources>();
                res.name = "SceneManager";
                res.clusterProperties = new List <ClusterProperty>();
            }
            Func <ClusterProperty, ClusterProperty, bool> equalCompare = (a, b) =>
            {
                return(a.name == b.name);
            };
            ClusterProperty property = new ClusterProperty();

            property.name = modelName;
            foreach (var i in res.clusterProperties)
            {
                if (equalCompare(property, i))
                {
                    Debug.LogError("Already Contained Scene " + modelName);
                    return;
                }
            }
            LODGroup[] groups = GetComponentsInChildren <LODGroup>();
            Dictionary <MeshRenderer, bool> lowLevelDict = new Dictionary <MeshRenderer, bool>();

            foreach (var i in groups)
            {
                LOD[] lods = i.GetLODs();
                for (int j = 1; j < lods.Length; ++j)
                {
                    foreach (var k in lods[j].renderers)
                    {
                        if (k.GetType() == typeof(MeshRenderer))
                        {
                            lowLevelDict.Add(k as MeshRenderer, true);
                        }
                    }
                }
            }
            CombinedModel model = ProcessCluster(GetComponentsInChildren <MeshRenderer>(false), lowLevelDict);

            property.vm              = model.vm;
            property.clusterCount    = ClusterGenerator.GenerateCluster(model.allPoints, model.bound, modelName, voxelCount, res.clusterProperties.Count);
            res.maximumMaterialCount = Mathf.Max(1, res.maximumMaterialCount);
            res.maximumMaterialCount = Mathf.Max(res.maximumMaterialCount, model.vm.allProperties.Count);
            res.clusterProperties.Add(property);
            if (save)
            {
                AssetDatabase.CreateAsset(res, "Assets/SceneManager.asset");
            }
            else
            {
                EditorUtility.SetDirty(res);
            }
        }
Example #6
0
 public void Init(MStringBuilder msb, ClusterMatResources resources)
 {
     this.resources = resources;
     sb             = msb;
     state          = State.Unloaded;
     propertyCount  = propertyStaticCount;
     propertyStaticCount++;
 }
 public SceneStreaming(ClusterProperty property, int propertyCount, MStringBuilder msb, ClusterMatResources resources)
 {
     this.resources     = resources;
     sb                 = msb;
     this.propertyCount = propertyCount;
     state              = State.Unloaded;
     this.property      = property;
 }
 public void Dispose()
 {
     current = null;
     rgbaPool.Dispose();
     emissionPool.Dispose();
     heightPool.Dispose();
     vmManager.Dispose();
     referenceCacheDict.Dispose();
     mipIDs.Dispose();
 }
Example #9
0
        public static void Awake(PipelineResources resources)
        {
            int maximumClusterCount        = 0;
            ClusterMatResources clusterRes = resources.clusterResources;

            if (Application.isPlaying && clusterRes)
            {
                clusterRes.Init(resources);
                maximumClusterCount = clusterRes.maximumClusterCount;
            }
            singletonReady            = true;
            SceneController.resources = resources;
            addList    = new NativeList <ulong>(10, Allocator.Persistent);
            baseBuffer = new PipelineBaseBuffer();
            PipelineFunctions.InitBaseBuffer(baseBuffer, maximumClusterCount);
        }
        public void Init(PipelineResources res)
        {
            current            = this;
            referenceCacheDict = new NativeDictionary <int4x4, int, Int4x4Equal>(200, Allocator.Persistent, new Int4x4Equal());
            mipIDs             = new NativeArray <int>(2, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            mipIDs[0]          = Shader.PropertyToID("_Mip0");
            mipIDs[1]          = Shader.PropertyToID("_Mip1");

            /*mipIDs[2] = Shader.PropertyToID("_Mip2");
            *  mipIDs[3] = Shader.PropertyToID("_Mip3");
            *  mipIDs[4] = Shader.PropertyToID("_Mip4");
            *  mipIDs[5] = Shader.PropertyToID("_Mip5");*/
            rgbaPool.Init(0, GraphicsFormat.R8G8B8A8_UNorm, (int)fixedTextureSize, this);
            emissionPool.Init(2, GraphicsFormat.R16G16B16A16_SFloat, (int)fixedTextureSize, this);
            heightPool.Init(3, GraphicsFormat.R8_UNorm, (int)fixedTextureSize, this);
            vmManager = new VirtualMaterialManager(materialPoolSize, maximumMaterialCount, res.shaders.streamingShader);
            SceneStreaming.loading = false;
        }
        public static void Awake(PipelineResources resources, string mapResources)
        {
            singletonReady            = true;
            SceneController.resources = resources;
            addList          = new NativeList <ulong>(10, Allocator.Persistent);
            baseBuffer       = new PipelineBaseBuffer();
            clusterResources = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
        }
        public static void Awake(PipelineResources resources, ClusterMatResources mapResources)
        {
            singletonReady            = true;
            SceneController.resources = resources;
            addList          = new NativeList <ulong>(10, Allocator.Persistent);
            baseBuffer       = new PipelineBaseBuffer();
            clusterResources = mapResources;
            int clusterCount = 0;

            if (clusterResources)
            {
                allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);

                for (int i = 0; i < clusterResources.clusterProperties.Count; ++i)
                {
                    var cur = clusterResources.clusterProperties[i];
                    clusterCount += cur.clusterCount;
                    allScenes.Add(new SceneStreaming(cur, i));
                }
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterCount);
        }
Example #13
0
        public static void Awake(PipelineResources resources, int resolution, int texArrayCapacity, int lightmapResolution, int lightmapCapacity, int propertyCapacity, string mapResources)
        {
            SceneController.resolution = resolution;
            singletonReady             = true;
            SceneController.resources  = resources;
            addList          = new NativeList <ulong>(10, Allocator.Persistent);
            baseBuffer       = new PipelineBaseBuffer();
            clusterResources = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
            RenderTextureDescriptor desc = new RenderTextureDescriptor
            {
                autoGenerateMips   = false,
                bindMS             = false,
                colorFormat        = RenderTextureFormat.ARGB32,
                depthBufferBits    = 0,
                dimension          = TextureDimension.Tex2DArray,
                enableRandomWrite  = true,
                height             = resolution,
                width              = resolution,
                memoryless         = RenderTextureMemoryless.None,
                msaaSamples        = 1,
                vrUsage            = VRTextureUsage.None,
                volumeDepth        = texArrayCapacity,
                shadowSamplingMode = ShadowSamplingMode.None,
                sRGB      = false,
                useMipMap = false
            };
        }
        public void Init(int streamingIndex, RenderTextureFormat format, int resolution, ClusterMatResources clusterRes, bool isNormal)
        {
            this.isNormal       = isNormal;
            this.clusterRes     = clusterRes;
            this.streamingIndex = streamingIndex;
            int targetLevel = (int)(log2(resolution + 0.1)) - 4;

            rt                   = new RenderTexture(resolution, resolution, 0, format, targetLevel);
            rt.useMipMap         = targetLevel > 1;
            rt.autoGenerateMips  = false;
            rt.dimension         = TextureDimension.Tex2DArray;
            rt.volumeDepth       = maximumPoolCapacity;
            rt.enableRandomWrite = true;
            rt.filterMode        = FilterMode.Trilinear;
            rt.wrapMode          = TextureWrapMode.Repeat;
            rt.Create();
            indexPool = new NativeList <int>(maximumPoolCapacity, maximumPoolCapacity, Allocator.Persistent);
            for (int i = 0; i < maximumPoolCapacity; ++i)
            {
                indexPool[i] = i;
            }
            usageCount  = new NativeArray <int>(maximumPoolCapacity, Allocator.Persistent, NativeArrayOptions.ClearMemory);
            guidToIndex = new Dictionary <AssetReference, int>(maximumPoolCapacity);
        }
        public void Awake(MonoBehaviour behavior)
        {
            current          = this;
            addList          = new NativeList <ulong>(10, Allocator.Persistent);
            this.behavior    = behavior;
            baseBuffer       = new PipelineBaseBuffer();
            clusterResources = Resources.Load <ClusterMatResources>("MapMat/" + mapResources);
            int clusterCount = 0;

            allScenes = new List <SceneStreaming>(clusterResources.clusterProperties.Count);
            foreach (var i in clusterResources.clusterProperties)
            {
                clusterCount += i.clusterCount;
                allScenes.Add(new SceneStreaming(i));
            }
            PipelineFunctions.InitBaseBuffer(baseBuffer, clusterResources, mapResources, clusterCount);
            pointerContainer = new NativeList <ulong>(clusterCount, Allocator.Persistent);
            commandQueue     = new LoadingCommandQueue();
            RenderTextureDescriptor desc = new RenderTextureDescriptor
            {
                autoGenerateMips   = false,
                bindMS             = false,
                colorFormat        = RenderTextureFormat.ARGB32,
                depthBufferBits    = 0,
                dimension          = TextureDimension.Tex2DArray,
                enableRandomWrite  = false,
                height             = resolution,
                width              = resolution,
                memoryless         = RenderTextureMemoryless.None,
                msaaSamples        = 1,
                vrUsage            = VRTextureUsage.None,
                volumeDepth        = texArrayCapacity,
                shadowSamplingMode = ShadowSamplingMode.None,
                sRGB      = false,
                useMipMap = false
            };

            commonData = new SceneCommonData
            {
                texDict              = new Dictionary <string, SceneCommonData.TextureIdentifier>(),
                avaiableProperties   = new NativeList <int>(propertyCapacity, Allocator.Persistent),
                avaiableTexs         = new NativeList <int>(texArrayCapacity, Allocator.Persistent),
                texCopyBuffer        = new ComputeBuffer(resolution * resolution, sizeof(int)),
                propertyBuffer       = new ComputeBuffer(propertyCapacity, sizeof(PropertyValue)),
                copyTextureMat       = new Material(RenderPipeline.current.resources.copyShader),
                texArray             = new RenderTexture(desc),
                clusterMaterial      = new Material(RenderPipeline.current.resources.clusterRenderShader),
                terrainMaterial      = new Material(RenderPipeline.current.resources.terrainShader),
                terrainDrawStreaming = new TerrainDrawStreaming(100, 16, RenderPipeline.current.resources.terrainCompute)
            };
            commonData.clusterMaterial.SetBuffer(ShaderIDs._PropertiesBuffer, commonData.propertyBuffer);
            commonData.clusterMaterial.SetTexture(ShaderIDs._MainTex, commonData.texArray);
            commonData.copyTextureMat.SetVector("_TextureSize", new Vector4(resolution, resolution));
            commonData.copyTextureMat.SetBuffer("_TextureBuffer", commonData.texCopyBuffer);
            for (int i = 0; i < propertyCapacity; ++i)
            {
                commonData.avaiableProperties.Add(i);
            }
            for (int i = 0; i < texArrayCapacity; ++i)
            {
                commonData.avaiableTexs.Add(i);
            }
            testNodeArray = new NativeList <ulong>(terrainTransforms.Length, Allocator.Persistent);
            foreach (var i in terrainTransforms)
            {
                TerrainQuadTree.QuadTreeNode *testNode = (TerrainQuadTree.QuadTreeNode *)UnsafeUtility.Malloc(sizeof(TerrainQuadTree.QuadTreeNode), 16, Allocator.Persistent);
                testNode->listPosition = -1;
                ref TerrainPanel panel = ref testNode->panel;
                if (i.localScale.x > 1.1f)
                {
                    panel.edgeFlag = 0;
                }
                else
                {
                    panel.edgeFlag = 15;
                }
                panel.extent         = i.localScale * 0.5f;
                panel.position       = i.position;
                panel.textureIndex   = 0;
                panel.heightMapIndex = 0;
                testNodeArray.Add((ulong)testNode);
            }
        public void TryThis()
        {
            bool save = false;

            if (res == null)
            {
                save     = true;
                res      = ScriptableObject.CreateInstance <ClusterMatResources>();
                res.name = "SceneManager";
                res.clusterProperties = new List <ClusterProperty>();
            }

            ClusterProperty property = new ClusterProperty();

            property.name = modelName;
            int containIndex = -1;

            for (int i = 0; i < res.clusterProperties.Count; ++i)
            {
                if (property.name == res.clusterProperties[i].name)
                {
                    containIndex = i;
                    break;
                }
            }
            LODGroup[] groups = GetComponentsInChildren <LODGroup>();
            Dictionary <MeshRenderer, bool> lowLevelDict = new Dictionary <MeshRenderer, bool>();

            foreach (var i in groups)
            {
                LOD[] lods = i.GetLODs();
                for (int j = 1; j < lods.Length; ++j)
                {
                    foreach (var k in lods[j].renderers)
                    {
                        if (k.GetType() == typeof(MeshRenderer))
                        {
                            lowLevelDict.Add(k as MeshRenderer, true);
                        }
                    }
                }
            }
            CombinedModel model = ProcessCluster(GetComponentsInChildren <MeshRenderer>(false), lowLevelDict);

            property.vm              = model.vm;
            property.clusterCount    = ClusterGenerator.GenerateCluster(model.allPoints, model.allMatIndex, model.bound, modelName, voxelCount, containIndex < 0 ? res.clusterProperties.Count : containIndex);
            res.maximumMaterialCount = Mathf.Max(1, res.maximumMaterialCount);
            res.maximumMaterialCount = Mathf.Max(res.maximumMaterialCount, model.vm.allProperties.Count);
            if (containIndex < 0)
            {
                res.clusterProperties.Add(property);
            }
            else
            {
                res.clusterProperties[containIndex] = property;
            }
            if (save)
            {
                AssetDatabase.CreateAsset(res, "Assets/SceneManager.asset");
            }
            else
            {
                EditorUtility.SetDirty(res);
            }
        }
Example #17
0
        public void TryThis()
        {
            string fileName = ClusterMatResources.infosPath + modelName + ".mpipe";

            if (!property)
            {
                Debug.LogError("Property Empty!");
            }

            if (string.IsNullOrEmpty(modelName))
            {
                Debug.LogError("Name Empty!");
                return;
            }
            if (File.Exists(fileName))
            {
                Debug.LogError("File Already Exists!");
                return;
            }


            bool save = false;

            if (!res)
            {
                res = AssetDatabase.LoadAssetAtPath <ClusterMatResources>("Assets/SceneManager.asset");
            }
            if (!res)
            {
                save     = true;
                res      = ScriptableObject.CreateInstance <ClusterMatResources>();
                res.name = "SceneManager";
            }
            SceneStreamLoader loader = new SceneStreamLoader();

            loader.fsm        = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            property.fileName = modelName;
            LODGroup[] groups = GetComponentsInChildren <LODGroup>();
            Dictionary <MeshRenderer, bool> lowLevelDict = new Dictionary <MeshRenderer, bool>();

            foreach (var i in groups)
            {
                LOD[] lods = i.GetLODs();
                for (int j = 1; j < lods.Length; ++j)
                {
                    foreach (var k in lods[j].renderers)
                    {
                        if (k.GetType() == typeof(MeshRenderer))
                        {
                            lowLevelDict.Add(k as MeshRenderer, true);
                        }
                    }
                }
            }
            CombinedModel model = ProcessCluster(GetComponentsInChildren <MeshRenderer>(false), ref loader, lowLevelDict);

            loader.clusterCount = ClusterGenerator.GenerateCluster(model.allPoints, model.allMatIndex, model.bound, voxelCount, ref loader);

            res.maximumMaterialCount = Mathf.Max(1, res.maximumMaterialCount);
            res.maximumMaterialCount = Mathf.Max(res.maximumMaterialCount, loader.allProperties.Length);
            if (save)
            {
                AssetDatabase.CreateAsset(res, "Assets/SceneManager.asset");
            }
            else
            {
                EditorUtility.SetDirty(res);
            }
            loader.SaveAll();
            loader.Dispose();
        }