Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 $$anonymous$$ · Apr 27, 2020 at 12:03 AM · cameraresolutioneffectaspect-ratiodistortion

Camera horizontal distortion?

Hello!

A while ago I was looking for how to make the camera stretch (distort) horizontally. Or, an alternative is to make the screen resolution wider horizontally and make the image look that way.

But the "Fisheye" effect doesn't work the way I'm looking for   And the resolution has an "aspect ratio" that does not allow me to make such an effect

Does anyone know how that effect can be done? Thank you!

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
Best Answer

Answer by Namey5 · Apr 27, 2020 at 12:50 AM

Cameras use a projection matrix to map things to the screen for rendering. As part of this, things like field of view, clipping planes and aspect ratio are taken into account - separate from resolution. As such, we can override the camera's projection matrix using a custom aspect ratio without actually modifying the screen's aspect ratio;

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class HorizontalDistortion : MonoBehaviour
 {
     private Camera cam;
 
     //This is in relation to the rendering aspect ratio, clamped to a minimum to stop errors
     [Min(0.01f)]
     public float aspectMultiplier = 1f;
 
     //Before the camera culls the scene
     private void OnPreCull ()
     {
         //Get the camera if we don't already have it
         if (!cam)
             cam = GetComponent<Camera>();
 
         //Override the projection matrix, only adjusting aspect ratio
         cam.projectionMatrix = Matrix4x4.Perspective (cam.fieldOfView, cam.aspect / aspectMultiplier, cam.nearClipPlane, cam.farClipPlane);
     }
 
     private void OnDisable ()
     {
         //Reset the projection matrix when we are done
         if (cam)
             cam.ResetProjectionMatrix ();
     }
 }
Comment
Add comment · Show 2 · 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 $$anonymous$$ · Apr 27, 2020 at 02:17 AM 0
Share

Thanks a lot!!

avatar image Lenardjee · Oct 21, 2021 at 10:10 PM 0
Share

Thanks for posting this answer, but I do have a question about it. Please excuse my ter$$anonymous$$ology, I'm very new to this and I don't know how all this works.

It seems the more the aspect ratio changes from the original, say by making it way 0.3 instead of 1.77 (for fullHD), it will become more and more pixelated in the horizontal direction. This seems pretty logical to me as it stretches the 1:3 image to fit a 16:9 screen and I guess it simply doesn't have the amount of 'information' on the horizontal axis as it normally would. Is there any way to fix that and have the camera actually 'gather' the same amount of information on the horizontal axis as it normally would, regardless the aspect ratio?

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

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

Related Questions

Aspect Ration For 2D Sprites and Canvas 0 Answers

Keep Aspect ratio/Letterbox and maintain pixel perfection 0 Answers

Camera viewport should be square and pixel-perfect, regardless of player aspect ratio. 0 Answers

Phantom camera translation when trying to set screen size 1 Answer

4:3 aspect ratio 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