Ejemplo n.º 1
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (current == this)
            {
                current = null;
            }
            iRunnableObjects.Dispose();
            CustomDrawRequest.Dispose();
            if (m_afterFrameBuffer != null)
            {
                m_afterFrameBuffer.Dispose();
                m_afterFrameBuffer = null;
            }
            if (m_beforeFrameBuffer != null)
            {
                m_beforeFrameBuffer.Dispose();
                m_beforeFrameBuffer = null;
            }

            try
            {
                eventsGuideBook.Dispose();
                waitReleaseRT.Dispose();
            }
            catch { }
            SceneController.Dispose(resources);
            resources.loadingThread.Dispose();
            data.buffer.Dispose();
            var allEvents = resources.allEvents;

            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                resources.availiableEvents[i].DisposeEvent();
            }
            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                resources.availiableEvents[i].DisposeDependEventsList();
            }

            foreach (var camPtr in PipelineCamera.CameraSearchDict)
            {
                PipelineCamera cam = MUnsafeUtility.GetObject <PipelineCamera>((void *)camPtr.value);
                if (cam.allDatas.isCreated)
                {
                    foreach (var i in cam.allDatas)
                    {
                        IPerCameraData data = ((IPerCameraData)MUnsafeUtility.GetHookedObject(i.value));
                        data.DisposeProperty();
                        MUnsafeUtility.RemoveHookedObject(i.value);
                    }
                    cam.allDatas.Dispose();
                }
            }
            if (motionVectorMatricesBuffer != null)
            {
                motionVectorMatricesBuffer.Dispose();
            }
            MotionVectorDrawer.Dispose();
        }
Ejemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            eventsGuideBook.Dispose();
            waitReleaseRT.Dispose();
            base.Dispose(disposing);
            if (current == this)
            {
                current = null;
            }
            data.buffer.Dispose();
            var allEvents = resources.allEvents;

            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                resources.availiableEvents[i].DisposeEvent();
            }
            for (int i = 0; i < resources.availiableEvents.Length; ++i)
            {
                resources.availiableEvents[i].DisposeDependEventsList();
            }
            if (PipelineCamera.allCamera.isCreated)
            {
                foreach (var i in PipelineCamera.allCamera)
                {
                    PipelineCamera cam    = MUnsafeUtility.GetObject <PipelineCamera>(i.value.ToPointer());
                    var            values = cam.allDatas.Values;
                    foreach (var j in values)
                    {
                        j.DisposeProperty();
                    }
                    cam.allDatas.Clear();
                }
            }
        }
Ejemplo n.º 3
0
        private void OnDisable()
        {
            allProbe[index] = allProbe[allProbe.Length - 1];
            AOProbe prb = MUnsafeUtility.GetObject <AOProbe>(allProbe[index].ToPointer());

            prb.index = index;
        }
Ejemplo n.º 4
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 (!MathLib.ConeIntersect(allSpotLightPosition[i], MathLib.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;
                }
            }
Ejemplo n.º 5
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (current != this)
            {
                return;
            }
            current = null;
            data.buffer.Dispose();
            var allEvents = resources.allEvents;

            foreach (var i in allEvents)
            {
                if (i != null)
                {
                    foreach (var j in i)
                    {
                        j.DisposeEvent();
                    }
                }
            }
            foreach (var i in PipelineCamera.allCamera)
            {
                PipelineCamera cam    = MUnsafeUtility.GetObject <PipelineCamera>(i.ToPointer());
                var            values = cam.allDatas.Values;
                foreach (var j in values)
                {
                    j.DisposeProperty();
                }
                cam.allDatas.Clear();
            }
        }
        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;
            }
Ejemplo n.º 7
0
        private void OnDestroy()
        {
            Decal lastDec = MUnsafeUtility.GetObject <Decal>(decalDatas[decalDatas.Length - 1].comp);

            lastDec.index     = index;
            decalDatas[index] = decalDatas[decalDatas.Length - 1];
            decalDatas.RemoveLast();
        }
Ejemplo n.º 8
0
        private void OnDisable()
        {
            AreaVolumeProbe lastProbe = MUnsafeUtility.GetObject <AreaVolumeProbe>(allAreaLight[allAreaLight.Length - 1].componentPtr);

            lastProbe.index     = index;
            allAreaLight[index] = allAreaLight[allAreaLight.Length - 1];
            allAreaLight.RemoveLast();
        }
Ejemplo n.º 9
0
        private void OnDisable()
        {
            *container = allVolumes[allVolumes.Length - 1];
            FogVolumeComponent lastComp = MUnsafeUtility.GetObject <FogVolumeComponent>(container->light);

            lastComp.container = container;
            allVolumes.RemoveLast();
        }
        private void OnDisable()
        {
            allVolumes[index] = allVolumes[allVolumes.Length - 1];
            FogVolumeComponent lastComp = MUnsafeUtility.GetObject <FogVolumeComponent>(allVolumes[index].light);

            lastComp.index = index;
            allVolumes.RemoveLast();
        }
Ejemplo n.º 11
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            if (!enabledPost || !cam.postProfile)
            {
                data.buffer.Blit(cam.targets.renderTargetIdentifier, cam.cameraTarget);
                return;
            }
#if UNITY_EDITOR
            if (!enableInEditor && RenderPipeline.renderingEditor)
            {
                data.buffer.Blit(cam.targets.renderTargetIdentifier, cam.cameraTarget);
                return;
            }
#endif
            NativeDictionary <ulong, ulong, PtrEqual> allSettings = new NativeDictionary <ulong, ulong, PtrEqual>(allPostEffects.Count, Unity.Collections.Allocator.Temp, new PtrEqual());
            foreach (var i in cam.postProfile.settings)
            {
                allSettings.Add((ulong)MUnsafeUtility.GetManagedPtr(i.GetType()), (ulong)MUnsafeUtility.GetManagedPtr(i));
            }
            postContext.camera              = cam.cam;
            postContext.command             = data.buffer;
            postContext.sourceFormat        = RenderTextureFormat.ARGBHalf;
            postContext.autoExposureTexture = RuntimeUtilities.whiteTexture;
            postContext.bloomBufferNameID   = -1;
            RenderTargetIdentifier source, dest;
            postContext.source      = cam.targets.renderTargetIdentifier;
            postContext.destination = cam.targets.backupIdentifier;
            postContext.logHistogram.Generate(postContext);
            cyberGlitch.Render(data.buffer, ref cam.targets);
            foreach (var i in allPostEffects)
            {
                ulong settingsPtr;
                if (allSettings.Get((ulong)MUnsafeUtility.GetManagedPtr(i.type), out settingsPtr))
                {
                    PostProcessEffectSettings setting = MUnsafeUtility.GetObject <PostProcessEffectSettings>((void *)settingsPtr);
                    if (i.needBlit && setting.active)
                    {
                        PipelineFunctions.RunPostProcess(ref cam.targets, out source, out dest);
                        postContext.source      = source;
                        postContext.destination = dest;
                    }
                    i.renderer.SetSettings(setting);
                    i.renderer.Render(postContext);
                }
            }
            ;
            allSettings.Dispose();
            //   data.buffer.Blit(ShaderIDs._CameraMotionVectorsTexture, cam.cameraTarget);
            //     data.buffer.BlitSRT(cam.cameraTarget, debugMat, 0);
            data.buffer.BlitSRT(cam.targets.renderTargetIdentifier, cam.cameraTarget, postContext.uberSheet.material, 0, postContext.uberSheet.properties);
            if (postContext.bloomBufferNameID > -1)
            {
                data.buffer.ReleaseTemporaryRT(postContext.bloomBufferNameID);
            }
        }
Ejemplo n.º 12
0
        private void PointLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            shadowCullHandle.Complete();
            CommandBuffer buffer = data.buffer;

            VoxelLightCommonData(buffer, cam.cam);
            lightingHandle.Complete();
            foreach (var i in addMLightCommandList)
            {
                MLight.AddMLight(i);
            }
            foreach (var i in needCheckedShadows)
            {
                MLight mlt = MUnsafeUtility.GetObject <MLight>(i.mlight.ToPointer());
                mlt.CheckShadowSetting(i.isAvaliable);
            }
            addMLightCommandList.Clear();
            int count = Mathf.Min(cubemapVPMatrices.Length, CBDRSharedData.MAXIMUMPOINTLIGHTCOUNT);

            cbdr.pointshadowCount = count;
            //Calculate PointLight Shadow
            pointLightCustomCullHandle.Complete();
            if (LightFilter.pointLightCount > 0)
            {
                if (count > 0)
                {
                    var cullShader = data.resources.shaders.gpuFrustumCulling;
                    buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap);
                    NativeArray <VisibleLight> allLights     = proper.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);
                        light.CheckShadowCamera();
                        ref PointLightStruct ptLitStr = ref pointLightPtr[lightIndex.x];
                        if (!light.useShadowCache || light.updateShadowCache)
                        {
                            light.updateShadowCache = false;
                            SceneController.DrawPointLight(light, localLightShadowLayer, ref ptLitStr, cubeDepthMaterial, cullShader, ref data, ref vpMatrices, cbdr.cubeArrayMap, cam.inverseRender, proper.overrideOpaqueMaterial);
                        }
                        vpMatrices.customCulledResult.Dispose();
                        if (vpMatrices.frustumPlanes != null)
                        {
                            UnsafeUtility.Free(vpMatrices.frustumPlanes, Allocator.TempJob);
                        }
                        ptLitStr.shadowIndex = light.ShadowIndex;
                        //TODO
                        //Multi frame shadowmap
                    }
                }
Ejemplo n.º 13
0
        private void PointLight(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            pointLightMaterial.SetBuffer(ShaderIDs.verticesBuffer, sphereBuffer);
            VoxelLightCommonData(buffer, cam.cam);
            ClearDispatch(buffer);
            lightingHandle.Complete();
            foreach (var i in addMLightCommandList)
            {
                MLight.AddMLight(i);
            }
            addMLightCommandList.Clear();
            cbdr.pointshadowCount = cubemapVPMatrices.Length;
            if (LightFilter.pointLightCount > 0)
            {
                if (cubemapVPMatrices.Length > 0)
                {
                    var cullShader = data.resources.gpuFrustumCulling;
                    buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap);
                    RenderClusterOptions opts = new RenderClusterOptions
                    {
                        cullingShader = cullShader,
                        command       = buffer,
                        frustumPlanes = null,
                        isOrtho       = false
                    };
                    List <VisibleLight> allLights     = data.cullResults.visibleLights;
                    PointLightStruct *  pointLightPtr = pointLightArray.Ptr();
                    for (int i = 0; i < cubemapVPMatrices.Length; ++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.updateShadowmap)
                        {
                            light.UpdateShadowCacheType(true);
                            SceneController.DrawPointLight(light, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, ref opts, i, light.shadowMap, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap);
                        }
                        else
                        {
                            PipelineFunctions.CopyToCubeMap(cbdr.cubeArrayMap, light.shadowMap, buffer, i);
                        }

                        //TODO
                        //Multi frame shadowmap
                    }
                }
                SetPointLightBuffer(pointLightArray, LightFilter.pointLightCount, buffer);
                buffer.EnableShaderKeyword("POINTLIGHT");
                cbdr.lightFlag |= 1;
            }
Ejemplo n.º 14
0
 public V this[K key]
 {
     get
     {
         Func <K, K, bool> equalsFunc = MUnsafeUtility.GetObject <Func <K, K, bool> >(this.equalsFunc);
         int index      = Mathf.Abs(key.GetHashCode()) % data->capacity;
         K **currentPos = GetK(index);
         while ((*currentPos) != null)
         {
             if (equalsFunc(**currentPos, key))
             {
                 return(*GetV(*currentPos));
             }
             currentPos = GetNextPtr(*currentPos);
         }
         return(default);
Ejemplo n.º 15
0
        public bool Contains(K key)
        {
            Func <K, K, bool> equalsFunc = MUnsafeUtility.GetObject <Func <K, K, bool> >(this.equalsFunc);
            int index      = Mathf.Abs(key.GetHashCode()) % data->capacity;
            K **currentPos = GetK(index);

            while ((*currentPos) != null)
            {
                if (equalsFunc(**currentPos, key))
                {
                    return(true);
                }
                currentPos = GetNextPtr(*currentPos);
            }
            return(false);
        }
        public void SetRenderingPath()
        {
            NativeArray <UIntPtr> allCollection = GetAllPath();

            allEvents = new PipelineEvent[allCollection.Length][];
            Dictionary <Type, PipelineEvent> evtDict = new Dictionary <Type, PipelineEvent>(availiableEvents.Length);

            foreach (var i in availiableEvents)
            {
                evtDict.Add(i.GetType(), i);
            }
            for (int i = 0; i < allCollection.Length; ++i)
            {
                FieldInfo tp = MUnsafeUtility.GetObject <FieldInfo>(allCollection[i].ToPointer());
                Type[]    tt = tp.GetValue(null) as Type[];
                allEvents[i] = GetAllEvents(tt, evtDict);
            }
        }
Ejemplo n.º 17
0
        public void InitEvent(PipelineResources resources)
        {
            if (initialized)
            {
                return;
            }
            initialized = true;
            Init(resources);

            if (enabled)
            {
                if (dependingEvents.isCreated)
                {
                    foreach (var i in dependingEvents)
                    {
                        PipelineEvent evt = MUnsafeUtility.GetObject <PipelineEvent>(i.ToPointer());
                        if (!evt.enabled)
                        {
                            Enabled = false;
                            return;
                        }
                    }
                }
            }
            else
            {
                if (dependedEvents.isCreated)
                {
                    foreach (var i in dependedEvents)
                    {
                        PipelineEvent evt = MUnsafeUtility.GetObject <PipelineEvent>(i.ToPointer());
                        evt.Enabled = false;
                    }
                }
            }
            if (Enabled)
            {
                OnEnable();
            }
            else
            {
                OnDisable();
            }
        }
Ejemplo n.º 18
0
        public void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            handle.Complete();
            buffer.GetTemporaryRT(ShaderIDs._BackupAlbedoMap, cam.cam.pixelWidth, cam.cam.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, false);
            buffer.GetTemporaryRT(ShaderIDs._BackupNormalMap, cam.cam.pixelWidth, cam.cam.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear, 1, false);
            buffer.CopyTexture(cam.targets.gbufferIndex[2], 0, 0, ShaderIDs._BackupNormalMap, 0, 0);
            buffer.CopyTexture(cam.targets.gbufferIndex[0], 0, 0, ShaderIDs._BackupAlbedoMap, 0, 0);
            decalTargets[0] = cam.targets.gbufferIndex[0];
            decalTargets[1] = cam.targets.gbufferIndex[2];
            buffer.SetRenderTarget(colors: decalTargets, depth: ShaderIDs._DepthBufferTexture);
            DecalData *resulPtr = decalCullResults.Ptr();

            for (int i = 0; i < cullJob.count; ++i)
            {
                ref DecalData decal = ref resulPtr[i];
                DecalBase     dec   = MUnsafeUtility.GetObject <DecalBase>(decal.comp);
                dec.DrawDecal(buffer);
            }
Ejemplo n.º 19
0
        public void Remove(K key)
        {
            Func <K, K, bool> equalsFunc = MUnsafeUtility.GetObject <Func <K, K, bool> >(this.equalsFunc);
            int index      = Mathf.Abs(key.GetHashCode()) % data->capacity;
            K **currentPtr = GetK(index);

            while ((*currentPtr) != null)
            {
                K **next = GetNextPtr(*currentPtr);
                if (equalsFunc(**currentPtr, key))
                {
                    K *prev = *currentPtr;
                    *currentPtr = *next;
                    UnsafeUtility.Free(prev, data->alloc);
                    data->length--;
                    return;
                }
                else
                {
                    currentPtr = next;
                }
            }
        }
Ejemplo n.º 20
0
        protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
        {
            bool *propertyCheckedFlags = stackalloc bool[]
            {
                false,
                false,
                false
            };

            GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher;
            foreach (var i in beforeRenderFrame)
            {
                i.func(i.obj);
            }
            beforeRenderFrame.Clear();
            SceneController.SetState();
#if UNITY_EDITOR
            foreach (var pair in bakeList)
            {
                PipelineCamera pipelineCam = pair.pipelineCamera;
                for (int i = 0; i < pair.worldToCamera.Length; ++i)
                {
                    pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i];
                    pipelineCam.cam.projectionMatrix    = pair.projection[i];
                    Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags);
                    data.buffer.Blit(pipelineCam.targets.renderTargetIdentifier, pair.tempTex);
                    PipelineFunctions.ReleaseRenderTarget(data.buffer, ref pipelineCam.targets);
                    data.buffer.CopyTexture(pair.tempTex, 0, 0, pair.texArray, i, 0);
                    data.ExecuteCommandBuffer();
                    renderContext.Submit();
                }
                pair.worldToCamera.Dispose();
                pair.projection.Dispose();
                renderContext.ExecuteCommandBuffer(pair.buffer);
                pair.buffer.Clear();
                renderContext.Submit();
            }
            bakeList.Clear();
#endif

            if (!PipelineCamera.allCamera.isCreated)
            {
                return;
            }

            foreach (var cam in cameras)
            {
                PipelineCamera pipelineCam;
                UIntPtr        pipelineCamPtr;
                if (!PipelineCamera.allCamera.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr))
                {
#if UNITY_EDITOR
                    renderingEditor = true;
                    if (!PipelineCamera.allCamera.Get(Camera.main.gameObject.GetInstanceID(), out pipelineCamPtr))
                    {
                        continue;
                    }
#else
                    continue;
#endif
                }
                else
                {
                    renderingEditor = false;
                }
                pipelineCam = MUnsafeUtility.GetObject <PipelineCamera>(pipelineCamPtr.ToPointer());
                Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags);
                PipelineFunctions.ReleaseRenderTarget(data.buffer, ref pipelineCam.targets);
                data.ExecuteCommandBuffer();
                renderContext.Submit();
            }
            foreach (var i in afterRenderFrame)
            {
                i.func(i.obj);
            }
            afterRenderFrame.Clear();
            if (bufferAfterFrame.Count > 0)
            {
                foreach (var i in bufferAfterFrame)
                {
                    i(data.buffer);
                }
                data.ExecuteCommandBuffer();
                bufferAfterFrame.Clear();
                renderContext.Submit();
            }
        }
Ejemplo n.º 21
0
        protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
        {
            bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length];

            UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length);
            GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher;
            SceneController.SetState();
#if UNITY_EDITOR
            int tempID = Shader.PropertyToID("_TempRT");
            foreach (var pair in bakeList)
            {
                PipelineCamera pipelineCam = pair.pipelineCamera;
                for (int i = 0; i < pair.worldToCamera.Length; ++i)
                {
                    pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i];
                    pipelineCam.cam.projectionMatrix    = pair.projection[i];
                    pipelineCam.cameraTarget            = tempID;
                    data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear);
                    Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags);
                    data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0);
                    data.buffer.ReleaseTemporaryRT(tempID);
                    data.ExecuteCommandBuffer();
                    renderContext.Submit();
                }
                pair.worldToCamera.Dispose();
                pair.projection.Dispose();
                renderContext.ExecuteCommandBuffer(pair.buffer);
                pair.buffer.Clear();
                renderContext.Submit();
            }
            bakeList.Clear();
#endif

            if (PipelineCamera.allCamera.isCreated)
            {
                foreach (var cam in cameras)
                {
                    PipelineCamera pipelineCam;
                    UIntPtr        pipelineCamPtr;
                    if (!PipelineCamera.allCamera.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr))
                    {
#if UNITY_EDITOR
                        renderingEditor = true;
                        var pos = cam.transform.eulerAngles;
                        pos.z = 0;
                        cam.transform.eulerAngles = pos;
                        if (!PipelineCamera.allCamera.Get(Camera.main.gameObject.GetInstanceID(), out pipelineCamPtr))
                        {
                            continue;
                        }
#else
                        continue;
#endif
                    }
                    else
                    {
                        renderingEditor = false;
                    }

                    pipelineCam = MUnsafeUtility.GetObject <PipelineCamera>(pipelineCamPtr.ToPointer());
                    Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags);
                    data.ExecuteCommandBuffer();
                    renderContext.Submit();
                }
                if (bufferAfterFrame.Count > 0)
                {
                    foreach (var i in bufferAfterFrame)
                    {
                        i(data.buffer);
                    }
                    data.ExecuteCommandBuffer();
                    bufferAfterFrame.Clear();
                    renderContext.Submit();
                }
            }
            else
            {
                if (bufferAfterFrame.Count > 0)
                {
                    foreach (var i in bufferAfterFrame)
                    {
                        i(data.buffer);
                    }
                    Graphics.ExecuteCommandBuffer(data.buffer);
                    bufferAfterFrame.Clear();
                }
            }
        }
Ejemplo n.º 22
0
        protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
        {
            bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length];
            bool  needSubmit           = false;

            UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length);
            GraphicsSettings.useScriptableRenderPipelineBatching = resources.useSRPBatcher;
            SceneController.SetState();
            data.context   = renderContext;
            data.resources = resources;
#if UNITY_EDITOR
            int tempID = Shader.PropertyToID("_TempRT");
            foreach (var pair in bakeList)
            {
                PipelineCamera pipelineCam = pair.pipelineCamera;
                for (int i = 0; i < pair.worldToCamera.Length; ++i)
                {
                    pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i];
                    pipelineCam.cam.projectionMatrix    = pair.projection[i];
                    pipelineCam.cameraTarget            = tempID;
                    data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear);
                    Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags);
                    data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0);
                    data.buffer.ReleaseTemporaryRT(tempID);
                    data.ExecuteCommandBuffer();
                    renderContext.Submit();
                    needSubmit = false;
                }
                pair.worldToCamera.Dispose();
                pair.projection.Dispose();
                renderContext.ExecuteCommandBuffer(pair.buffer);
                pair.buffer.Clear();
                renderContext.Submit();
                needSubmit = false;
            }
            bakeList.Clear();
#endif
            foreach (var cam in preFrameRenderCamera)
            {
                Render(cam, ref renderContext, cam.cam, propertyCheckedFlags);
                data.ExecuteCommandBuffer();
                renderContext.Submit();
                needSubmit = false;
            }
            preFrameRenderCamera.Clear();
            if (CustomDrawRequest.AllEvents.Count > 0 || JobProcessEvent.allEvents.Count > 0)
            {
                foreach (var i in CustomDrawRequest.AllEvents)
                {
                    i.PrepareJob(resources);
                }
                foreach (var i in JobProcessEvent.allEvents)
                {
                    i.PrepareJob();
                }
                JobHandle.ScheduleBatchedJobs();
                foreach (var i in CustomDrawRequest.AllEvents)
                {
                    i.FinishJob();
                }
                foreach (var i in JobProcessEvent.allEvents)
                {
                    i.FinishJob();
                }
            }
            if (useBeforeFrameBuffer)
            {
                renderContext.ExecuteCommandBuffer(m_beforeFrameBuffer);
                m_beforeFrameBuffer.Clear();
                needSubmit           = true;
                useBeforeFrameBuffer = false;
            }
            if (PipelineCamera.allCamera.isCreated)
            {
                foreach (var cam in cameras)
                {
                    PipelineCamera pipelineCam;
                    UIntPtr        pipelineCamPtr;
                    if (!PipelineCamera.allCamera.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr))
                    {
#if UNITY_EDITOR
                        renderingEditor = true;
                        var pos = cam.transform.eulerAngles;
                        pos.z = 0;
                        cam.transform.eulerAngles = pos;
                        if (!PipelineCamera.allCamera.Get(Camera.main.gameObject.GetInstanceID(), out pipelineCamPtr))
                        {
                            continue;
                        }
#else
                        continue;
#endif
                    }
                    else
                    {
                        renderingEditor = false;
                    }
                    pipelineCam = MUnsafeUtility.GetObject <PipelineCamera>(pipelineCamPtr.ToPointer());
                    Render(pipelineCam, ref renderContext, cam, propertyCheckedFlags);
                    data.ExecuteCommandBuffer();
#if UNITY_EDITOR
                    if (renderingEditor)
                    {
                        renderContext.DrawGizmos(cam, GizmoSubset.PostImageEffects);
                    }
#endif
                    renderContext.Submit();
                    needSubmit = false;
                }
            }
            if (useAfterFrameBuffer)
            {
                renderContext.ExecuteCommandBuffer(m_afterFrameBuffer);
                m_afterFrameBuffer.Clear();
                needSubmit          = true;
                useAfterFrameBuffer = false;
            }
            if (needSubmit)
            {
                renderContext.Submit();
            }
        }
Ejemplo n.º 23
0
        protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
        {
            currentFrameCamera.Clear();
            PipelineCamera.InitializeDict();
            foreach (var cam in cameras)
            {
                CameraSetting csg;
                ulong         pipelineCamPtr;
                if (!PipelineCamera.CameraSearchDict.Get(cam.gameObject.GetInstanceID(), out pipelineCamPtr))
                {
                    if (!cam.TryGetComponent(out csg.pipeCam))
                    {
#if UNITY_EDITOR
                        if (cam.cameraType == CameraType.SceneView)
                        {
                            csg.isRenderingEditor = true;
                            var pos = cam.transform.eulerAngles;
                            pos.z = 0;
                            cam.transform.eulerAngles = pos;
                            if (!Camera.main || !(csg.pipeCam = Camera.main.GetComponent <PipelineCamera>()))
                            {
                                continue;
                            }
                        }
                        else if (cam.cameraType == CameraType.Game)
                        {
                            csg.isRenderingEditor = false;
                            csg.pipeCam           = cam.gameObject.AddComponent <PipelineCamera>();
                        }
                        else
                        {
                            continue;
                        }
#else
                        csg.isRenderingEditor = false;
                        csg.pipeCam           = cam.gameObject.AddComponent <PipelineCamera>();
#endif
                    }
                    else
                    {
                        csg.isRenderingEditor = false;
                        csg.pipeCam.AddToDict();
                    }
                }
                else
                {
                    csg.isRenderingEditor = false;
                    csg.pipeCam           = MUnsafeUtility.GetObject <PipelineCamera>((void *)pipelineCamPtr);
                }
                csg.cam         = cam;
                csg.pipeCam.cam = cam;
                csg.pipeCam.BeforeFrameRendering();
                currentFrameCamera.Add(csg);
            }
            bool *propertyCheckedFlags = stackalloc bool[resources.allEvents.Length];
            bool  needSubmit           = false;
            CustomDrawRequest.Initialize();
            UnsafeUtility.MemClear(propertyCheckedFlags, resources.allEvents.Length);
            SceneController.SetState();
            data.context   = renderContext;
            data.resources = resources;
            if (motionVectorMatricesBuffer == null || !motionVectorMatricesBuffer.IsValid())
            {
                motionVectorMatricesBuffer = new ComputeBuffer(MotionVectorDrawer.Capacity, sizeof(float3x4));
            }
            else if (motionVectorMatricesBuffer.count < MotionVectorDrawer.Capacity)
            {
                motionVectorMatricesBuffer.Dispose();
                motionVectorMatricesBuffer = new ComputeBuffer(MotionVectorDrawer.Capacity, sizeof(float3x4));
            }
            MotionVectorDrawer.ExecuteBeforeFrame(motionVectorMatricesBuffer);
            data.buffer.SetGlobalBuffer(ShaderIDs._LastFrameModel, motionVectorMatricesBuffer);

#if UNITY_EDITOR
            int tempID = Shader.PropertyToID("_TempRT");

            foreach (var pair in bakeList)
            {
                PipelineCamera pipelineCam = pair.pipelineCamera;
                for (int i = 0; i < pair.worldToCamera.Length; ++i)
                {
                    pipelineCam.cam.worldToCameraMatrix = pair.worldToCamera[i];
                    pipelineCam.cam.projectionMatrix    = pair.projection[i];
                    pipelineCam.cameraTarget            = tempID;
                    data.buffer.GetTemporaryRT(tempID, pair.texArray.width, pair.texArray.height, pair.texArray.depth, FilterMode.Point, pair.texArray.format, RenderTextureReadWrite.Linear);
                    Render(pipelineCam, ref renderContext, pipelineCam.cam, propertyCheckedFlags);
                    data.buffer.CopyTexture(tempID, 0, 0, pair.texArray, i, 0);
                    data.buffer.ReleaseTemporaryRT(tempID);
                    data.ExecuteCommandBuffer();
                    renderContext.Submit();
                    needSubmit = false;
                }
                pair.worldToCamera.Dispose();
                pair.projection.Dispose();
                renderContext.ExecuteCommandBuffer(pair.buffer);
                pair.buffer.Clear();
                renderContext.Submit();
                needSubmit = false;
            }
            bakeList.Clear();
#endif
            foreach (var cam in preFrameRenderCamera)
            {
                Render(cam, ref renderContext, cam.cam, propertyCheckedFlags);
                data.ExecuteCommandBuffer();
                renderContext.Submit();
                needSubmit = false;
            }
            preFrameRenderCamera.Clear();
            if (CustomDrawRequest.allEvents.Count > 0 || JobProcessEvent.allEvents.Count > 0)
            {
                foreach (var i in CustomDrawRequest.allEvents)
                {
                    i.PrepareJob(resources);
                }
                foreach (var i in JobProcessEvent.allEvents)
                {
                    i.PrepareJob();
                }
                JobHandle.ScheduleBatchedJobs();
                foreach (var i in CustomDrawRequest.allEvents)
                {
                    i.FinishJob();
                }
                foreach (var i in JobProcessEvent.allEvents)
                {
                    i.FinishJob();
                }
            }
            if (Application.isPlaying && resources.clusterResources)
            {
                resources.clusterResources.UpdateData(data.buffer, resources);
            }
            resources.loadingThread.Update();
            if (useBeforeFrameBuffer)
            {
                renderContext.ExecuteCommandBuffer(m_beforeFrameBuffer);
                m_beforeFrameBuffer.Clear();
                needSubmit           = true;
                useBeforeFrameBuffer = false;
            }
            if (iRunnableObjects.isCreated)
            {
                foreach (var i in iRunnableObjects)
                {
                    IPipelineRunnable func = MUnsafeUtility.GetObject <IPipelineRunnable>((void *)i.value);
                    func.PipelineUpdate(ref data);
                }
            }
            if (cameras.Length > 0)
            {
                data.buffer.SetGlobalVector(ShaderIDs._SceneOffset, new float4(sceneOffset, 1));
            }
            foreach (var cam in currentFrameCamera)
            {
                renderingEditor = cam.isRenderingEditor;

                Render(cam.pipeCam, ref renderContext, cam.cam, propertyCheckedFlags);
                data.ExecuteCommandBuffer();
#if UNITY_EDITOR
                if (renderingEditor)
                {
                    renderContext.DrawGizmos(cam.cam, GizmoSubset.PostImageEffects);
                    ScriptableRenderContext.EmitWorldGeometryForSceneView(cam.cam);
                }
#endif
                renderContext.Submit();
                needSubmit = false;
            }

            if (useAfterFrameBuffer)
            {
                renderContext.ExecuteCommandBuffer(m_afterFrameBuffer);
                m_afterFrameBuffer.Clear();
                needSubmit          = true;
                useAfterFrameBuffer = false;
            }
            if (needSubmit)
            {
                renderContext.Submit();
            }
            MotionVectorDrawer.ExecuteAfterFrame();
            sceneOffset = 0;
            foreach (var cam in currentFrameCamera)
            {
                cam.pipeCam.cam = cam.cam;
                cam.pipeCam.AfterFrameRendering();
            }
        }