コード例 #1
0
        public void Execute()
        {
            List <MLight> allSpotLight  = MLight.avaliableSpotShadowIndices;
            List <MLight> allPointLight = MLight.avaliableCubemapIndices;
            UIntPtr *     allPtr        = stackalloc UIntPtr[max(spotExists ? allSpotLight.Count : 0, pointExists ? allPointLight.Count : 0)];
            int           ptrCount      = 0;

            if (spotExists)
            {
                for (int i = 0; i < allSpotLight.Count; ++i)
                {
                    ref Cone c   = ref allSpotLightPosition[i];
                    float3   dir = c.vertex - cameraPos;
                    if (!VectorUtility.ConeIntersect(allSpotLightPosition[i], VectorUtility.GetPlane(dir, cameraPos + dir * shadowDistance)))
                    {
                        allPtr[ptrCount] = new UIntPtr(MUnsafeUtility.GetManagedPtr(allSpotLight[i]));
                        ptrCount++;
                    }
                }
                for (int i = 0; i < ptrCount; ++i)
                {
                    MLight ml = MUnsafeUtility.GetObject <MLight>(allPtr[i].ToPointer());
                    ml.RemoveLightFromAtlas(false);
                    ml.updateShadowCache = true;
                }
            }
コード例 #2
0
        public override void PreRenderFrame(PipelineCamera cam, ref PipelineCommandData data)
        {
            culler.PreRenderFrame(ref data);
            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 = data.cullResults.visibleLights;

            LightFilter.allVisibleLight = visLights.Ptr();
            allLights.Clear();
            foreach (var i in visLights)
            {
                allLights.Add(i.light);
            }
            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;

            lightingHandle = (new LightFilter {
                cullPlane = VectorUtility.GetPlane(camTrans.forward, camTrans.position + camTrans.forward * localLightDistance)
            }).Schedule(allLights.Count, 1);
            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);
                PipelineFunctions.GetfrustumCorners(clipDistances, SunLight.CASCADELEVELCOUNT + 1, cam.cam, staticFit.frustumCorners.Ptr());
                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);
            }
        }