Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Motion Blur doesn't work with exclude layers and deferred lighting

Discussion in 'Editor & General Support' started by eskovas, Jul 22, 2013.

  1. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    Hello,

    I've been having this problem for awhile but never asked for help.
    Like the title says, Camera Motion Blur doesn't work with exclude layers and deferred lighting.

    $motionblurProblem.jpg

    I've tried to change everything i could think of and nothing works.

    I also just created a new project, to see if the problem was with my game's project, and it's still the same, but i found out it works with forward rendering but not with deferred lighting.

    Is there a way to make it work with deferred lighting? or is there something wrong with the project?

    Thanks
     
  2. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    Hey Eskovas, I too had this problem. Dont know if this will work good on your end and it adds 5 drawcalls.

    In the CameraMotionBlur.js script go to GetTmpCam function and add this line after tmpCam.camera.CopyFrom (camera);

    Code (csharp):
    1. tmpCam.camera.renderingPath = RenderingPath.Forward;
    The whole function should look like

    Code (csharp):
    1.  
    2.     function GetTmpCam () : Camera {
    3.         if (tmpCam == null) {
    4.             var name : String = "_" + camera.name + "_MotionBlurTmpCam";
    5.             var go : GameObject = GameObject.Find (name);
    6.             if (null == go) // couldn't find, recreate
    7.                 tmpCam = new GameObject (name, typeof (Camera));
    8.             else
    9.                 tmpCam = go;
    10.         }
    11.  
    12.         tmpCam.hideFlags = HideFlags.DontSave;
    13.         tmpCam.transform.position = camera.transform.position;
    14.         tmpCam.transform.rotation = camera.transform.rotation;
    15.         tmpCam.transform.localScale = camera.transform.localScale;
    16.         tmpCam.camera.CopyFrom (camera);
    17.         tmpCam.camera.renderingPath = RenderingPath.Forward;
    18.  
    19.         tmpCam.camera.enabled = false;
    20.         tmpCam.camera.depthTextureMode = DepthTextureMode.None;
    21.         tmpCam.camera.clearFlags = CameraClearFlags.Nothing;
    22.  
    23.         return tmpCam.camera;
    24.     }
    25.  
     
    Last edited: Jul 23, 2013
  3. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    @ Boomsma1995

    Doesn't work, Unity crashes when i do that.
     
  4. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    I taught so, I forgot to say make sure the motion blur is the last image effect on the camera. If you put any effect after it it will crash.
     
  5. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,373
    Thanks, it works now.

    This shouldn't crash Unity and should work without changing the code, so i'll probably send a bug report with the scene i made in a new project to see if they can fix it.
     
  6. RideTheT

    RideTheT

    Joined:
    Jun 11, 2012
    Posts:
    23
    Hey did you send the bug report in the end? I'll do it if not, just ran into it myself, pretty annoying.
     
  7. NikkiH

    NikkiH

    Joined:
    Dec 11, 2013
    Posts:
    1
    This script is completely different in 5.3 but the problem persists. There is a workaround:

    I have copied my main camera, set the culling mask to your character (or whatever else you don't want to blur) and remove the motion-blur image-effect. Make sure to uncheck your character layer in the culling mask for the camera that has the motion-blur image-effect. Now you put the Clear Flags to "Don't Clear" and finally the Depth to be bigger than the depths of your motion-blurred camera so it will stay on top.
     
  8. Zireael07

    Zireael07

    Joined:
    Apr 27, 2016
    Posts:
    47
    Are you sure the depth has to be bigger?
    I have a depth camera on 0, the main camera on 1 and the copy on 2 and it renders.... weird is the only way to put it.