public static void UpdateData(ref CubeCullingBuffer buffer, PipelineBaseBuffer baseBuffer, ComputeShader shader, CommandBuffer cb, NativeArray <Vector4> positions)
        {
            cb.SetComputeBufferParam(shader, ClearCluster, ShaderIDs.instanceCountBuffer, buffer.indirectDrawBuffer);
            cb.SetComputeBufferParam(shader, RunFrustumCull, ShaderIDs.instanceCountBuffer, buffer.indirectDrawBuffer);
            cb.SetComputeBufferParam(shader, RunFrustumCull, ShaderIDs.clusterBuffer, baseBuffer.clusterBuffer);
            cb.SetComputeBufferParam(shader, RunFrustumCull, ShaderIDs.resultBuffer, baseBuffer.resultBuffer);
            cb.SetComputeBufferParam(shader, RunFrustumCull, ShaderIDs.planes, buffer.planes);
            cb.SetComputeBufferParam(shader, GetFrustumPlane, ShaderIDs.planes, buffer.planes);
            cb.SetComputeBufferParam(shader, GetFrustumPlane, ShaderIDs.lightPositionBuffer, buffer.lightPositionBuffer);
            int targetLength = positions.Length;

            buffer.lightPositionBuffer.SetData(positions);
            ComputeShaderUtility.Dispatch(shader, cb, ClearCluster, targetLength, 256);
            ComputeShaderUtility.Dispatch(shader, cb, GetFrustumPlane, targetLength, 16);
        }
Пример #2
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);
        }
        private void GenerateRunSync()
        {
            PipelineResources  resources  = RenderPipeline.current.resources;
            PipelineBaseBuffer baseBuffer = SceneController.baseBuffer;

            baseBuffer.clusterBuffer.SetData(clusterBuffer, 0, baseBuffer.clusterCount, clusterBuffer.Length);
            baseBuffer.verticesBuffer.SetData(pointsBuffer, 0, baseBuffer.clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, clusterBuffer.Length * PipelineBaseBuffer.CLUSTERCLIPCOUNT);
            int clusterCount = clusterBuffer.Length;

            clusterBuffer.Dispose();
            pointsBuffer.Dispose();
            loading = false;
            state   = State.Loaded;
            baseBuffer.clusterCount += clusterCount;
            Debug.Log("Loaded");
        }
        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);
        }
        private bool GenerateRun(ref PipelineBaseBuffer baseBuffer, PipelineResources resources)
        {
            int targetCount = currentCount + MAXIMUMVERTCOUNT;

            if (targetCount >= clusterBuffer.Length)
            {
                baseBuffer.clusterBuffer.SetData(clusterBuffer, currentCount, currentCount + baseBuffer.clusterCount, clusterBuffer.Length - currentCount);
                baseBuffer.verticesBuffer.SetData(pointsBuffer, currentCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, (currentCount + baseBuffer.clusterCount) * PipelineBaseBuffer.CLUSTERCLIPCOUNT, (clusterBuffer.Length - currentCount) * PipelineBaseBuffer.CLUSTERCLIPCOUNT);
                baseBuffer.clusterCount += clusterBuffer.Length;
                clusterBuffer.Dispose();
                pointsBuffer.Dispose();
                loading = false;
                state   = State.Loaded;
                return(true);
            }
            else
            {
                baseBuffer.clusterBuffer.SetData(clusterBuffer, currentCount, currentCount + baseBuffer.clusterCount, MAXIMUMVERTCOUNT);
                baseBuffer.verticesBuffer.SetData(pointsBuffer, currentCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, (currentCount + baseBuffer.clusterCount) * PipelineBaseBuffer.CLUSTERCLIPCOUNT, MAXIMUMVERTCOUNT * PipelineBaseBuffer.CLUSTERCLIPCOUNT);
                currentCount = targetCount;
                return(false);
            }
        }
Пример #7
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
            };
        }
Пример #8
0
 private static bool GetBaseBuffer(out PipelineBaseBuffer result)
 {
     result = baseBuffer;
     return(result.clusterCount > 0);
 }
Пример #9
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);
            commandQueue     = new LoadingCommandQueue();
            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
            };

            commonData = new SceneCommonData
            {
                texDict              = new Dictionary <string, SceneCommonData.TextureIdentifier>(texArrayCapacity),
                lightmapDict         = new Dictionary <string, SceneCommonData.TextureIdentifier>(lightmapCapacity),
                avaiableProperties   = new NativeList <int>(propertyCapacity, Allocator.Persistent),
                avaiableTexs         = new NativeList <int>(texArrayCapacity, Allocator.Persistent),
                avaiableLightmap     = new NativeList <int>(lightmapCapacity, Allocator.Persistent),
                texCopyBuffer        = new ComputeBuffer(resolution * resolution, sizeof(int)),
                lightmapCopyBuffer   = new ComputeBuffer(lightmapResolution * lightmapResolution, sizeof(int)),
                propertyBuffer       = new ComputeBuffer(propertyCapacity, sizeof(PropertyValue)),
                texArray             = new RenderTexture(desc),
                clusterMaterial      = new Material(resources.shaders.clusterRenderShader),
                terrainMaterial      = new Material(resources.shaders.terrainShader),
                terrainDrawStreaming = new TerrainDrawStreaming(100, 16, resources.shaders.terrainCompute),
                allTempBuffers       = new Dictionary <int, ComputeBuffer>(11)
            };
            commonData.texArray.wrapMode = TextureWrapMode.Repeat;
            desc.volumeDepth             = lightmapCapacity;
            desc.width               = lightmapResolution;
            desc.height              = lightmapResolution;
            desc.colorFormat         = RenderTextureFormat.RGB111110Float;
            commonData.lightmapArray = new RenderTexture(desc);
            for (int i = 0; i < propertyCapacity; ++i)
            {
                commonData.avaiableProperties.Add(i);
            }
            for (int i = 0; i < texArrayCapacity; ++i)
            {
                commonData.avaiableTexs.Add(i);
            }
            for (int i = 0; i < lightmapCapacity; ++i)
            {
                commonData.avaiableLightmap.Add(i);
            }
            commonData.lightmapArray.Create();
            commonData.texArray.Create();
        }
 public virtual bool GetBaseBuffer(out PipelineBaseBuffer result)
 {
     result = null;
     return(false);
 }
 public override bool GetBaseBuffer(out PipelineBaseBuffer result)
 {
     result = baseBuffer;
     return(true);
 }
 public override bool GetBaseBufferAndCheck(out PipelineBaseBuffer result)
 {
     result = baseBuffer;
     return(result.clusterCount > 0);
 }
Пример #13
0
        public static void DrawShadow(MPointLight lit, CommandBuffer cb, ref CubeCullingBuffer buffer, ref PipelineBaseBuffer baseBuffer, ComputeShader shader, int offset, Material depthMaterial)
        {
            cb.SetComputeIntParam(shader, ShaderIDs._LightOffset, offset);
            ComputeShaderUtility.Dispatch(shader, cb, RunFrustumCull, baseBuffer.clusterCount, 256);
            PerspCam cam = new PerspCam();

            cam.aspect        = 1;
            cam.farClipPlane  = lit.range;
            cam.nearClipPlane = 0.3f;
            cam.position      = lit.position;
            cam.fov           = 90f;
            Matrix4x4 vpMatrix;

            cb.SetGlobalVector(ShaderIDs._LightPos, new Vector4(lit.position.x, lit.position.y, lit.position.z, lit.range));
            PipelineFunctions.SetShaderBuffer(ref baseBuffer, cb);
            //Forward
            cam.forward  = Vector3.forward;
            cam.up       = Vector3.down;
            cam.right    = Vector3.left;
            cam.position = lit.position;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeZ);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            offset = offset * 20;
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Back
            cam.forward = Vector3.back;
            cam.up      = Vector3.down;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveZ);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Up
            cam.forward = Vector3.up;
            cam.up      = Vector3.back;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveY);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Down
            cam.forward = Vector3.down;
            cam.up      = Vector3.forward;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeY);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Right
            cam.forward = Vector3.right;
            cam.up      = Vector3.down;
            cam.right   = Vector3.forward;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveX);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Left
            cam.forward = Vector3.left;
            cam.up      = Vector3.down;
            cam.right   = Vector3.back;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeX);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
        }
        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);
            }