当前位置:网站首页>Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition

Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition

2022-07-05 17:23:00 euphorias


Conduct post-treatment once GammaToLinner Transformation , Can achieve the correct effect

URP Next, uncheck the map SRGB,

file
file

Post processing script

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class CameraFeature : ScriptableRendererFeature
{
    
    public Material Material; //UniversalRenderPipelineAsset_Renderer  panel , Set the material 
    private MyVolumeFeaturePass myPass;

    public override void Create()
    {
    
        myPass = new MyVolumeFeaturePass();
        myPass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
    }


    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
    
        renderer.EnqueuePass(myPass);
        myPass.SetValue(renderer.cameraColorTarget, Material); // Transfer camera images , And materials , to Pass  Handle 
    }

    public class MyVolumeFeaturePass : ScriptableRenderPass
    {
    

        // This method is called before executing the render pass.
        // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
        // When empty this render pass will render to the active camera render target.
        // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
        // The render pipeline will ensure target setup and clearing happens in a performant manner.
        public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
        {
    


        }

        private Material Material;// Accept from Feature  Material of panel settings 
        private RenderTargetIdentifier source;// Accept camera images 

        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
    
            //if (renderingData.cameraData.camera.name != "UIMainCamera")
            //{
    
            // return;
            //}
            // Post execution processing 
            if (Material == null)
            {
    
                return;
            }
            CommandBuffer cmd = CommandBufferPool.Get();
            //source // The source image 
            var dec = renderingData.cameraData.cameraTargetDescriptor; // Target image 
            RenderTargetHandle tempTargetHandle = new RenderTargetHandle();
            cmd.GetTemporaryRT(tempTargetHandle.id, dec);

            cmd.Blit(source, tempTargetHandle.Identifier(), Material);
            // Core command CommandBuffer
            cmd.Blit(tempTargetHandle.Identifier(), source); // amount to  Graphics.Blit

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }

        public void SetValue(RenderTargetIdentifier source, Material material)
        {
    
            Material = material; // Accept panel material 
            this.source = source;
        }
    }
}

Multiple post-processing problems

file

Because it is not specified UI The camera , Cause all camera pictures to be converted repeatedly , Need to specify only UI The camera performs GammaToLinner transformation ( The image can also be rendered once after all GammaToLinner transformation )

stay Execute The camera name exposed in the function is filled in on the panel , Determine whether it is the designated camera , Not a designated camera , No post-treatment

			// Determine whether it is the designated camera 
            if (renderingData.cameraData.camera.name != cameraName)
            {
    
                return;
            }

stay Redner Feature Fill in the camera name on the panel

file

Effect comparison

file

Complete reference code

CameraFeature

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class CameraFeature : ScriptableRendererFeature
{
    
    public Material Material; //UniversalRenderPipelineAsset_Renderer  panel , Set the material 
    private MyVolumeFeaturePass myPass;
    public string CameraName="";
    public override void Create()
    {
    
        myPass = new MyVolumeFeaturePass();
        myPass.renderPassEvent = RenderPassEvent.AfterRenderingTransparents;
    }


    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {
    
        renderer.EnqueuePass(myPass);
        myPass.SetValue(renderer.cameraColorTarget, Material, CameraName); // Transfer camera images , And materials , to Pass  Handle 
    }

    public class MyVolumeFeaturePass : ScriptableRenderPass
    {
    

        // This method is called before executing the render pass.
        // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
        // When empty this render pass will render to the active camera render target.
        // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
        // The render pipeline will ensure target setup and clearing happens in a performant manner.
        public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
        {
    


        }

        private Material material;// Accept from Feature  Material of panel settings 
        private RenderTargetIdentifier source;// Accept camera images 
        private string cameraName;
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
    
            // Determine whether it is the designated camera 
            if (renderingData.cameraData.camera.name != cameraName)
            {
    
                return;
            }
            // Post execution processing 
            if (material == null)
            {
    
                return;
            }
            CommandBuffer cmd = CommandBufferPool.Get();
            //source // The source image 
            var dec = renderingData.cameraData.cameraTargetDescriptor; // Target image 
            RenderTargetHandle tempTargetHandle = new RenderTargetHandle();
            cmd.GetTemporaryRT(tempTargetHandle.id, dec);

            cmd.Blit(source, tempTargetHandle.Identifier(), material);
            // Core command CommandBuffer
            cmd.Blit(tempTargetHandle.Identifier(), source); // amount to  Graphics.Blit

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }

        public void SetValue(RenderTargetIdentifier source, Material material, string cameraName)
        {
    
            this.material = material; // Accept panel material 
            this.source = source;
            this.cameraName = cameraName;
        }
    }
}

PostGammaToLinner Shader

Use Amplify Even one , among _MainTex Is a must
file

原网站

版权声明
本文为[euphorias]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051637289621.html