Search Unity

UWRP add custom shadow pass for vertex animation

Discussion in 'Shaders' started by Binary42, Aug 17, 2020.

  1. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Hello,

    im looking for the equivalent of the addshadow directive from surface shaders in uwrp, im using the UniversalPipelineTemplateShader and with the default shadow pass the shadow is rendered with the unanimated mesh.
    If that's not available anymore, do i have to do the vertex calculations in the shadow pass again? Or can i transfer the output from LitPassVertex some how to ShadowPassVertex?

    Thanks!
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,551
    addshadow
    simply generated a custom ShadowPass vertex program using the vertex program from your shader. So yeah, you'll have to manually choose to do that now. But you don't have to duplicate your code, just put it in a .hlsl file and reference your vertex animation function from both LitPass and ShadowPass.
     
  3. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Referencing the function is a good idea, but is there no way to avoid the duplicate calculations (or threefold with depth pass)?
     
  4. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,551
    With Forward rendering, the shadowmask has to be rendered first so that your fragment can sample from it. Each mesh is in its own little world being rendered and doesn't know about the meshes around it, so it needs that mask so it can decide how to shadow itself from the shadows that other objects may have cast. It's an unfortunate downside to the forward rendering approach, which is what URP currently is (though they're adding deferred support in down the line).

    With Deferred, the shadowing can just be done using the GBuffer data that the shaders all output to, as the shaders themselves don't calculate their own lighting, it's "deferred" until the end and done in post-effect/screen-space basically with the buffers. This is also why deferred can handle so many dang lights with ease (but can't do proper transparency easily and thus transparencies still get rendered in forward pipeline)

    If this is a particularly expensive vertex calculation you're doing, then you could avoid the duplicate calculations by taking the GPU skinning kind of approach, where you compute the deformed mesh to a buffer and then render the mesh data from that buffer instead of the original mesh data. This will require you having scripts on the objects you want the deformation on that can handle this though, just like SkinnedMeshRenderer does.

    I'd recommend just testing how the performance is on your target device when letting the shader do the vertex calculations each pass, then if the performance impact is noticeable you can look into optimizations like the one above.
     
    Last edited: Aug 19, 2020
    Binary42 likes this.
  5. Binary42

    Binary42

    Joined:
    Aug 15, 2013
    Posts:
    207
    Thanks a lot! Your answer helped me understand what is happening and, indeed, there is as good as no performance impact.