예제 #1
0
        public RenderPipeline(PipelineResources resources)
        {
            resources.SetRenderingPath();
            var allEvents = resources.allEvents;

            GraphicsUtility.UpdatePlatform();
            MLight.ClearLightDict();
            this.resources     = resources;
            current            = this;
            data.buffer        = new CommandBuffer();
            data.frustumPlanes = new Vector4[6];

            for (int i = 0; i < allEvents.Length; ++i)
            {
                PipelineEvent[] events = allEvents[i];
                if (events == null)
                {
                    continue;
                }
                foreach (var j in events)
                {
                    j.Prepare((PipelineResources.CameraRenderingPath)i);
                }
                foreach (var j in events)
                {
                    j.InitEvent(resources);
                }
            }
        }
        private void PointLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            VoxelLightCommonData(buffer, cam.cam);
            lightingHandle.Complete();
            foreach (var i in addMLightCommandList)
            {
                MLight.AddMLight(i);
            }
            addMLightCommandList.Clear();
            int count = Mathf.Min(cubemapVPMatrices.Length, CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT);

            cbdr.pointshadowCount = count;
            if (LightFilter.pointLightCount > 0)
            {
                if (count > 0)
                {
                    var cullShader = data.resources.shaders.gpuFrustumCulling;
                    buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap);
                    NativeArray <VisibleLight> allLights     = data.cullResults.visibleLights;
                    PointLightStruct *         pointLightPtr = pointLightArray.Ptr();

                    for (int i = 0; i < count; ++i)
                    {
                        ref CubemapViewProjMatrix vpMatrices = ref cubemapVPMatrices[i];
                        int2   lightIndex = vpMatrices.index;
                        Light  lt         = allLights[lightIndex.y].light;
                        MLight light      = MUnsafeUtility.GetObject <MLight>(vpMatrices.mLightPtr);
                        if (light.useShadowCache)
                        {
                            light.UpdateShadowCacheType(true);
                            if (light.updateShadowCache)
                            {
                                light.updateShadowCache = false;
                                SceneController.DrawPointLight(light, shadowLayer, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, buffer, cullShader, i, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap, cam.inverseRender);
                                int offset = i * 6;
                                for (int a = 0; a < 6; ++a)
                                {
                                    buffer.CopyTexture(cbdr.cubeArrayMap, offset + a, light.shadowMap, a);
                                }
                            }
                            else
                            {
                                PipelineFunctions.CopyToCubeMap(cbdr.cubeArrayMap, light.shadowMap, buffer, i);
                            }
                        }
                        else
                        {
                            SceneController.DrawPointLight(light, shadowLayer, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, buffer, cullShader, i, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap, cam.inverseRender);
                        }

                        //TODO
                        //Multi frame shadowmap
                    }
                }
                SetPointLightBuffer(pointLightArray, LightFilter.pointLightCount);
                buffer.EnableShaderKeyword("POINTLIGHT");
                cbdr.lightFlag |= 1;
            }
 public RenderPipeline(GameObject pipelinePrefab, PipelineResources resources)
 {
     allDrawEvents.Clear();
     MLight.ClearLightDict();
     this.pipelinePrefab = pipelinePrefab;
     this.resources      = resources;
     current             = this;
     data.buffer         = new CommandBuffer();
     data.frustumPlanes  = new Vector4[6];
     allEvents           = pipelinePrefab.GetComponentsInChildren <PipelineEvent>();
     foreach (var i in allEvents)
     {
         i.InitEvent(resources);
     }
 }