public static CustomPassVolume GetActivePassVolume(CustomPassInjectionPoint injectionPoint)
        {
            var volumes = new List <CustomPassVolume>();

            GetActivePassVolumes(injectionPoint, volumes);
            return(volumes.FirstOrDefault());
        }
        public void MakeSureVolumeExistsForInjectionPoint(CustomPassInjectionPoint injPt)
        {
            if (volumes.ContainsKey(injPt))
            {
                return;
            }

            // not found in the dictionary - see if there is one on this object
            CustomPassVolume volume = null;

            foreach (CustomPassVolume v in GetComponents <CustomPassVolume>())
            {
                if (v.injectionPoint == injPt)
                {
                    volume = v;
                    break;
                }
            }

            if (volume == null)
            {
                // not found on this object, create it
                volume = gameObject.AddComponent <CustomPassVolume>();
                volume.injectionPoint = injPt;
                volume.hideFlags      = HideFlags.DontSave;            // don't serialize this pls
                                        #if UNITY_EDITOR
                volume.runInEditMode = true;
                                        #endif

                volume.AddPassOfType(typeof(ShapesRenderPass));                   // this pass branches internally
            }

            volumes[injPt] = volume;
        }
Exemple #3
0
        internal void PushCustomPassTexture(
            RenderGraph renderGraph,
            CustomPassInjectionPoint injectionPoint,
            TextureHandle cameraSource,
            Lazy <RTHandle> customPassSource,
            List <RTHandle> targets
            )
        {
            if (!isValid || m_CustomPassAOVBuffers == null)
            {
                return;
            }

            Assert.IsNotNull(targets);

            int index = -1;

            for (int i = 0; i < m_CustomPassAOVBuffers.Length; ++i)
            {
                if (m_CustomPassAOVBuffers[i].injectionPoint == injectionPoint)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                return;
            }

            using (var builder = renderGraph.AddRenderPass <PushCustomPassTexturePassData>("Push Custom Pass Texture", out var passData))
            {
                if (m_CustomPassAOVBuffers[index].outputType == CustomPassAOVBuffers.OutputType.Camera)
                {
                    passData.source           = builder.ReadTexture(cameraSource);
                    passData.customPassSource = null;
                }
                else
                {
                    passData.customPassSource = customPassSource.Value;
                }
                passData.target = targets[index];

                builder.SetRenderFunc(
                    (PushCustomPassTexturePassData data, RenderGraphContext ctx) =>
                {
                    if (data.customPassSource != null)
                    {
                        HDUtils.BlitCameraTexture(ctx.cmd, data.customPassSource, data.target);
                    }
                    else
                    {
                        HDUtils.BlitCameraTexture(ctx.cmd, data.source, data.target);
                    }
                });
            }
        }
Exemple #4
0
 /// <summary>
 /// Gets the currently active Custom Pass Volume for a given injection point.
 /// </summary>
 /// <param name="injectionPoint">The injection point to get the currently active Custom Pass Volume for.</param>
 /// <returns>Returns the Custom Pass Volume instance associated with the injection point.</returns>
 public static CustomPassVolume GetActivePassVolume(CustomPassInjectionPoint injectionPoint)
 {
     foreach (var volume in m_OverlappingPassVolumes)
     {
         if (volume.injectionPoint == injectionPoint)
         {
             return(volume);
         }
     }
     return(null);
 }
 /// <summary>
 /// Gets the currently active Custom Pass Volume for a given injection point.
 /// </summary>
 /// <param name="injectionPoint">The injection point to get the currently active Custom Pass Volume for.</param>
 /// <param name="volumes">The list of custom pass volumes to popuplate with the active volumes.</param>
 public static void GetActivePassVolumes(CustomPassInjectionPoint injectionPoint, List <CustomPassVolume> volumes)
 {
     volumes.Clear();
     foreach (var volume in m_OverlappingPassVolumes)
     {
         if (volume.injectionPoint == injectionPoint)
         {
             volumes.Add(volume);
         }
     }
 }
Exemple #6
0
    private CustomPassVolume GetVolume(CustomPassInjectionPoint injectionPoint)
    {
        if (volumes.ContainsKey(injectionPoint))
        {
            return(volumes[injectionPoint]);
        }

        var volume = gameObject.AddComponent <CustomPassVolume>();

        volume.injectionPoint = injectionPoint;
        volume.isGlobal       = true;

        volumes.Add(injectionPoint, volume);
        return(volume);
    }
 public void MakeSureVolumeExistsForInjectionPoint(CustomPassInjectionPoint injPt)
 {
     if (volumes.TryGetValue(injPt, out CustomPassVolume volume) == false)
     {
         // not found in the dictionary - see if there is one on this object
         if ((volume = GetComponents <CustomPassVolume>().FirstOrDefault(v => v.injectionPoint == injPt)) == null)
         {
             // not found on this object, create it
             volume = gameObject.AddComponent <CustomPassVolume>();
             volume.injectionPoint = injPt;
             volume.hideFlags      = HideFlags.DontSave;                // don't serialize this pls
             volume.runInEditMode  = true;
             volumes[injPt]        = volume;
             volume.AddPassOfType(typeof(ShapesRenderPass));                       // this pass branches internally
         }
     }
 }
Exemple #8
0
        internal void PushCustomPassTexture(
            CommandBuffer cmd,
            CustomPassInjectionPoint injectionPoint,
            RTHandle cameraSource,
            Lazy <RTHandle> customPassSource,
            List <RTHandle> targets
            )
        {
            if (!isValid || m_CustomPassAOVBuffers == null)
            {
                return;
            }

            Assert.IsNotNull(targets);

            int index = -1;

            for (int i = 0; i < m_CustomPassAOVBuffers.Length; ++i)
            {
                if (m_CustomPassAOVBuffers[i].injectionPoint == injectionPoint)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                return;
            }

            if (m_CustomPassAOVBuffers[index].outputType == CustomPassAOVBuffers.OutputType.Camera)
            {
                HDUtils.BlitCameraTexture(cmd, cameraSource, targets[index]);
            }
            else
            {
                if (customPassSource.IsValueCreated)
                {
                    HDUtils.BlitCameraTexture(cmd, customPassSource.Value, targets[index]);
                }
            }
        }
Exemple #9
0
    public CustomPass AddPass(Type passType, CustomPassInjectionPoint injectionPoint, int priority = 0,
                              CustomPass.TargetBuffer targetColorBuffer = CustomPass.TargetBuffer.Camera,
                              CustomPass.TargetBuffer targetDepthBuffer = CustomPass.TargetBuffer.Camera)
    {
        var volume = GetVolume(injectionPoint);
        var passes = volume.customPasses;

        if (!typeof(CustomPass).IsAssignableFrom(passType))
        {
            throw new Exception($"Can't add pass type {passType} to the list because it does not inherit from {nameof(CustomPass)}.");
        }

        var instance = Activator.CreateInstance(passType) as CustomPass;

        if (instance == null)
        {
            throw new Exception($"Failed instance creation of type {passType}");
        }

        instance.name = passType.Name;
        instance.targetColorBuffer = targetColorBuffer;
        instance.targetDepthBuffer = targetDepthBuffer;
        order.Add(instance, priority);

        for (var i = 0; i < passes.Count; ++i)
        {
            if (order[passes[i]] > priority)
            {
                passes.Insert(i, instance);
                return(instance);
            }
        }

        passes.Add(instance);
        return(instance);
    }
Exemple #10
0
 /// <summary>
 /// Constructor for CustomPassAOVBuffers
 /// </summary>
 /// <param name="injectionPoint"> The injection point of the custom passes that will be exported. </param>
 /// <param name="outputType"> The buffer type to export at the scpecified injection point. </param>
 public CustomPassAOVBuffers(CustomPassInjectionPoint injectionPoint, OutputType outputType)
 {
     this.injectionPoint = injectionPoint;
     this.outputType     = outputType;
 }
Exemple #11
0
 internal DrawCommand Initialize(Camera cam, CustomPassInjectionPoint cameraEvent = CustomPassInjectionPoint.BeforePostProcess)
 {
 public static CustomPassVolume GetActivePassVolume(CustomPassInjectionPoint injectionPoint)
 {
     return(m_OverlappingPassVolumes.FirstOrDefault(v => v.injectionPoint == injectionPoint));
 }
Exemple #13
0
 public static DrawCommand Command(Camera cam, CustomPassInjectionPoint cameraEvent = CustomPassInjectionPoint.BeforePostProcess) => ObjectPool <DrawCommand> .Alloc().Initialize(cam, cameraEvent);
Exemple #14
0
 public static DrawCommand Command(Camera cam, CustomPassInjectionPoint cameraEvent = CustomPassInjectionPoint.BeforePostProcess) => new DrawCommand(cam, cameraEvent);
Exemple #15
0
 public T AddPass <T>(CustomPassInjectionPoint injectionPoint, int priority = 0,
                      CustomPass.TargetBuffer targetColorBuffer             = CustomPass.TargetBuffer.Camera,
                      CustomPass.TargetBuffer targetDepthBuffer             = CustomPass.TargetBuffer.Camera) where T : CustomPass
 {
     return(AddPass(typeof(T), injectionPoint, priority, targetColorBuffer, targetDepthBuffer) as T);
 }