Search Unity

Question Framing transposer does not account for lens shift. How Can I make it happen?

Discussion in 'Cinemachine' started by PowerJake, Apr 10, 2022.

  1. PowerJake

    PowerJake

    Joined:
    Nov 15, 2019
    Posts:
    64
    [unity 2021.2.8f1 and cinemachine 2.8.4]

    I'm working on a top down shooter and I'm trying to use an oblique frustum to keep the visuals interesting without sacrificing too much visual clarity to depth. So I added lens shift to the physical cam on my framing transposer vcam, and it messes things up like so

    Frustum.PNG


    So what I want to do is shift the projection matrix or so something so things are properly framed on screen. Is there any way built in to do this? Or how could I mod it in somewhere? I'm hoping there is a way to handle this as part of cinemachine because I want to use cinemachine to blend between camera perspectives.

    One clue I think I found is that I noticed the game view guides appear as though they are in the same position as the original frustum. If I turn the lens shift down such that the old and new frustums overlap, then I can see the game view guides positioned as though there is no lens shift, pictured below with a lens shift of (0,0.7). Maybe something is wrong with the projections to screen space. Could I have found a bug?

    frustumsoverlap.PNG

    Thanks,

    And as a side note, I had this working in the game in an orthographic camera thanks to the solution at https://forum.unity.com/threads/how...jection-matrix-for-a-45-degree-camera.817647/ which pretty much did it all for me. But I want to use perspective which is why that wasn't sufficient. Reworking this might be the answer instead of the built in physical camera stuff, but I'm struggling to understand how to repurpose it if so.
     
    Last edited: Apr 10, 2022
    Alic likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    hmmmm... looks like CM doesn't support that usecase out of the box.
    It's interesting, though.
    If you'd like to prepare a simple test project (i.e. no art, just cubes etc) that sets up this situation, I can take a stab at finding a solution.
     
    Alic likes this.
  3. PowerJake

    PowerJake

    Joined:
    Nov 15, 2019
    Posts:
    64
    Thanks. Here is a link to a test project.
     
    Alic likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Awesome test project, so clear and concise. I love it when people make that effort.
    That's the good news.
    The bad news is that it would be too deep a change in CM to get it to take lens shift into account for framing. I imagine that such an exaggerated lens shift would negatively impact a whole lot of other code too.

    Do you absolutely need to use lens shift to get the effect you want? Is there some other way? What's wrong with an orthographic camera? If it's to enable blending to perspective cameras, then you can fake an ortho camera by using a telephoto perspective placed very far away, like this:

    upload_2022-4-14_9-21-28.png

    Could that approach work for you?
     
    Alic and PowerJake like this.
  5. PowerJake

    PowerJake

    Joined:
    Nov 15, 2019
    Posts:
    64
    Thanks for taking a look at that.

    You guessed it on the reason I want this. I wanted to blend between the oblique gameplay camera and the not oblique boss intros, and score summary screen perspective cameras. I will be sure to try out the angled false orthographic solution in case it works well enough.

    Unfortunately though, I think the obliqueness of the perspective is too important to the idea I am exploring to give up. The reasoning behind it is to make sure that no visual information about the position of characters or hazards is lost to depth, which means I want the camera looking directly down for best results. The importance of that is amplified by my control scheme that emulates old 8-way arcade joysticks instead of free mouse aiming, which complicates the act of lining up shots. And the oblique part comes from my personal distaste for games where all I can see are the tops of people's heads.

    I appreciate you looking at that and ruling out lens shift through cinemachine for my use case, so I don't have to worry about it anymore. If the angled false orthographic projection ends up being too big of a compromise, then I can focus on finding another way to swap perspectives. Maybe I could just mask the transition with tv static or something.
     
    Alic likes this.