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);
  • 相关阅读:
    ubuntu 安装 redis desktop manager
    ubuntu 升级内核
    Ubuntu 内核升级,导致无法正常启动
    spring mvc 上传文件,但是接收到文件后发现文件变大,且文件打不开(multipartfile)
    angular5 open modal
    POJ 1426 Find the Multiple(二维DP)
    POJ 3093 Margritas
    POJ 3260 The Fewest Coins
    POJ 1837 Balance(二维DP)
    POJ 1337 A Lazy Worker
  • 原文地址:https://www.cnblogs.com/nafio/p/14817385.html
Copyright © 2011-2022 走看看