Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Lighting problem with deferred rendering path and custom camera projection matrix

Discussion in 'Editor & General Support' started by redblast, Apr 26, 2017.

  1. redblast


    Apr 26, 2017

    I'm currently looking on how to create a mirror effect.

    I'm using a camera to create a reflection view, so i setup a custom projection matrix like this :

    Code (CSharp):
    1. camera.projectionMatrix *= Matrix4x4.Scale (new Vector3 (-1.0f, 1.0f, 1.0f));
    And also invert culling :

    Code (CSharp):
    1. GL.invertCulling = true;
    I noticed however that when i'm using deferred rendering path and a custom matrix for the camera at the same time, the lighting is not correct.

    I have join a little scene to illustrate the problem and made a screenshot of it :


    Bottom right viewport is too dark, i've also noticed that when i turn off environment reflections other three become dark as well :



    So maybe something has to do with this setting not been taken into account.

    If anyone have an idea on how to fix this, you're welcome, i'm using Unity 5.6.

    I can post here the CSharp script (included in the join package) if you wish.

    That's my first post here so I hope this is the right category to post it.


    PS : sorry for my English, i know it is far from perfect ;)

    Attached Files:

  2. barbelot


    Jul 18, 2017
    Replying to say I have a very similar problem. I use custom projection matrices to create off-center cameras as in this example : While this works very well in forward rendering, lighting is wrong when I switch to deferred rendering. As shown in the previous post, everything seems darker, I also noticed that spotlights disappear.

    If I make the frustum perfectly symmetrical with the custom projection matrix it sometimes work but is very unstable and makes lighting flicker when the camera moves.
  3. barbelot


    Jul 18, 2017
    I found the solution to my problem, I had a wrong scaling on the distance value "d" ([2,3]) as described here. Re-using the example from Unity documentation worked.
    This seems to be what was responsible for wrong lighting in deferred rendering in my case.