当前位置:网站首页>[unity URP] the code obtains the universalrendererdata of the current URP configuration and dynamically adds the rendererfeature
[unity URP] the code obtains the universalrendererdata of the current URP configuration and dynamically adds the rendererfeature
2022-07-27 06:56:00 【True ghost 123】
Reference resources https://forum.unity.com/threads/how-to-access-scriptablerendererdata-from-script.1012336/
Code to get the current UniversalRendererData
We go through GraphicsSettings.renderPipelineAsset or QualitySettings.renderPipeline, Can be obtained Edit in Graphic or Quality Set in the URP To configure .
But we can't get RendererList,
UniversalRenderPipelineAsset This attribute is not opened .
So we can get this property through reflection .( Got RendererList First of all data)
UniversalRenderPipelineAsset URPAsset = (UniversalRenderPipelineAsset)QualitySettings.renderPipeline;
FieldInfo propertyInfo = URPAsset.GetType().GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.NonPublic);
UniversalRendererData URPData = (UniversalRendererData)(((ScriptableRendererData[])propertyInfo?.GetValue(URPAsset))?[0]);
Dynamic addition RendererFeature Rendering
Code completion AddRendererFeature function ( Available at run time )
Take rendering in the front as an example :
RenderObjects rendererFeatrue = ScriptableObject.CreateInstance<RenderObjects>();
rendererFeatrue.name = "Test";
// Fill in the desired layer
rendererFeatrue.settings.filterSettings.LayerMask = (1 << LayerMask.NameToLayer("yourlayer0") | 1 << LayerMask.NameToLayer("yourlayer1"));
// Set whether the material is transparent
rendererFeatrue.settings.filterSettings.RenderQueueType = RenderQueueType.Transparent;
rendererFeatrue.settings.overrideDepthState = true;
rendererFeatrue.settings.depthCompareFunction = CompareFunction.Disabled;
After creation , Add to UniversalRendererData Of rendererFeatures in
URPData.rendererFeatures.Add(rendererFeatrue);
Finally , Make it effective immediately .
URPData.SetDirty();
it is to be noted that , If in Editor Next play, After closing, in URP In profile , Dynamically added Reature It'll be empty , So we need to OnDestory Clean up in .
Complete code :
private RenderObjects rendererFeatrue;
private UniversalRendererData URPData;
private void Start()
{
AddRenderFeatrue();
}
private void OnDestroy()
{
URPData.rendererFeatures.Remove(rendererFeatrue);
}
private void AddRenderFeatrue()
{
rendererFeatrue = ScriptableObject.CreateInstance<RenderObjects>();
rendererFeatrue.name = "Test";
rendererFeatrue.settings.filterSettings.LayerMask = (1 << LayerMask.NameToLayer("yourlayer0") | 1 << LayerMask.NameToLayer("yourlayer1"));
rendererFeatrue.settings.filterSettings.RenderQueueType = RenderQueueType.Transparent;
rendererFeatrue.settings.overrideDepthState = true;
rendererFeatrue.settings.depthCompareFunction = CompareFunction.Disabled;
UniversalRenderPipelineAsset URPAsset = (UniversalRenderPipelineAsset)QualitySettings.renderPipeline;
FieldInfo propertyInfo = URPAsset.GetType().GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.NonPublic);
URPData = (UniversalRendererData)(((ScriptableRendererData[])propertyInfo?.GetValue(URPAsset))?[0]);
URPData.rendererFeatures.Add(rendererFeatrue);
URPData.SetDirty();
}
边栏推荐
- What if the website server is attacked? Sunflower tips that preventing loopholes is the key
- Problems related to compilation and training of Darknet yolov3 and Yolo fast using CUDA environment of rtx30 Series graphics card on win10 platform
- New features of ES6 (2)
- Install redis under Windows
- Ftx.us launched stock and ETF trading services to make trading more transparent
- C语言怎么学?这篇文章给你完整答案
- Linux Installation and uninstallation of MySQL
- What is the reason why the channel list is empty on the intelligent security video platform easycvr?
- 脱氧核糖核酸DNA改性近红外二区砷化镓GaAs量子点|GaAs-DNA QDs|DNA修饰GaAs量子点
- px4源码编译之 建立自己的程序模块
猜你喜欢

FTX US launched FTX stocks, striding forward to the mainstream financial industry

FTX 基金会资助1500万帮助新冠疫苗临床实验,将影响全球公共卫生

Inventory of the world's six most technologically competent smart contract audit companies in 2022

Alibaba cloud SMS authentication third-party interface (fast use)

Introduction to the official functions of easyrecovery14 data recovery software

What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!

Speech and language processing (3rd ed. draft) Chapter 2 - regular expression, text normalization, editing distance reading notes

关于在Gazebo中给无人机添加相机(摄像头)之后,无人机无法起飞

3D打印品牌的康复骨科支具有何特别之处?

关于ES6的新特性
随机推荐
C语言怎么学?这篇文章给你完整答案
For redis under windows, it can only read but not write
程序、进程、线程、协程以及单线程、多线程基本概念
云原生运行环境搭建
Express framework
GoLand 编写go程序
如何让最小 API 绑定查询字符串中的数组
Do it yourself container
使用密钥方式登录阿里云服务器
2022年全球6家最具技术实力的的智能合约审计公司盘点
px4源码编译之 建立自己的程序模块
Esxi virtual machine starts, and the module "monitorloop" fails to power on
Soul submitted an application for listing in Hong Kong stocks, accelerating the diversified and scene based layout of social gathering places
About the problem that Druid can't connect to the database
How to make the minimum API bind the array in the query string
deepsort源码解读(二)
FTX US推出FTX Stocks,向主流金融行业迈进
Li Hongyi 2020 deep learning and human language processing dlhlp core resolution-p21
如何删除或替换EasyPlayer流媒体播放器的loading样式?
聊聊大火的多模态