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 doctorseus · Aug 27, 2013 at 05:30 PM · cameraviewprojectionperspective

Change or Manipulate Camera Perspective View

Hello,

i have a question about the perspective view of the camera. By standard, the camera view on a cube looks like this:

alt text

So you cant take a look on the sides of the cube. They got be hidden by the front side. I wanted to know if there is any possibility to change the camera view of unity to something like this or some other tricks that could result in the same way.

alt text

I want it to look like the back of the cube is stretched in every side so you are able to look what is going on on the other sides while you are still focused on the front side of the cube. Thanks for your help.

camera_oldview.png (9.0 kB)
camera_newview.png (11.8 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Skylar.S · Sep 28, 2013 at 08:14 PM

you could make a shaper like that, but i dont know of any camera mode that does that..

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
avatar image
0

Answer by correia55 · Nov 03, 2015 at 05:23 PM

Unity Version: 5.2.2f1 Personal

First of all, I'm not an expert in shaders.

I've found a way of doing this by using a shader that modified and combined excerpts from other shader scripts I found online, the sources of which are on the first lines of the shader. The result shown here is from a (2, 2, 2) sized cube from unity.

alt text

To apply this to your cube you need to create a file with this shader and used this in your material. The shader used is this:

 // Part of the Shader was created by Alastair Aitchison (url: https://alastaira.wordpress.com)
 // Some parts come from https://en.wikibooks.org/wiki/Cg_Programming/Unity/Lighting_Textured_Surfaces
 // Some parts come from https://en.wikibooks.org/wiki/Cg_Programming/Unity/Transparency
 
 Shader "Custom/PerspectiveView" {
     Properties{
         [Header(Material)]
           _MainTex ("Texture For Diffuse Material Color", 2D) = "white" {}
         _Color ("Color", Color) = (1.0, 1.0, 1.0, 1.0)
           _SpecColor ("Specular Material Color", Color) = (1,1,1,1)
           _Shininess ("Shininess", Float) = 10
     }
     
     SubShader{
         Tags {"LightMode" = "ForwardBase"}
           Tags {"Queue" = "Transparent"} 
     
         Pass{
              Blend SrcAlpha OneMinusSrcAlpha // use alpha blending
                          
             CGPROGRAM
             
             // Pragmas
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc" 
             uniform fixed4 _LightColor0;
             
             // User defined variables
             uniform sampler2D _MainTex; 
             uniform fixed4 _Color;
             uniform fixed4 _SpecColor; 
             uniform half _Shininess;
             
             struct VertexInput{
                 float4 vertex : POSITION;
                 
                 float3 normal : NORMAL;
                 float4 texcoord : TEXCOORD0;
             };
             
             struct VertexOutput{
                 float4 pos : SV_POSITION;
                 
                 float4 tex : TEXCOORD0;
                 fixed3 diffuseColor : TEXCOORD1;
                 fixed3 specularColor : TEXCOORD2;
             };
             
             VertexOutput vert(VertexInput v){
                 VertexOutput o;
                 
                 // Perspective Section
                 //-------------------------------------------------------------------
                 //
                 
                 // Transform the vertex coordinates from model space into world space
                 float4 vv = mul( _Object2World, v.vertex);
      
                 // Now adjust the coordinates to be relative to the camera position
                 vv.xyz += _WorldSpaceCameraPos.xyz;
 
                 if(vv.y > 0)
                     vv.y = vv.z - _WorldSpaceCameraPos.z;
                 else
                     vv.y = _WorldSpaceCameraPos.z - vv.z - 2;
 
                 if(vv.x > 0)
                     vv.x = vv.z - _WorldSpaceCameraPos.z;
                 else
                     vv.x = _WorldSpaceCameraPos.z - vv.z - 2;
 
                 /*if(vv.z > _WorldSpaceCameraPos.z)
                     vv = float4(vv.x - _WorldSpaceCameraPos.x, vv.y - _WorldSpaceCameraPos.y, 0.0f, 0.0f);
                 else
                     vv = float4(0.0f, 0.0f, 0.0f, 0.0f);*/
 
                 // Now apply the offset back to the vertices in model space
                 v.vertex += mul(_World2Object, vv);
 
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 
                 // Light Section
                 //-------------------------------------------------------------------
                 //
  
                 // multiplication with unity_Scale.w is unnecessary 
                 // because we normalize transformed vectors
      
                 float3 normalDirection = normalize(mul(float4(v.normal, 0.0), _World2Object).xyz);
                 float3 viewDirection = normalize(_WorldSpaceCameraPos - mul(_Object2World, v.vertex).xyz);
                 float3 lightDirection;
                 float attenuation;
      
                 if (0.0 == _WorldSpaceLightPos0.w) // directional light?
                 {
                    attenuation = 1.0; // no attenuation
                    lightDirection = normalize(_WorldSpaceLightPos0.xyz);
                 } 
                 else // point or spot light
                 {
                    float3 vertexToLightSource = _WorldSpaceLightPos0.xyz - mul(_Object2World, v.vertex).xyz;
                    float distance = length(vertexToLightSource);
                    attenuation = 1.0 / distance; // linear attenuation 
                    lightDirection = normalize(vertexToLightSource);
                 }
      
                 float3 ambientLighting = UNITY_LIGHTMODEL_AMBIENT.rgb * _Color.rgb;
      
                 float3 diffuseReflection = attenuation * _LightColor0.rgb * _Color.rgb * max(0.0, dot(normalDirection, lightDirection));
      
                 float3 specularReflection;
                 
                 if (dot(normalDirection, lightDirection) < 0.0) 
                    // light source on the wrong side?
                 {
                    specularReflection = float3(0.0, 0.0, 0.0); 
                       // no specular reflection
                 }
                 else // light source on the right side
                 {
                    specularReflection = attenuation * _LightColor0.rgb * _SpecColor.rgb * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), _Shininess);
                 }
      
                 o.diffuseColor = ambientLighting + diffuseReflection;
                 o.specularColor = specularReflection;
                 o.tex = v.texcoord;
                 
                 return o;
             }
             
             fixed4 frag(VertexOutput i) : COLOR {
                 return fixed4(i.specularColor + i.diffuseColor * tex2D(_MainTex, i.tex.xy), _Color.a);
             }
             
             ENDCG
         }
     }
 }


As I said before, this is a combination of multiple shaders I found online and the part that creates the perspective effect in this cube is presented below. As for adjusting it to a cube of a different size or to another model, it's probably doable by changing the shader in that part. There's another restriction to this shader which is the fact that the result depends on the camera position, this was done while the camera was at (-0.5, -0.5, -10) with a rotation of (0, 0, 0), by changing these values you'll get different results.

I take the opportunity to ask for some suggestions on how to improve and generalize this shader for all models, with no restrictions.

 // Perspective Section
                  //-------------------------------------------------------------------
                  //
                  
                  // Transform the vertex coordinates from model space into world space
                  float4 vv = mul( _Object2World, v.vertex);
       
                  // Now adjust the coordinates to be relative to the camera position
                  vv.xyz += _WorldSpaceCameraPos.xyz;
  
                  if(vv.y > 0)
                      vv.y = vv.z - _WorldSpaceCameraPos.z;
                  else
                      vv.y = _WorldSpaceCameraPos.z - vv.z - 2;
  
                  if(vv.x > 0)
                      vv.x = vv.z - _WorldSpaceCameraPos.z;
                  else
                      vv.x = _WorldSpaceCameraPos.z - vv.z - 2;
  
                  /*if(vv.z > _WorldSpaceCameraPos.z)
                      vv = float4(vv.x - _WorldSpaceCameraPos.x, vv.y - _WorldSpaceCameraPos.y, 0.0f, 0.0f);
                  else
                      vv = float4(0.0f, 0.0f, 0.0f, 0.0f);*/
  
                  // Now apply the offset back to the vertices in model space
                  v.vertex += mul(_World2Object, vv);
  
                  o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

xecatwi.png (14.9 kB)
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

17 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

Related Questions

Drawing on the same screen with different cameras? 1 Answer

How do projection matrices work in Unity? 1 Answer

What is the typical setup for switching between third and first person, in terms of model culling? 0 Answers

Viewer position lost in Space. How to get back to scene? 1 Answer

How do I calculate a view matrix using Matrix4x4.LookAt? 2 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