Search Unity

Orthographic always better for 2D?

Discussion in 'iOS and tvOS' started by Jared M, Jul 15, 2009.

  1. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    Hey all-

    currently working on a 2D project and using a normal style camera, and so far everything is working fine. However I would prefer to set things up so that there was a 1:1 mapping of the images. I have seen the references on how to do that with an orthographic camera. I also understand all perspective is removed from this style, so normal style parallax which would easily work in a standard camera is removed. I figure I could fake it by moving background and foreground layers according to camera position, however is this worth it? Does the 1:1 mapping look significantly better?

    If anyone with experience in the matter could offer some pros and cons, or advice, before I go and change my whole project it would be greatly appreciated. Thanks!
     
  2. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    Anybody?
     
  3. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    I have a very early prototype where I use a non-orthographic camera to achieve parallax scrolling. To get my sprites (near) pixel-perfect, I first put a cube at the position where I would want a sprite, press play, take a screenshot, and then make a texture of the exact same size as the cube is in the screenshot. If you then apply the texture to the cube (or a plane, or a spritemanager sprite, I hadn't gotten that far yet, it will almost be pixel-perfect. I say almost, since sometimes I lost a few pixels depending on the camera position, but it was pretty good.

    But using an ortho-camera and moving the layers will work too, off course. I don't think there would be much if any difference in performance, but I'm no expert.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    if orthographic is better highly depends on the game.
    there are cases where it clearly is as you can position all objects independent on the depth the same way (important for multiple scrolling parallax layers and alike) but there are also cases (for example in 2.5d ie isometric) where both is an option
     
  5. buffonomics

    buffonomics

    Joined:
    Jun 10, 2009
    Posts:
    59
    Really no difference most of the time.
     
  6. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    I prefer perspective cameras, but I'm also scaling/rotating/animating my 2d elements like crazy. If I were trying to make something pixel perfect I would probably go orthographic, but I'm fine with my assets getting a little filtering, the effect is invisible with my art style.
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    perhaps its my stupid day but don't see how rotating etc implies any camera type, as perspective camera impacts the rendering in the depth, not transformation applied to objects at a specific depth or image animation
     
  8. BigRedSwitch

    BigRedSwitch

    Joined:
    Feb 11, 2009
    Posts:
    724
    Personally, I'm pretty sure I'll always use 3D cameras for 2D games. The reason being that the miniscule amount of "glittering" that you would see on sprites in a 3D world is negligible compared to the extra game power this offers you - automatic parallax, possiblilty of 3D scene objects or backgrounds and a bit more freedom when it comes to level design (multiple distance depths to the 2D world as opposed to a single plane. Obviously you can get around this, but using a 3D camera, there's less of a need to.

    Also, there are other ways to make sure you retain visual integrity when you're doing games with 2D characters in 3D:

    * Make sure the sprites are billboarded (always facing the camera). That way, you'll get no distortion of the images.

    * Calculate the view distance from the camera so that you get a 1:1 pixel ratio with the original texture. I can't remember the way to do this exactly, but dreamora put up a very succinct and effective equation for this in another thread.

    Based on that, unless you're actually trying to do something which looks identical to an old 2D game, there's no reason not to use a 3D camera, IMHO. :)
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    don't get the automatic parallax part.
    flat is flat and UV transform is uv transform. both are not the slightest bit related to orthographic or perspective cam

    as you see in the orthographic cam settings thread, its automatic with ortho cams too and the script is as dead simple as it can be and uses the sprite manager


    perhaps I'm wrong but it seems like there is a serious missunderstanding around what ortho cams do and what perspective cams do.

    basically perspective cams project the whole world onto a single point (cam) while ortho cams project it parallel on a plane. this means that the only things that are actually affected by it are things with different z coordinate (relative to cam) and things that are not in planes perpendicular to the cam (-> billboard) and naturally 3d objects with real depth

    if you have everything in a single plane + billboard you are really just wasting performance with perspective transformations of each single object.
     
  10. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    Hi Dreamora-

    Can you expound a bit on wasting performance with perspective transformations? I am currently shooting for three layers of parallax here, and while it does come "automatically" when using a perpsective camera with everything aligned in the XY plane with different Z depths, I just don't like that for whatever reason.

    When I switch to an orthographic camera, I do lose the innate parallax of the perspective camera. Everything just stays where it was placed and that's it, regardless of depth. What I read above seems to insinuate that it should still be automatic? I haven't done it yet but it should be pretty easy to script slightly altering the position of the layers relative to the main layer, however then I know I'm wasting cycles on code that positions objects. I'm the kind of person that likes to make things as small and tight as possible and will obsess over minute details for better or worse. I am just getting to grips with Unity but it seems pretty good so far.

    So do you actually gain performance by using an ortho camera over the perspective version? It seems like having everything "flat" with an ortho camera, and then moving around the layers would be more elegant than trying to place things with depth and line them up to the proper size and distance so they look right. But I just want to start it off right and use the approach that will be the most efficient in the end and give me the most FPS, not which will be the easiest necessarily.

    Thanks for any advice you can offer.
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    An orthographic camera does not require to do perspective transformation to "skew" models in shape (or math wise, its an identity matrix), while a perspective camera needs to do so. that means that you basically add another 4x4 * 4x4 matrix multiplication per transform to get nothing from it.
    but the lose on that end is actually pretty low and shouldn't make a feelable difference unless you have many objects or polys


    perhaps we don't think of the same thing as parallax.
    parallax is movement of the background from one side to the other or just in a direction.
    Don't see how you would get that from perspective cameras without having UV animation. I've provided code using the sprite manager that offers exactly that and that in a pixel perfect way, allowing you to define the scrolling on a pixel per second base.

    Or are you talking just of the fact that you can have multiple layers one behind the other, if so then thats possible with orthographic cams just as well, with the difference that the layers remain pixel perfect.


    If not done much performance comparisions as I prefer / require the pixel perfect positioning of the objects instead of blind guessing.
     
  12. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Posts:
    1,224
    Not to pick nits, but this is not parallax... it is simply scrolling. Parallax scrolling, by definition, requires multiple background layers moving at different speeds. Hence, the parallax effect.

    And if there is an easy way to do parallax with the orthographic camera, I'd love to know what it is!
     
  13. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    I'll work on a solution and post it if I make one.
     
  14. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    My point was that the only benefit of an orthographic camera is to be 100% positive that your graphical elements are not being scaled or otherwise filtered in any way by perspective. Any kind of scale (either through transforms, or depth) or rotation will cause your images to no longer be pixel perfect, and recieve a bit of filtering, and since I do rotate/scale my 2d elements constantly my textures are always recieving some amount of filtering. (which is fine by me).

    If you want to avoid EVER having your art get filtered at all, you'd want an ortho camera so that you can have things on different depth layers without having the depth mess with their scale as well. I suppose a perspective camera requires more computation too, but the effects are rather miniscule. I prefer getting that parallax scrolling effect "for free" rather than faking it through code.
     
  15. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Thats exactly what I described.
    Parallax is an effect that bases on different speeds for things in different "distances", not on a perspective camera.
    Actually, back in the days parallax was used, ie 16bit console age and earlier, there was no perspective camera or 3D at all, it was all pure 2D, or as you would call it today "orthographic camera"


    I recommend to search the orthographic setup thread. You will find a Sprite Manager script in there that allows you to define something as a scrolling background with its own speed (in x and y direction) in pixel per second.
    Nothing prevents you from having multiple such layers at different depths, I for example have 5 of them.
     
  16. tonyd

    tonyd

    Joined:
    Jun 2, 2009
    Posts:
    1,224
    Yeah, I know how to do parallax the old fashioned way. It's just not as easy as using the perspective camera and having it work automatically! :wink:
     
  17. Jared M

    Jared M

    Joined:
    Apr 22, 2009
    Posts:
    59
    Well this thread has answered my question. I am going to try orthographic for my 2D game. I would much rather have exact control over each layer in terms of the scrolling rather than try and fudge and mess with scaling, depth etc. Thanks all.
     
  18. BigRedSwitch

    BigRedSwitch

    Joined:
    Feb 11, 2009
    Posts:
    724
    Think you might have got the wrong end of the stick, Dreamora.

    By Automatic Parallax, I simply meant that if you have a 3D camera (not ortho) looking at a 3D landscape, but are treating game objects (such as player character and NPC) as 2D objects (they're billboarded sprites, and all have the same Z-Depth), then you WILL see a parallax effect in the background due to the increasing distance away from the camera that the 3D background has.

    You're correct in stating that an Orthographic Camera projects in parallel lines, so has no perspective forshortening. This means that in order to create parallax, you need to actually move background layers at different speeds, otherwise the motion of the camera will make it look like all layers are superimposed over each other, even though they could be miles apart on the Z-Axis.

    In short, Orthographic cameras turn the Z-Axis into a "Zoom-In" on an XY plane, so parallax has to be handled manually.

    SB
     
  19. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Ah you were talking about real 3D backdrops 8)

    Was the whole time under the impression that we talk about 2D and 2D only, so the dynamic things beeing 2D and the background layers beeing 2D.
    In that case the decision on cam would be unimportant.

    With real 3D its naturally a whole different story :)
     
  20. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    Dreamore, even for 2D, a non-ortho cam can be handy because it will have automatic parallax. If you put one (flat) layer at 100 units from the camera, and the other one at 200, they will obviously move at different speeds when you move the camera. Easy.
     
  21. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Yes
    But I lose the control over the layers movement speed which makes it impossible to have "boosters" / run.
    With ortographic and my solution I have clearly per layer defined pixel / second movements which I can finetune to give me exactly what I want and that with a click and entering the value.
    Not with half an hour of tinkering and moving around.

    Additionally you don't save anything with your attempt as longer levels will require uv animations in your environment too, at least unless you replicate the same texture again and again next to each other.

    I would never come up with the idea to use 3d perspective for such flatplane parallax attempts as the pixel perfect control is just not present and in a 2D game, it is at least to me just too important to have it.
    But thats my personal opinion
     
  22. MonkeyTrax

    MonkeyTrax

    Joined:
    Mar 31, 2009
    Posts:
    34
    Can't find an "orthographic setup" thread...Can you post a link

    Thanks
     
  23. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
  24. bernardfrancois

    bernardfrancois

    Joined:
    Oct 29, 2009
    Posts:
    373
    One way you can do parallax with the orthographic camera is by using multiple cameras and move them at different speeds (for example, the camera for the foreground would be controlled by the game, and the other cameras take its position, but multiply it by a value between 0.0f and 1.0f).

    For this to work, you'll have to assign your objects to different layers and only render specific layers with each camera.
     
  25. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    While not being trivial to set-up and polish, it is amazingly intuitive and you can get some very good results with some pen-and-paper planning beforehand.

    One main camera for the player's layer, several secondary cameras (one per parallax layer and each with a reference to the main camera), and the main camera moving according to the motion of the main player. I wanted to replicate the classic beat'em-up scrolling style in which you only scroll the camera when your character starts pushing against an invisible bounding box, but can freely walk inside it and then reach the edges of the screen if the camera cannot go farther in that direction.
     
  26. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    I had orthographic camera, but now i want to try perspective, because i don't want to add blur effects for each layer separately, but make one camera and use "depth of field" on it. and also static batching would give some performance.
     
  27. abuki

    abuki

    Joined:
    Nov 14, 2013
    Posts:
    40