Search Unity

Lighting problem with deferred rendering path and custom camera projection matrix

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

  1. redblast

    redblast

    Joined:
    Apr 26, 2017
    Posts:
    1
    Hello,

    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 :

    1.png


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

    3.png

    2.png


    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.


    Thanks


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

    Attached Files:

  2. barbelot

    barbelot

    Joined:
    Jul 18, 2017
    Posts:
    38
    Replying to say I have a very similar problem. I use custom projection matrices to create off-center cameras as in this example : https://en.wikibooks.org/wiki/Cg_Programming/Unity/Projection_for_Virtual_Reality. 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

    barbelot

    Joined:
    Jul 18, 2017
    Posts:
    38
    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.