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

How to shear orthographic camera like this one?

Discussion in 'General Graphics' started by benzsuankularb, Jun 10, 2018.

  1. benzsuankularb

    benzsuankularb

    Joined:
    Apr 10, 2013
    Posts:
    132
    Hi,

    How can I shear the camera image without panning the camera direction?

    From
    original.png
    To this (But without white space)
    sheared.jpg

    Can I use projection matrix?
    Or I need a shader?
    And how :)
     
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You can render to a render texture. Then assign that texture to a quad in the shape you want. and render again with a new camera
     
  3. benzsuankularb

    benzsuankularb

    Joined:
    Apr 10, 2013
    Posts:
    132
    Good idea.
    But any ways to do without new camera. adding new camera increase complexities to my project.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    If you don't want that "white space", what do you expect to be visible in that area instead? I mean, once sheared, the image does not fill the entire screen anymore...
     
    benzsuankularb likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Doesn't need a new camera. This can be done with an image effect.

    Also the above is not a shear. A shear, or skew, is easy to do with a projection matrix. This kind of transform is closer to a perspective matrix, which a projection matrix can obviously also do. What you're looking to do is a trapezoidal transform, sometimes referred to as linear affine quadrilateral interpolation, which you cannot do with a projection matrix.

    Your options are using a custom shader on all objects in the scene to pinch the vertices based on screen position (kind of like curved world shaders), or to use an image effect.

    Note, using a shader to pinching the vertices can cause texturing problems, like this:

    The "Affine" example is what you'll see, especially on larger parts of the geometry. The rightmost "Correct" example is your basic perspective corrected texture projection, which also doesn't appear to be what you want. You seem to want is this:


    This can be solved, but it's complicated to do on arbitrary scene geometry.
    https://stackoverflow.com/questions/12414708/correct-glsl-affine-texture-mapping

    Your best bet is to use an image effect in which case it's much easier to solve.
     
    Last edited: Jun 11, 2018
    benzsuankularb likes this.
  6. benzsuankularb

    benzsuankularb

    Joined:
    Apr 10, 2013
    Posts:
    132
    I want to have the environment outside of the original bound.