当前位置:网站首页>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是必须的
边栏推荐
- 【729. 我的日程安排表 I】
- How can C TCP set heartbeat packets to be elegant?
- Error in composer installation: no composer lock file present.
- thinkphp模板的使用
- Android privacy sandbox developer preview 3: privacy, security and personalized experience
- 关于new Map( )还有哪些是你不知道的
- 【剑指 Offer】62. 圆圈中最后剩下的数字
- Judge whether a string is a full letter sentence
- 【剑指 Offer】61. 扑克牌中的顺子
- Do sqlserver have any requirements for database performance when doing CDC
猜你喜欢
Embedded UC (UNIX System Advanced Programming) -2
Cs231n notes (bottom) - applicable to 0 Foundation
Browser rendering principle and rearrangement and redrawing
[team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
Machine learning compilation lesson 2: tensor program abstraction
【性能测试】jmeter+Grafana+influxdb部署实战
Learnopongl notes (II) - Lighting
Games101 notes (II)
拷贝方式之DMA
Jarvis OJ shell traffic analysis
随机推荐
飞桨EasyDL实操范例:工业零件划痕自动识别
Embedded -arm (bare board development) -1
【性能测试】jmeter+Grafana+influxdb部署实战
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
深潜Kotlin协程(二十一):Flow 生命周期函数
【testlink】TestLink1.9.18常见问题解决方法
ternary operator
Jarvis OJ 简单网管协议
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
7.Scala类
Deep dive kotlin synergy (XXI): flow life cycle function
C how TCP restricts the access traffic of a single client
Games101 notes (I)
Games101 notes (III)
项目引入jar从私服Nexus 拉去遇到的一个问题
Excuse me, is the redis syntax used in DMS based on the commands of the redis community version of the cloud database
【jmeter】jmeter脚本高级写法:接口自动化脚本内全部为变量,参数(参数可jenkins配置),函数等实现完整业务流测试
[Jianzhi offer] 66 Build product array
Is it safe to open an account for digging wealth stocks? How is it safe to open a stock account?
叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?