Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RasmusHaugaard · Jun 01, 2014 at 02:31 PM · orthographicmatrixprojectionperspective

Vertical Perspective / Horizontal Orthographic

Hi there,

I've been trying to come up with a solution to this for quite a while now.. I want my camera to be horizontally orthographic but still have vertical perspective.

I'm able to draw the frustom, but creating a projection matrix for this, made my head spin a little.. Is there such a matrix available somewhere, or would you recommend something different?

Any help is much appreciated!

alt text

imag2529.jpg (29.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Scribe · Jun 02, 2014 at 02:38 PM

Unfortunately I don't think this is physically possible using a projection matrix as you can never separate all the variables out to be able to solve for a matrix. This is because in orthographic projection, x, y and z are all just multiples of themselves, so w can be equal to 1. In perspective projection, x and y are some multiple of -z and so w is set to -z so that on division by it you get all x, y, and z as either functions of themselves or constants.

Fortunately this does seem do-able via shader scripts, this would mean everything you need affected has to have some variation of these shaders attached, which may be a quite large disadvantage. I am not very experienced with shader scripts (in fact this is the first thing I've properly attempt to do with them) but I've managed to get some ~working~ shaders-

A surface shader, set your camera to orthographic and attach a material that uses this shader to the object:

 Shader "Custom/OrthoPerspective2" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _NearClipPlane ("Near Clip", Float) = 0.3
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         
         CGPROGRAM
         #pragma surface surf Lambert vertex:vert addshadow
         
         sampler2D _MainTex;
         uniform float _NearClipPlane;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         void vert (inout appdata_full v) {
             //v.vertex.y += _NearClipPlane*0.1*v.vertex.y/v.vertex.z;
             
             float4 hpos = mul (UNITY_MATRIX_MVP, v.vertex);
             hpos.y *= 0.03/hpos.z;
             hpos = mul(UNITY_MATRIX_IT_MV, hpos);
             v.vertex.y = hpos.y;
             
         }
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }


And a vertex/fragment shader for which you would set your camera as Perspective:

 Shader "Custom/OrthoPerspective" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _NearClipPlane ("Near Clip", Float) = 0.3
     }
     SubShader {
         Pass {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
             
             uniform float _NearClipPlane;
             
             struct vertexInput {
                 float4 vertex : POSITION;
                 float4 texcoord0 : TEXCOORD0;
             };
 
             struct fragmentInput{
                 float4 position : SV_POSITION;
                 float4 texcoord0 : TEXCOORD0;
             };
 
             fragmentInput vert(vertexInput i){
                 fragmentInput o;
                 float4 v = mul (UNITY_MATRIX_MVP, i.vertex);
                 o.position = v;
                 o.position.x *= o.position.z/(_NearClipPlane*30);
                 o.texcoord0 = i.texcoord0;
                 return o;
             }
 
             float4 frag(fragmentInput i) : COLOR {
                 float4 color;
                 if ( fmod(i.texcoord0.x*8.0,2.0) < 1.0 ){
                     if ( fmod(i.texcoord0.y*8.0,2.0) < 1.0 )
                     {
                         color = float4(1.0,1.0,1.0,1.0);
                     } else {
                         color = float4(0.0,0.0,0.0,1.0);
                     }
                 } else {
                     if ( fmod(i.texcoord0.y*8.0,2.0) > 1.0 )
                     {
                         color = float4(1.0,1.0,1.0,1.0);
                     } else {
                         color = float4(0.0,0.0,0.0,1.0);}
                     }
                 return color;
             }        
             ENDCG
         }
     }
 }


I hope this helps somewhat!

Scribe

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you create a camera perspective that doesn't change with viewing angle? 0 Answers

How do projection matrices work in Unity? 1 Answer

Drawing on the same screen with different cameras? 1 Answer

Difference in gameplay image in orthographic & perspective projection 0 Answers

Android perspective skybox 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges