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);
  • 相关阅读:
    Qt 动态添加控件,并删除指定控件
    Qt 采用遍历方式删除QList中全部元素的方法
    Qt 动态添加checkbox,并添加点击事件
    Qt 动态添加删除控件总结
    Qt 动态添加删除控件的方法
    Qt QScrollArea显示滚动条(添加自定义控件)
    Qt Qt::​Alignment 设置对齐方式
    Qt QListView 简单应用
    MATLAB R2019b超详细安装教程
    OpenCV 伪彩 applyColorMap
  • 原文地址:https://www.cnblogs.com/nafio/p/14817385.html
Copyright © 2011-2022 走看看