当前位置:网站首页>URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加
URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加
2022-07-05 16:37:00 【euphorias】
使用后处理进行一次GammaToLinner的转换,能达到正确效果
URP 下取消勾选贴图SRGB,
后处理脚本
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class CameraFeature : ScriptableRendererFeature
{
public Material Material; //UniversalRenderPipelineAsset_Renderer 面板,设置材质
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); //传递摄像机图像,和材质,给Pass 处理
}
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;//接受从Feature 面板设置的材质
private RenderTargetIdentifier source;//接受相机图像
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
//if (renderingData.cameraData.camera.name != "UIMainCamera")
//{
// return;
//}
//执行后处理
if (Material == null)
{
return;
}
CommandBuffer cmd = CommandBufferPool.Get();
//source //源图像
var dec = renderingData.cameraData.cameraTargetDescriptor; //目标图像
RenderTargetHandle tempTargetHandle = new RenderTargetHandle();
cmd.GetTemporaryRT(tempTargetHandle.id, dec);
cmd.Blit(source, tempTargetHandle.Identifier(), Material);
//核心命令CommandBuffer
cmd.Blit(tempTargetHandle.Identifier(), source); //相当于 Graphics.Blit
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public void SetValue(RenderTargetIdentifier source, Material material)
{
Material = material; //接受面板材质
this.source = source;
}
}
}
多重后处理问题
因为没有指定UI相机,导致所有相机画面重复被转换,需要指定仅UI相机进行GammaToLinner转换(也可以在所有渲染之后对图像进行一次GammaToLinner转换)
在Execute函数中暴露相机名在面板上进行填写,判断是否是指定相机,不是指定相机,不进行后处理
//判断是否是指定相机
if (renderingData.cameraData.camera.name != cameraName)
{
return;
}
在Redner Feature 面板填入相机名
效果对比
完整参考代码
CameraFeature
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class CameraFeature : ScriptableRendererFeature
{
public Material Material; //UniversalRenderPipelineAsset_Renderer 面板,设置材质
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); //传递摄像机图像,和材质,给Pass 处理
}
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;//接受从Feature 面板设置的材质
private RenderTargetIdentifier source;//接受相机图像
private string cameraName;
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
//判断是否是指定相机
if (renderingData.cameraData.camera.name != cameraName)
{
return;
}
//执行后处理
if (material == null)
{
return;
}
CommandBuffer cmd = CommandBufferPool.Get();
//source //源图像
var dec = renderingData.cameraData.cameraTargetDescriptor; //目标图像
RenderTargetHandle tempTargetHandle = new RenderTargetHandle();
cmd.GetTemporaryRT(tempTargetHandle.id, dec);
cmd.Blit(source, tempTargetHandle.Identifier(), material);
//核心命令CommandBuffer
cmd.Blit(tempTargetHandle.Identifier(), source); //相当于 Graphics.Blit
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public void SetValue(RenderTargetIdentifier source, Material material, string cameraName)
{
this.material = material; //接受面板材质
this.source = source;
this.cameraName = cameraName;
}
}
}
PostGammaToLinner Shader
使用Amplify 连一个,其中_MainTex是必须的
边栏推荐
- Browser rendering principle and rearrangement and redrawing
- [wechat applet] read the life cycle and route jump of the applet
- 张平安:加快云上数字创新,共建产业智慧生态
- Jarvis OJ webshell analysis
- 高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
- Embedded-c Language-1
- 微信公众号网页授权登录实现起来如此简单
- 2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
- How to install MySQL
- 网站页面禁止复制内容 JS代码
猜你喜欢
【性能测试】jmeter+Grafana+influxdb部署实战
ternary operator
Judge whether a string is a full letter sentence
Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found
If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
Judge whether a number is a prime number (prime number)
飞桨EasyDL实操范例:工业零件划痕自动识别
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
Application of threshold homomorphic encryption in privacy Computing: Interpretation
[729. My Schedule i]
随机推荐
Raspberry pie 4B installation pytorch1.11
启牛商学院股票开户安全吗?靠谱吗?
关于new Map( )还有哪些是你不知道的
Detailed explanation of printf() and scanf() functions of C language
Benji Banas membership pass holders' second quarter reward activities update list
Embedded-c Language-4
Cs231n notes (bottom) - applicable to 0 Foundation
【剑指 Offer】62. 圆圈中最后剩下的数字
手机开证券账户安全吗?怎么买股票详细步骤
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
[brush questions] effective Sudoku
[first lecture on robot coordinate system]
【性能测试】全链路压测
Learnopongl notes (II) - Lighting
调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
EasyX second lesson
Embedded UC (UNIX System Advanced Programming) -1
WSL2.0安装
Yarn common commands
【机器人坐标系第一讲】