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);
  • 相关阅读:
    [Java优化] Java代码细节优化
    [网址] 工具类网址
    [Hadoop] 大数据环境安装博客
    简单说下Netty和RPC吧,大佬绕行
    nginx二级域名配置[CentOS]
    java面试准备-自我介绍
    同步||异步&&阻塞||非阻塞
    关于多线程的知识点-02
    [java进阶]关于多线程的知识点
    [java进阶]关于多线程的知识点
  • 原文地址:https://www.cnblogs.com/nafio/p/14817385.html
Copyright © 2011-2022 走看看