当前位置:网站首页>[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();
}
边栏推荐
- 工控用Web组态软件比组态软件更高效
- DataScience:数据生成之在原始数据上添加小量噪声(可自定义噪声)进而实现构造新数据(dataframe格式数据存储案例)
- 3D打印品牌的康复骨科支具有何特别之处?
- Redis operation of Linux Installation
- Li Hongyi 2020 deep learning and human language processing dlhlp conditional generation by RNN and attention-p22
- Alibaba cloud SMS authentication third-party interface (fast use)
- Linux Installation and uninstallation of MySQL
- GoLand writes Go program
- 聊聊大火的多模态
- Esxi virtual machine starts, and the module "monitorloop" fails to power on
猜你喜欢

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

关于卡尔曼滤波的协方差如何影响deepsort的跟踪效果的考虑

Soul持续发力社交渠道赴港上市,“Soul式社交”凭什么火出圈?

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

What is the reason why the channel list is empty on the intelligent security video platform easycvr?

Install redis under Windows

最新!国资委发布国有企业数字化转型新举措

Many of the world's top 500 enterprises gathered at the second digital Expo, and the digital industry curtain is about to open!

EasyCVR平台播放设备录像时,拖动时间轴播放无效是什么原因?

FTX.US推出股票和ETF交易服务,让交易更透明
随机推荐
Event capture and bubbling - what is the difference between them?
Soul持续发力社交渠道赴港上市,“Soul式社交”凭什么火出圈?
Express框架
What if the website server is attacked? Sunflower tips that preventing loopholes is the key
如何删除或替换EasyPlayer流媒体播放器的loading样式?
Redis operation of Linux Installation
Add virtual network card and configure OP route in win10
deepsort源码解读(六)
3D打印品牌的康复骨科支具有何特别之处?
deepsort源码解读(四)
Linux Installation and uninstallation of MySQL
Redis fast learning
FTP service introduction and configuration
gin-vue-admin 使用docker容器中的数据库
向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解清楚再判断向日葵:遇到电脑漏洞别担心,了解
Boostrap
CentOS上使用Docker安装和部署Redis
多模态数据库 | 星环科技多模数据库ArgoDB“一库多用“,构建高性能湖仓集一体平台
FTX.US推出股票和ETF交易服务,让交易更透明
Project training experience 2