码迷,mamicode.com
首页 > 其他好文 > 详细

hdrp gpu instance MPB不生效问题

时间:2021-06-02 12:56:58      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ace   raw   edit   ons   targe   type   ops   sha   function   

Thanks for posting these tips. I was devastated when my project dropped to 3 FPS because material properties don‘t work out of the box. I was able to edit the generated shader to go from 5000 draw calls to ~15. Here are some relevant snippets. I am only changing the color of my game objects in this example

Find all of these blocks of code (there are several copies)

Code (CSharp):
  1. CBUFFER_START(UnityPerMaterial)
  2. float4 _BaseColor;
  3. CBUFFER_END

Replace them with this

Code (CSharp):
  1. CBUFFER_START(UnityPerMaterial)
  2. UNITY_INSTANCING_BUFFER_START(Props)
  3. UNITY_DEFINE_INSTANCED_PROP(float4, _BaseColor)
  4. UNITY_INSTANCING_BUFFER_END(Props)
  5. CBUFFER_END

Then find every instance of _BaseColor in the shader functions (there are several copies)

Code (CSharp):
  1.  SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) {
  2.         SurfaceDescription surface = (SurfaceDescription)0;
  3.         float4 _Property_A850853A_Out_0 = _BaseColor;
  4.         ....

Replace them with UNITY_ACCESS_INSTANCED_PROP(Props, _BaseColor)

Code (CSharp):
  1. SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN) {
  2.         SurfaceDescription surface = (SurfaceDescription)0;
  3.         float4 _Property_A850853A_Out_0 = UNITY_ACCESS_INSTANCED_PROP(Props, _BaseColor);
  4.         ...

And lastly don‘t forget to set the material properties on your game object

Code (CSharp):
  1. int colorPropId = Shader.PropertyToID("_BaseColor");
  2. var matProps = new MaterialPropertyBlock();
  3. matProps.SetColor(colorPropId, color);
  4. renderer.SetPropertyBlock(matProps);

hdrp gpu instance MPB不生效问题

标签:ace   raw   edit   ons   targe   type   ops   sha   function   

原文地址:https://www.cnblogs.com/nafio/p/14817385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!