Exemple #1
0
        public void GenerateAsync(bool listCommand = true)
        {
            clusterBuffer = new NativeArray <CullBox>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            pointsBuffer  = new NativeArray <Point>(property.clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            indicesBuffer = new NativeArray <int>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            NativeList <ulong> pointerContainer = SceneController.pointerContainer;

            pointerContainer.AddCapacityTo(pointerContainer.Length + indicesBuffer.Length);
            CullBox *      clusterData  = clusterBuffer.Ptr();
            Point *        verticesData = pointsBuffer.Ptr();
            const string   infosPath    = "Assets/BinaryData/MapInfos/";
            const string   pointsPath   = "Assets/BinaryData/MapPoints/";
            MStringBuilder sb           = new MStringBuilder(pointsPath.Length + property.name.Length + ".txt".Length);

            allStrings[0] = infosPath;
            allStrings[1] = property.name;
            allStrings[2] = ".txt";
            sb.Combine(allStrings);
            using (BinaryReader reader = new BinaryReader(File.Open(sb.str, FileMode.Open)))
            {
                byte[] bytes = reader.ReadBytes((int)reader.BaseStream.Length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(clusterData, b, bytes.Length);
                }
            }
            allStrings[0] = pointsPath;
            sb.Combine(allStrings);
            using (BinaryReader reader = new BinaryReader(File.Open(sb.str, FileMode.Open)))
            {
                byte[] bytes = reader.ReadBytes((int)reader.BaseStream.Length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(verticesData, b, bytes.Length);
                }
            }
            int *indicesPtr = indicesBuffer.Ptr();
            LoadingCommandQueue commandQueue = SceneController.commandQueue;

            for (int i = 0; i < indicesBuffer.Length; ++i)
            {
                indicesPtr[i] = pointerContainer.Length;
                pointerContainer.Add((ulong)(indicesPtr + i));
            }
            LoadTextures();
            propertiesPool = SceneController.commonData.GetPropertyIndex(property.properties.Length);
            uint *poolPtr = propertiesPool.Ptr();

            for (int i = 0; i < pointsBuffer.Length; ++i)
            {
                verticesData[i].objIndex = poolPtr[verticesData[i].objIndex];
            }
            if (listCommand)
            {
                lock (commandQueue)
                {
                    commandQueue.Queue(GenerateRun());
                }
            }
        }
        //TODO
        //Use some clever resources loading system
        public IEnumerator Generate()
        {
            if (state == State.Unloaded)
            {
                state = State.Loading;
                while (loading)
                {
                    yield return(null);
                }
                loading       = true;
                clusterBuffer = new NativeArray <ClusterMeshData>(length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                pointsBuffer  = new NativeArray <Point>(length * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                indicesBuffer = new NativeArray <int>(length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                ResourceRequest clusterRequest = Resources.LoadAsync <TextAsset>("MapInfos/" + fileName);
                ResourceRequest pointsRequest  = Resources.LoadAsync <TextAsset>("MapPoints/" + fileName);
                yield return(clusterRequest);

                yield return(pointsRequest);

                pointBytesArray   = ((TextAsset)pointsRequest.asset).bytes;
                clusterBytesArray = ((TextAsset)clusterRequest.asset).bytes;
                Resources.UnloadAsset(pointsRequest.asset);
                Resources.UnloadAsset(clusterRequest.asset);
                pointerContainer.AddCapacityTo(pointerContainer.Length + indicesBuffer.Length);
                LoadingThread.AddCommand(generateAsyncFunc);
            }
        }
Exemple #3
0
        public void GenerateAsync(bool listCommand = true)
        {
            clusterBuffer = new NativeArray <CullBox>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            pointsBuffer  = new NativeArray <float3>(property.clusterCount * PipelineBaseBuffer.CLUSTERCLIPCOUNT, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            indicesBuffer = new NativeArray <int>(property.clusterCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
            NativeList <ulong> pointerContainer = SceneController.pointerContainer;

            pointerContainer.AddCapacityTo(pointerContainer.Length + indicesBuffer.Length);
            CullBox *      clusterData  = clusterBuffer.Ptr();
            float3 *       verticesData = pointsBuffer.Ptr();
            const string   infosPath    = "Assets/BinaryData/MapInfos/";
            const string   pointsPath   = "Assets/BinaryData/MapPoints/";
            MStringBuilder sb           = new MStringBuilder(pointsPath.Length + property.name.Length + ".mpipe".Length);

            allStrings[0] = infosPath;
            allStrings[1] = property.name;
            allStrings[2] = ".mpipe";
            sb.Combine(allStrings);
            // FileStream fileStream = new FileStream(sb.str, FileMode.Open, FileAccess.Read);
            using (FileStream reader = new FileStream(sb.str, FileMode.Open, FileAccess.Read))
            {
                int    length = (int)reader.Length;
                byte[] bytes  = GetByteArray(length);
                reader.Read(bytes, 0, length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(clusterData, b, length);
                }
            }
            allStrings[0] = pointsPath;
            sb.Combine(allStrings);
            using (FileStream reader = new FileStream(sb.str, FileMode.Open, FileAccess.Read))
            {
                int    length = (int)reader.Length;
                byte[] bytes  = GetByteArray(length);
                reader.Read(bytes, 0, length);
                fixed(byte *b = bytes)
                {
                    UnsafeUtility.MemCpy(verticesData, b, length);
                }
            }
            int *indicesPtr = indicesBuffer.Ptr();
            LoadingCommandQueue commandQueue = LoadingThread.commandQueue;

            for (int i = 0; i < indicesBuffer.Length; ++i)
            {
                indicesPtr[i] = pointerContainer.Length;
                pointerContainer.Add((ulong)(indicesPtr + i));
            }

            if (listCommand)
            {
                lock (commandQueue)
                {
                    commandQueue.Queue(GenerateRun());
                }
            }
        }
Exemple #4
0
        public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
        {
            float shadowDist = clamp(shadowDistance, 0, cam.cam.farClipPlane);

            if (SunLight.current && SunLight.current.enabled && SunLight.current.gameObject.activeSelf)
            {
                data.buffer.EnableShaderKeyword("ENABLE_SUN");
                data.buffer.SetKeyword("ENABLE_SUNSHADOW", SunLight.current.enableShadow);
            }
            else
            {
                data.buffer.DisableShaderKeyword("ENABLE_SUN");
            }
            var visLights = proper.cullResults.visibleLights;

            LightFilter.allVisibleLight = visLights.Ptr();
            allLights.Clear();
            foreach (var i in visLights)
            {
                allLights.Add(i.light);
            }
            shadowCheckJob.Init(cam.cam, shadowDistance);
            shadowCullHandle = shadowCheckJob.ScheduleRef();
            addMLightCommandList.Clear();
            LightFilter.allMLightCommandList = addMLightCommandList;
            pointLightArray               = new NativeArray <PointLightStruct>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            spotLightArray                = new NativeArray <SpotLight>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            cubemapVPMatrices             = new NativeList <CubemapViewProjMatrix>(CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT, Allocator.Temp);
            spotLightMatrices             = new NativeList <SpotLightMatrix>(CBDRSharedData.MAXIMUMSPOTLIGHTCOUNT, Allocator.Temp);
            LightFilter.allLights         = allLights;
            LightFilter.pointLightArray   = pointLightArray;
            LightFilter.spotLightArray    = spotLightArray;
            LightFilter.cubemapVPMatrices = cubemapVPMatrices;
            LightFilter.spotLightMatrices = spotLightMatrices;
            Transform camTrans = cam.cam.transform;

            needCheckedShadows.Clear();
            needCheckedShadows.AddCapacityTo(allLights.Count);
            lightingHandle = (new LightFilter
            {
                camPos = cam.cam.transform.position,
                shadowDist = shadowDist,
                lightDist = cbdrDistance,
                needCheckLight = needCheckedShadows
            }).Schedule(allLights.Count, 1, shadowCullHandle);
            if (SunLight.current != null && SunLight.current.enabled && SunLight.current.enableShadow)
            {
                clipDistances = (float *)UnsafeUtility.Malloc(SunLight.CASCADECLIPSIZE * sizeof(float), 16, Allocator.Temp);
                staticFit     = DirectionalShadowStaticFit(cam.cam, SunLight.current, clipDistances);
                sunShadowCams = MUnsafeUtility.Malloc <OrthoCam>(SunLight.CASCADELEVELCOUNT * sizeof(OrthoCam), Allocator.Temp);
                Matrix4x4 proj = cam.cam.projectionMatrix;
                //      cam.cam.projectionMatrix = cam.cam.nonJitteredProjectionMatrix;
                PipelineFunctions.GetfrustumCorners(clipDistances, SunLight.CASCADELEVELCOUNT + 1, cam.cam, staticFit.frustumCorners.Ptr());
                //   cam.cam.projectionMatrix = proj;
                csmStruct = new CascadeShadowmap
                {
                    cascadeShadowmapVPs = (float4x4 *)cascadeShadowMapVP.Ptr(),
                    results             = sunShadowCams,
                    orthoCam            = (OrthoCam *)UnsafeUtility.AddressOf(ref SunLight.current.shadCam),
                    farClipPlane        = SunLight.current.farestZ,
                    frustumCorners      = staticFit.frustumCorners.Ptr(),
                    resolution          = staticFit.resolution,
                    isD3D = GraphicsUtility.platformIsD3D
                };
                csmHandle = csmStruct.ScheduleRefBurst(SunLight.CASCADELEVELCOUNT, 1);
            }
        }
Exemple #5
0
        public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
        {
            float shadowDist = clamp(shadowDistance, 0, cam.cam.farClipPlane);

            if (SunLight.current && SunLight.current.enabled && SunLight.current.gameObject.activeSelf)
            {
                lightEnabledSettings.x = SunLight.current.sunlightOnlyForVolumetricLight ? 0 : 1;
                lightEnabledSettings.y = SunLight.current.enableShadow ? 1 : 0;
            }
            else
            {
                lightEnabledSettings.x = 0;
            }
            var visLights = proper.cullResults.visibleLights;

            LightFilter.allVisibleLight = visLights.Ptr();
            allLights.Clear();
            foreach (var i in visLights)
            {
                allLights.Add(i.light);
            }
            shadowCheckJob.Init(cam.cam, shadowDistance);
            shadowCullHandle = shadowCheckJob.ScheduleRef();
            addMLightCommandList.Clear();
            LightFilter.allMLightCommandList = addMLightCommandList;
            pointLightArray   = new NativeArray <PointLightStruct>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            spotLightArray    = new NativeArray <SpotLight>(visLights.Length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            cubemapVPMatrices = new NativeList <CubemapViewProjMatrix>(CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT, Allocator.Temp);
            spotLightMatrices = new NativeList <SpotLightMatrix>(CBDRSharedData.MAXIMUMSPOTLIGHTCOUNT, Allocator.Temp);
            NativeList_ulong allSpotCustomCullResults  = new NativeList_ulong(CBDRSharedData.MAXIMUMSPOTLIGHTCOUNT, Allocator.Temp);
            NativeList_ulong allPointCustomCullResults = new NativeList_ulong(CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT, Allocator.Temp);

            LightFilter.allLights         = allLights;
            LightFilter.pointLightArray   = pointLightArray;
            LightFilter.spotLightArray    = spotLightArray;
            LightFilter.cubemapVPMatrices = cubemapVPMatrices;
            LightFilter.spotLightMatrices = spotLightMatrices;
            Transform camTrans = cam.cam.transform;

            needCheckedShadows.Clear();
            needCheckedShadows.AddCapacityTo(allLights.Count);
            lightingHandle = (new LightFilter
            {
                camPos = cam.cam.transform.position,
                shadowDist = shadowDist,
                lightDist = cbdrDistance,
                needCheckLight = needCheckedShadows,
                allSpotCustomDrawRequests = allSpotCustomCullResults,
                allPointCustomDrawRequests = allPointCustomCullResults
            }).Schedule(allLights.Count, max(1, allLights.Count / 4), shadowCullHandle);
            spotLightCustomCullHandle = new SpotLightCull
            {
                ptrs           = allSpotCustomCullResults,
                drawShadowList = CustomDrawRequest.drawShadowList
            }.Schedule(2, 1, lightingHandle);
            pointLightCustomCullHandle = new PointLightCull
            {
                ptrs           = allPointCustomCullResults,
                drawShadowList = CustomDrawRequest.drawShadowList
            }.Schedule(2, 1, lightingHandle);
            if (SunLight.current != null && SunLight.current.enabled && SunLight.current.enableShadow)
            {
                clipDistances = (float *)UnsafeUtility.Malloc(SunLight.CASCADECLIPSIZE * sizeof(float), 16, Allocator.Temp);
                staticFit     = DirectionalShadowStaticFit(cam.cam, SunLight.current, clipDistances);
                sunShadowCams = MUnsafeUtility.Malloc <OrthoCam>(SunLight.CASCADELEVELCOUNT * sizeof(OrthoCam), Allocator.Temp);
                Matrix4x4 proj = cam.cam.projectionMatrix;
                //      cam.cam.projectionMatrix = cam.cam.nonJitteredProjectionMatrix;
                PipelineFunctions.GetfrustumCorners(clipDistances, SunLight.CASCADELEVELCOUNT + 1, cam.cam, staticFit.frustumCorners.Ptr());
                //   cam.cam.projectionMatrix = proj;
                csmStruct = new CascadeShadowmap
                {
                    cascadeShadowmapVPs = (float4x4 *)cascadeShadowMapVP.Ptr(),
                    results             = sunShadowCams,
                    orthoCam            = (OrthoCam *)UnsafeUtility.AddressOf(ref SunLight.current.shadCam),
                    farClipPlane        = SunLight.current.farestZ,
                    frustumCorners      = staticFit.frustumCorners.Ptr(),
                    resolution          = staticFit.resolution,
                    isD3D = GraphicsUtility.platformIsD3D
                };
                csmHandle = csmStruct.ScheduleRefBurst(SunLight.CASCADELEVELCOUNT, max(1, SunLight.CASCADELEVELCOUNT / 4));
                for (int i = 0; i < SunLight.CASCADELEVELCOUNT; ++i)
                {
                    SunLight.customCullResults[i] = new NativeList_Int(CustomDrawRequest.drawShadowList.Length, Allocator.Temp);
                }
                sunCullResultHandle = new SunCustomRenderCull
                {
                    cams        = sunShadowCams,
                    cullResults = SunLight.customCullResults.Ptr()
                }.Schedule(SunLight.CASCADELEVELCOUNT, 1, csmHandle);
            }
        }