zoukankan      html  css  js  c++  java
  • hdrp gpu instance MPB不生效问题

    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);
  • 相关阅读:
    日志/异常处理(nnlog+traceback)
    Excel操作
    商品管理系统
    大乐透作业
    随机生成密码作业
    时间相关的模块
    os模块
    sys模块
    Pytho中dict(或对象)与json之间的互相转化
    Python三元表达式和列表生成式
  • 原文地址:https://www.cnblogs.com/nafio/p/14817385.html
Copyright © 2011-2022 走看看