URP multi pass PostProcess shader SetVector failed.

I create a multi pass shader for postprocess

SubShader
{
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
        LOD 100
        ZTest Always ZWrite Off Cull Off

Pass A
{
...
}

Pass B
{
...
}

}

then i draw a fullscreen pass five times

for (int i = 0; i < 5; i++)
{
Vector4 params = ...
material.SetVector("paramsName", params);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, material, 0, 0);
}

I use renderdoc to debug it, i found that in drawcall 0(i =0), the params value is the drawcall 4(i=4)'s value.
It seems that unity don’t push the value to the gpu in drawcall 0.
How to fix that? Thanks.

It’s likely because Material.SetVector executes the moment it’s being called. Whilst CommandBuffer commands are queued and executed at a later stage.

You can use cmd.SetGlobalVector instead, that’s sure to work.

1 Like

It works now, Thanks.