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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Ultima VII Perspective Breakdown (3D)

Discussion in 'General Graphics' started by Farage, Dec 2, 2015.

  1. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    43
    Hello! This is my first post.
    Okay, so, im trying to get a certain perspective to work into Unity.
    The idea is to get the perspective of Ultima VII working with a 3D object.
    So far, i've reached half the way through by messing the camera rotation and aspect ratio.
    But heres the thing, the only step missing to make the perspective look perfect, is for the scene to rotate on its flat axis (x and y) by 45º
    Heres what im trying to do, illustrated:

    The idea is to get to the last image, but i can't :|
    What i did to get to the second image is to adjust the aspect ratio and the camera angles, but rotating the scene in the Z axis messes around with the second image, so its not entirely possible.
    I've thought about stacking 2 cameras to get the result, but this doesn't seem to work, so thats why im asking for help...
    So, any help would be appreciated, thanks!
     
    Last edited: Dec 2, 2015
  2. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    43
    So, i managed to do this using render texture:

    But this is a very weird solution, mostly because its gonna be freaking hard to get the resolution just right.
    If anyone got any idea of how to make this simpler, please, feel free to post here
     
  3. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    ...I'm sorry but I actually laughed out loud when seeing this. It seems so ridiculously overcomplicated. As a thanks, here's a way that sort of makes it work the sort of intended way:

    Set your camera rotation to (65,-30,-30) or similar. And then it look like this:



    It's not exactly the thing as in proper 2.5D, but it's quite close. You'll probably need a custom projection matrix or dedicated art to do the final bit.

    Edit: I'm stupid. Took my 7 edits. Final version!
     
    Last edited: Dec 2, 2015
  4. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    43
    Thanks for the effort! But as i said before, the idea is to simulate the perspective from Ultima VII, the top of the cube should create a perfect square, just like in my final picture, or like, this one:

    I managed to get to half that result by searching a little bit into google and finding this discussion:
    http://opengameart.org/forumtopic/reverse-engineering-ultima-vii-isometrics-wip
    If you look into the link, you'll find a person that managed to do it using Blender, and i've managed to follow his instructions up until the part he just says "now flip it all 45º" which comes back to this topic.
    So... yeah. But thanks for the effort anyways!
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Try using a vertex shader to skew the scene rather than rotating the camera.
     
    Farage likes this.
  6. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    43
    Oh, that might actually work, im guessing setting the camera to a top view, and then skewing all the vertices along the Y axis by a 45 degree angle, that makes sense.
    Im a complete noob when it comes to shaders though, im looking into a few tutorials and pages about it and honestly i feel completely lost. I know how to edit the mesh through a c# script though, is there a difference between those two? I know that the c# script will have to loop through all the vertices and change their positions individualy, are the shaders more efficient in this case? And can i apply a single shader to all my meshes on the scene?
     
    theANMATOR2b likes this.
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    http://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/

    When you get further along the bit of code you'll need is something like this.

    float4 worldPos = mul(_Object2World, v.vertex);
    worldPos.xy += worldPos.z;
    o.vertex = mul(UNITY_MATRIX_MVP, mul(_World2Object, worldPos));


    That might make more sense to you once you've gotten through part4 of the above tutorial.

    edit: Btw, what you're trying to do is skew or shear the scene, not rotate it.
     
    theANMATOR2b, Farage and Zuntatos like this.
  8. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    Well, turns out everyone is being silly here.

    Check: http://docs.unity3d.com/Manual/ObliqueFrustum.html

    So just adding a script like this:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestScript : MonoBehaviour {
    5.     public float AngleX = -0.03f;
    6.     public float AngleY = 0.09f;
    7.  
    8.     void Update () {
    9.         Matrix4x4 matrix = Camera.main.projectionMatrix;
    10.         matrix [0, 2] = AngleX;
    11.         matrix [1, 2] = AngleY;
    12.         Camera.main.projectionMatrix = matrix;
    13.     }
    14. }
    15.  
    somewhere already makes it work (Further away from ortho camera = more translated to bottomright).

    With the added benefits that the entire lighting system works with it, and frustrum culling as well.

    The ratio between the 2 angles depends on the aspect ratio used btw.
     
    theANMATOR2b and Farage like this.
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    Except that completely breaks real time shadows, otherwise it's a good solution.
     
    Zuntatos likes this.
  10. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    43
    Yeah, i managed to do it both ways, the simpler way was to just add the camera script, but they both don't seem to work well with shadows. So i guess the idea is to use the script for the distortion and the shader to create shadows (since shadows are pretty much skewed black textures)
    Heres the final result

    And uh, heres how it works with the shader btw
    But theres also the possibility that im F***ing something up on the shader code too... not really sure
     
    Last edited: Dec 3, 2015
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    For the shader version you'll want to add addshadow to your #pragma surf line, assuming you're using a surface shader.
     
    Farage likes this.
  12. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    bgolus and Farage like this.
  13. Farage

    Farage

    Joined:
    Apr 25, 2014
    Posts:
    43
    Thanks to bgolus i got the shader working perfectly, even with realtime shadows.
    If anyones interested, i can post the code here
    So i guess this is it! Problem solved.
     
  14. Detocroix

    Detocroix

    Joined:
    Jul 2, 2010
    Posts:
    75
    Hey! I would love to see how you managed to get it done. I know this is a very old thread, but I can't find a way to send you a private message about it :(
     
  15. MatthiasStuetzer

    MatthiasStuetzer

    Joined:
    Oct 5, 2016
    Posts:
    17
    This is quite an old thread but I'd be very interested in your code!
     
  16. Sposito

    Sposito

    Joined:
    May 4, 2014
    Posts:
    16
    hey got late to the party...I would really appreciate if u can share how u got it
     
  17. robbo007

    robbo007

    Joined:
    Apr 21, 2022
    Posts:
    1
    I second this...