Beispiel #1
0
        private void UpdateBundleSortList(List <SerializedBundleRef> sortedList, PostProcessEvent evt)
        {
            List <PostProcessBundle> effects = (from kvp in m_Bundles
                                                where kvp.Value.attribute.eventType == evt && !kvp.Value.attribute.builtinEffect
                                                select kvp.Value).ToList();

            sortedList.RemoveAll(delegate(SerializedBundleRef x)
            {
                string searchStr = x.assemblyQualifiedName;
                return(!effects.Exists((PostProcessBundle b) => b.settings.GetType().AssemblyQualifiedName == searchStr));
            });
            foreach (PostProcessBundle item2 in effects)
            {
                string typeName2 = item2.settings.GetType().AssemblyQualifiedName;
                if (!sortedList.Exists((SerializedBundleRef b) => b.assemblyQualifiedName == typeName2))
                {
                    SerializedBundleRef serializedBundleRef = new SerializedBundleRef();
                    serializedBundleRef.assemblyQualifiedName = typeName2;
                    SerializedBundleRef item = serializedBundleRef;
                    sortedList.Add(item);
                }
            }
            foreach (SerializedBundleRef sorted in sortedList)
            {
                string            typeName          = sorted.assemblyQualifiedName;
                PostProcessBundle postProcessBundle = sorted.bundle = effects.Find((PostProcessBundle b) => b.settings.GetType().AssemblyQualifiedName == typeName);
            }
        }
Beispiel #2
0
        private int RenderEffect <T>(PostProcessRenderContext context, bool useTempTarget = false) where T : PostProcessEffectSettings
        {
            PostProcessBundle bundle = GetBundle <T>();

            if (!bundle.settings.IsEnabledAndSupported(context))
            {
                return(-1);
            }
            if (m_IsRenderingInSceneView && !bundle.attribute.allowInSceneView)
            {
                return(-1);
            }
            if (!useTempTarget)
            {
                bundle.renderer.Render(context);
                return(-1);
            }
            RenderTargetIdentifier destination = context.destination;
            int num = m_TargetPool.Get();

            context.GetScreenSpaceTemporaryRT(context.command, num, 0, context.sourceFormat);
            context.destination = num;
            bundle.renderer.Render(context);
            context.source      = num;
            context.destination = destination;
            return(num);
        }
Beispiel #3
0
 public void InitBundles()
 {
     if (!haveBundlesBeenInited)
     {
         RuntimeUtilities.CreateIfNull(ref m_BeforeTransparentBundles);
         RuntimeUtilities.CreateIfNull(ref m_BeforeStackBundles);
         RuntimeUtilities.CreateIfNull(ref m_AfterStackBundles);
         m_Bundles = new Dictionary <Type, PostProcessBundle>();
         foreach (Type key in PostProcessManager.instance.settingsTypes.Keys)
         {
             PostProcessEffectSettings settings = (PostProcessEffectSettings)ScriptableObject.CreateInstance(key);
             PostProcessBundle         value    = new PostProcessBundle(settings);
             m_Bundles.Add(key, value);
         }
         UpdateBundleSortList(m_BeforeTransparentBundles, PostProcessEvent.BeforeTransparent);
         UpdateBundleSortList(m_BeforeStackBundles, PostProcessEvent.BeforeStack);
         UpdateBundleSortList(m_AfterStackBundles, PostProcessEvent.AfterStack);
         sortedBundles = new Dictionary <PostProcessEvent, List <SerializedBundleRef> >(default(PostProcessEventComparer))
         {
             {
                 PostProcessEvent.BeforeTransparent,
                 m_BeforeTransparentBundles
             },
             {
                 PostProcessEvent.BeforeStack,
                 m_BeforeStackBundles
             },
             {
                 PostProcessEvent.AfterStack,
                 m_AfterStackBundles
             }
         };
         haveBundlesBeenInited = true;
     }
 }
Beispiel #4
0
        public void InitBundles()
        {
            // Create these lists only once, the serialization system will take over after that
            RuntimeUtilities.CreateIfNull(ref m_BeforeTransparentBundles);
            RuntimeUtilities.CreateIfNull(ref m_BeforeStackBundles);
            RuntimeUtilities.CreateIfNull(ref m_AfterStackBundles);

            // Create a bundle for each effect type
            m_Bundles = new Dictionary <Type, PostProcessBundle>();

            foreach (var type in PostProcessManager.instance.settingsTypes.Keys)
            {
                var settings = (PostProcessEffectSettings)ScriptableObject.CreateInstance(type);
                var bundle   = new PostProcessBundle(settings);
                m_Bundles.Add(type, bundle);
            }

            // Update sorted lists with newly added or removed effects in the assemblies
            UpdateBundleSortList(m_BeforeTransparentBundles, PostProcessEvent.BeforeTransparent);
            UpdateBundleSortList(m_BeforeStackBundles, PostProcessEvent.BeforeStack);
            UpdateBundleSortList(m_AfterStackBundles, PostProcessEvent.AfterStack);

            // Push all sorted lists in a dictionary for easier access
            sortedBundles = new Dictionary <PostProcessEvent, List <SerializedBundleRef> >(new PostProcessEventComparer())
            {
                { PostProcessEvent.BeforeTransparent, m_BeforeTransparentBundles },
                { PostProcessEvent.BeforeStack, m_BeforeStackBundles },
                { PostProcessEvent.AfterStack, m_AfterStackBundles }
            };

            // Done
            haveBundlesBeenInited = true;
        }
Beispiel #5
0
        public void BakeMSVOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier destination, RenderTargetIdentifier?depthMap, bool invert, bool isMSAA = false)
        {
            PostProcessBundle bundle       = GetBundle <AmbientOcclusion>();
            MultiScaleVO      multiScaleVO = bundle.CastRenderer <AmbientOcclusionRenderer>().GetMultiScaleVO();

            multiScaleVO.SetResources(m_Resources);
            multiScaleVO.GenerateAOMap(cmd, camera, destination, depthMap, invert, isMSAA);
        }
Beispiel #6
0
        private void RenderList(List <SerializedBundleRef> list, PostProcessRenderContext context, string marker)
        {
            CommandBuffer command = context.command;

            command.BeginSample(marker);
            m_ActiveEffects.Clear();
            for (int i = 0; i < list.Count; i++)
            {
                PostProcessBundle bundle = list[i].bundle;
                if (bundle.settings.IsEnabledAndSupported(context) && (!context.isSceneView || (context.isSceneView && bundle.attribute.allowInSceneView)))
                {
                    m_ActiveEffects.Add(bundle.renderer);
                }
            }
            int count = m_ActiveEffects.Count;

            if (count == 1)
            {
                m_ActiveEffects[0].Render(context);
            }
            else
            {
                m_Targets.Clear();
                m_Targets.Add(context.source);
                int num  = m_TargetPool.Get();
                int num2 = m_TargetPool.Get();
                for (int j = 0; j < count - 1; j++)
                {
                    m_Targets.Add((j % 2 != 0) ? num2 : num);
                }
                m_Targets.Add(context.destination);
                context.GetScreenSpaceTemporaryRT(command, num, 0, context.sourceFormat);
                if (count > 2)
                {
                    context.GetScreenSpaceTemporaryRT(command, num2, 0, context.sourceFormat);
                }
                for (int k = 0; k < count; k++)
                {
                    context.source      = m_Targets[k];
                    context.destination = m_Targets[k + 1];
                    m_ActiveEffects[k].Render(context);
                }
                command.ReleaseTemporaryRT(num);
                if (count > 2)
                {
                    command.ReleaseTemporaryRT(num2);
                }
            }
            command.EndSample(marker);
        }
Beispiel #7
0
        private void BuildCommandBuffers()
        {
            PostProcessRenderContext currentContext      = m_CurrentContext;
            RenderTextureFormat      renderTextureFormat = (!m_Camera.allowHDR) ? RenderTextureFormat.Default : RuntimeUtilities.defaultHDRRenderTextureFormat;

            if (!RuntimeUtilities.isFloatingPointFormat(renderTextureFormat))
            {
                m_NaNKilled = true;
            }
            currentContext.Reset();
            currentContext.camera       = m_Camera;
            currentContext.sourceFormat = renderTextureFormat;
            m_LegacyCmdBufferBeforeReflections.Clear();
            m_LegacyCmdBufferBeforeLighting.Clear();
            m_LegacyCmdBufferOpaque.Clear();
            m_LegacyCmdBuffer.Clear();
            SetupContext(currentContext);
            currentContext.command = m_LegacyCmdBufferOpaque;
            TextureLerper.instance.BeginFrame(currentContext);
            UpdateSettingsIfNeeded(currentContext);
            PostProcessBundle        bundle                   = GetBundle <AmbientOcclusion>();
            AmbientOcclusion         ambientOcclusion         = bundle.CastSettings <AmbientOcclusion>();
            AmbientOcclusionRenderer ambientOcclusionRenderer = bundle.CastRenderer <AmbientOcclusionRenderer>();
            bool flag  = ambientOcclusion.IsEnabledAndSupported(currentContext);
            bool flag2 = ambientOcclusionRenderer.IsAmbientOnly(currentContext);
            bool flag3 = flag && flag2;
            bool flag4 = flag && !flag2;
            PostProcessBundle         bundle2  = GetBundle <ScreenSpaceReflections>();
            PostProcessEffectSettings settings = bundle2.settings;
            PostProcessEffectRenderer renderer = bundle2.renderer;
            bool flag5 = settings.IsEnabledAndSupported(currentContext);

            if (flag3)
            {
                IAmbientOcclusionMethod ambientOcclusionMethod = ambientOcclusionRenderer.Get();
                currentContext.command = m_LegacyCmdBufferBeforeReflections;
                ambientOcclusionMethod.RenderAmbientOnly(currentContext);
                currentContext.command = m_LegacyCmdBufferBeforeLighting;
                ambientOcclusionMethod.CompositeAmbientOnly(currentContext);
            }
            else if (flag4)
            {
                currentContext.command = m_LegacyCmdBufferOpaque;
                ambientOcclusionRenderer.Get().RenderAfterOpaque(currentContext);
            }
            bool flag6 = fog.IsEnabledAndSupported(currentContext);
            bool flag7 = HasOpaqueOnlyEffects(currentContext);
            int  num   = 0;

            num += (flag5 ? 1 : 0);
            num += (flag6 ? 1 : 0);
            num += (flag7 ? 1 : 0);
            RenderTargetIdentifier renderTargetIdentifier = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);

            if (num > 0)
            {
                CommandBuffer commandBuffer = currentContext.command = m_LegacyCmdBufferOpaque;
                int           nameID        = m_TargetPool.Get();
                currentContext.GetScreenSpaceTemporaryRT(commandBuffer, nameID, 0, renderTextureFormat);
                commandBuffer.BuiltinBlit(renderTargetIdentifier, nameID, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0);
                currentContext.source = nameID;
                int nameID2 = -1;
                if (num > 1)
                {
                    nameID2 = m_TargetPool.Get();
                    currentContext.GetScreenSpaceTemporaryRT(commandBuffer, nameID2, 0, renderTextureFormat);
                    currentContext.destination = nameID2;
                }
                else
                {
                    currentContext.destination = renderTargetIdentifier;
                }
                if (flag5)
                {
                    renderer.Render(currentContext);
                    num--;
                    RenderTargetIdentifier source = currentContext.source;
                    currentContext.source      = currentContext.destination;
                    currentContext.destination = ((num != 1) ? source : renderTargetIdentifier);
                }
                if (flag6)
                {
                    fog.Render(currentContext);
                    num--;
                    RenderTargetIdentifier source2 = currentContext.source;
                    currentContext.source      = currentContext.destination;
                    currentContext.destination = ((num != 1) ? source2 : renderTargetIdentifier);
                }
                if (flag7)
                {
                    RenderOpaqueOnly(currentContext);
                }
                if (num > 1)
                {
                    commandBuffer.ReleaseTemporaryRT(nameID2);
                }
                commandBuffer.ReleaseTemporaryRT(nameID);
            }
            int nameID3 = m_TargetPool.Get();

            currentContext.GetScreenSpaceTemporaryRT(m_LegacyCmdBuffer, nameID3, 0, renderTextureFormat, RenderTextureReadWrite.sRGB);
            m_LegacyCmdBuffer.BuiltinBlit(renderTargetIdentifier, nameID3, RuntimeUtilities.copyStdMaterial, stopNaNPropagation ? 1 : 0);
            if (!m_NaNKilled)
            {
                m_NaNKilled = stopNaNPropagation;
            }
            currentContext.command     = m_LegacyCmdBuffer;
            currentContext.source      = nameID3;
            currentContext.destination = renderTargetIdentifier;
            Render(currentContext);
            m_LegacyCmdBuffer.ReleaseTemporaryRT(nameID3);
        }