Search Unity

Resolved HDRP Wheel Motion Vector.

Discussion in 'High Definition Render Pipeline' started by AydinDeveloper, Oct 12, 2020.

  1. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    Motion blur has always been a problem with fast rotating objects. It looks very bad on car wheels. I know HDRP will allow Custom motion vector in shader graph in the future, but is there no way to fix the motion vector of wheels right now?

    While examining the custom pass volume, I realized that I can choose motion vector in material pass name. I wonder if I can do it using this.

    upload_2020-10-12_17-13-5.png
     
  2. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I've done this on the old style way (there's an example from PPv1 for custom movecs for wheels). That sample just used additional cage mesh with shader that mainly had movec pass on it. You'd want the cage mesh if your wheel meshes have holes but otherwise you could probably go with that custom pass route for movecs.

    You need to mod the shader a bit to function in HDRP, at very least you need to change line 15 to:
    Code (CSharp):
    1. ZTest Less Cull Back ZWrite Off
    You need this so the ZWrite doesn't prevent the underlying mesh from rendering.

    There are few additional issues with this setup which are not HDRP related (but apply to it as well). That shader only spins the wheel on one direction due to a logic error. To fix that you can swap line 60 to:
    Code (CSharp):
    1. c.rg = (c.rg * 2.0 - 1.0) * abs(_MotionAmount); // Using color texture so need to make 0.5 neutral
    Additionally, the shader doesn't scale the motion amount by the wheel size on screen so you have to implement some sort of scaling logic to prevent this from happening if you can zoom in and out to wheels in your gameplay.

    Edit: You also need to change the movec pass queue to make sure you actually render the movec after rest (required for newer HDRP versions, shouldn't hurt to do in the old versions either). You can do it like this:
    Code (CSharp):
    1.     SubShader
    2.     {
    3.         Tags { "Queue" = "Geometry+500" }
    4.         Pass
    5.         {
    6.             Name "Motion Vectors"
     
    Last edited: Oct 19, 2020
    AydinDeveloper likes this.
  3. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    thanks. current problem is that the shader renders before the unity motion vector.
    upload_2020-10-13_13-59-26.png
     
  4. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    It has no effect on motion blur other than the sorting issue.
    upload_2020-10-13_14-27-26.png
    upload_2020-10-13_14-26-56.png
     
  5. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    @AydinDeveloper Oh right, I forgot they changed the queue order a bit in recent HDRP, you now need to change the queue in that movec shader as well.

    Edit: moved the code snippet to my earlier post in case others stumble to this thread.
     
    Last edited: Oct 14, 2020
    AydinDeveloper likes this.
  6. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Hi all. Do you have a working example of custom motion vectors for HDRP to share?
     
  7. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    You mean the instructions I listed doesn't work anymore?

    That being said, this could potentially used for this effect as well: https://github.com/Unity-Technologies/Graphics/pull/4931 (not merged yet)
     
    AydinDeveloper likes this.
  8. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    @rz_0lento I fixed the problem months ago. I forgot to thank you for your help :) When I added stencil buffer to the shader, I managed to run it properly. but HDRP motion blur effect could not provide the quality blur I wanted.

    I found a better solution. Not as an image effect. I'm doing a Blur with a normal object shader. In this way, I get a better quality result than image effect motion blur.


    URP

    image_002_0010.jpg image_003_0010.jpg
     
  9. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Looks nice, this is traditional preblurred image over regular mesh kinda trick or do you sample the scene color for this?
     
    AydinDeveloper likes this.
  10. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    I created it based on the URP motion blur shader. I'm sampling the scene color with this texture. There are a few problems.

    I don't know what color I should apply for the other surface of the wheel. As shown in the screenshot, Scene color does not work in Scene view, with MSAA turned off or with Deferred rendering. This may be related to the Beta version. or the custom function is related to the way I write. I will rewrite with normal shader soon. HDRP and Default RP will be pretty easy to support.

    upload_2021-7-12_17-14-17.png
     
    rz_0lento and Ruchir like this.
  11. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    I tried, but gave up after 30min.

    Instead istarted to try to port this "overhead" kinda "brut force" Motion Blur method to HDRP.
    Half way done but i expect some tranparent sorting issues.
    However some high quality result should be possible with this.

    check the Unity WEBGL
    https://nothke.itch.io/volumetric-mesh-blur?secret=GA3D2cuKm8VJpNMu6PNA2Ei6Zl4

    and the method behind
    http://nothkedev.blogspot.com/2018/10/correct-motion-blur-for-fast-rotating.html

    This guy reworked this method with less code and more manually work (copying) needed.
    But gives an idea what to expect.
     
    Last edited: Jul 15, 2021
    Szociu likes this.
  12. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Here are the two scripts from the video tutorial.
    Add the scripts, a rigid body and a wheel collider to the wheel.
    Works nicely so far.
     

    Attached Files:

  13. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92
    @keeponshading It has HDRP Custom Velocity support. I no longer have any problems.
    image_196_0360.jpg
     

    Attached Files:

  14. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    wow. This looks fantastic.
    Does the TAA works too when the car is driving and
    how you did it? .-)


    I have
    6 different HDRP Lit materials for the rim
    3 different HDRP Lit materials for the tire

    1.JPG

    This should render something like this.
    But at the moment with default settings the TAA and MotionBlur goes crazy several cm around the complete wheel.

    2.JPG
     
    Last edited: Sep 20, 2021
  15. AydinDeveloper

    AydinDeveloper

    Joined:
    Sep 8, 2017
    Posts:
    92

    I set TAA speed reject to 0.2 (HDRP 11+)
    in this way, TAA is not processed on very fast objects.
     
  16. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    Nice. Didn t know that.
    How can i setup the HDRP Lit shader or an HDRP Shadergraph.
    Only enable custom velocity and the motion vectors know then they have to rotate?
     
  17. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    68
    Hi!
    Solution with transparent materials for rims works for me!
    But I have more general problem with hdrp motion blur - objects, far from moving camera are jerking. So, i.e. having car hood camera, driving fast, steer slowly, far objects sometimes partially blurred (i mean partially random on each frame, it looks like permanent noise).
    Are there any solution for it?
    It seems there are lack of some filtering.

    The same noise exists for SSR (HDRP 12). I.e. in Unigine engine there are no noise at all.
     
  18. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Which technique that you use for this one?