7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】RendererFeatureの値をランタイムで変更したい

Last updated at Posted at 2021-03-14

URPの場合は以下のようにRendererFeatureにアクセスできます。

var pipeline = ((UniversalRenderPipelineAsset)GraphicsSettings.renderPipelineAsset);
var propertyInfo = pipeline.GetType().GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.NonPublic);
var scriptableRendererData = ((ScriptableRendererData[])propertyInfo.GetValue(pipeline))[0];
var renderObjects = (RenderObjects)scriptableRendererData.rendererFeatures[index];

renderObjects.settings.depthCompareFunction = CompareFunction.Greater;
scriptableRendererData.SetDirty();

値を変更した場合、ScriptableRendererData.SetDirty() を呼び出すことで変更が反映されます。

RendererFeatureChange_gif.gif

自作RendererFeatureを実装している場合は以下のようにアクセスできます。


var myRendererFeature = scriptableRendererData.rendererFeatures.OfType<MyRendererFeature>().FirstOrDefault();

Unity 2020.1.17f1
Universal RP 8.3.1

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?