Search Unity

Question [SRP Batching] PositionOS cannot be converted to PositionWS

Discussion in 'Shaders' started by wwWwwwW1, Jun 23, 2022.

  1. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    769
    Hi, I was trying to support SRP Batching on my custom URP shader.
    • Move all parameters in inspector to one "UnityPerMaterial" cbuffer.
    • Make sure the shader has a "UnityPerDraw" cbuffer. (include "UnityInput.hlsl")
    I finished it successfully on 2022.2.a17 URP14.0.3. (Everything works fine)

    But when I test it on URP13-12, the mesh (with my shader) will always stay at the origin.

    Then I realized that there must be some thing wrong with the "unity_ObjectToWorld" matrix.
    (but I cannot see that matrix in Frame Debugger, the same to URP Lit shader)
    CBUFFER_UnityPerDraw.jpg

    I include "UnityInput.hlsl" manually but the problem still exists. (It should be included by other URP files)

    So, how can I fix the OS->WS conversion on URP 13 or what happened to SRP batching on URP 14?

    Thx a lot!
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    769
    Seems that I cannot find a fix to the "unity_ObjectToWorld" matrix.

    I can reproduce the problem manually on URP14 by treating positionOS as world space, so I'm sure that matrix is broken.

    Maybe the include order has changed between URP14 and URP13, but I failed to find the key changes.
    CBUFFER_IncludeOrder.jpg

    My current fix is to disable SRP Batching on URP 13 and below:
    CBUFFER_UnityPerMaterial.jpg

    Please let me know if you know what breaks that matrix, thx! :(