Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 rich_seabirdsim · Jun 15, 2015 at 05:25 AM · multiple camerasfrustrum

Oblique Frustrum on Multiple Cameras

I need to create an oblique frustrum on 3 scene cameras. I'm using Unity's canned SetObliqueness function, which works fine for a single camera. For some reason, when I add additional cameras, the frustrum will only go oblique on the newest camera. If I deactivate a camera, the most recently added camera will return properly oblique, but adding back the deactivated camera removes the obliqueness. I've tried renaming variables and functions and using Camera.current vs. Camera.main but at most, I can only get one camera oblique. I really need to get this functioning properly. Anyone have any ideas?

Comment
Add comment · Show 1
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 rich_seabirdsim · Jun 15, 2015 at 07:14 AM 0
Share

This is a rather huge project, but I can post the Set Obliqueness subroutine:

     public void SetObliqueness2(float horizObl, float vertObl) {
         $$anonymous$$atrix4x4 mat  = Camera.main.projection$$anonymous$$atrix; 
         mat[0, 2] = horizObl;
         mat[1, 2] = vertObl;
         Camera.main.projection$$anonymous$$atrix = mat;
     }

It's called inside Start of the camera's primary script as such: SetObliqueness2(0,1f);

I've also tried to call the function from inside Update.

I have two copies of the primary camera, which I have edited to be side cameras. I've looked at the camera matrix values during runtime, and I know my scripts are assigning the values (I assigned slightly different numbers for each camera) correctly. I do have some water objects, which I seem to recall play with the camera frustrum, so maybe some conflict there I can't find? @supernat, maybe I can answer a specific inquiry about the scripts?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jun 15, 2015 at 09:05 AM

Well, your method only works on the main camera. You have to change the method so it can work on a different camera.

You could create a seperate script which contains this:

 //ObliqueFrustum.cs
 using UnityEngine;
 
 public class ObliqueFrustum : MonoBehaviour
 {
     private Camera cam;
     public Vector2 offset;
     void Start()
     {
         cam = GetComponent<Camera>();
         SetMatrix(cam, offset);
     }
     public void SetObliqueness(float horizObl, float vertObl)
     {
         offset = new Vector2(horizObl, vertObl);
         SetMatrix(cam, offset);
     }
     
     public static void SetMatrix(Camera cam, Vector2 offset)
     {
         Matrix4x4 mat  = cam.projectionMatrix; 
         mat[0, 2] = offset.x;
         mat[1, 2] = offset.y;
         cam.projectionMatrix = mat;
     }
 }

Just attach this script to each camera object and set the offset in the inspector. If you want to change the obliquness later at runtime you can call "SetObliqueness()" on the appropriate instance of your script.

Maybe a bit more flexible would be:

 //ObliqueFrustum.cs
 using UnityEngine;
 
 public class ObliqueFrustum : MonoBehaviour
 {
     public Vector2 offset;
     void Start()
     {
         GetComponent<Camera>().SetObliqueProjection(offset)
     }
 }
 
 public static class CameraFrustumExtensions
 {
     // extension method of the Camera class, needs to be in a static class
     public static void SetObliqueProjection(this Camera cam, Vector2 offset)
     {
         Matrix4x4 mat  = cam.projectionMatrix; 
         mat[0, 2] = offset.x;
         mat[1, 2] = offset.y;
         cam.projectionMatrix = mat;
     }
     public static void SetObliqueProjection(this Camera cam, float horizObl, float vertObl)
     {
         SetObliqueProjection(cam, new Vector2(horizObl, vertObl));
     }
 }

This way you can simply call "SetObliqueProjection" on any camera reference. So you don't need to attach the "ObliqueFrustum" script to the camera as long as you reference the correct camera. For example:

 // some other manager script
 // ...
 public Camera cam1; // assigned in the inspector
 public Camera cam2;
 public Camera cam3;
 
 void Start()
 {
     // using the extension method we defined above.
     cam1.SetObliqueProjection(x1, y1);
     cam2.SetObliqueProjection(x2, y2);
     cam3.SetObliqueProjection(x3, y3);
 }

Comment
Add comment · Show 1 · 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 rich_seabirdsim · Jun 15, 2015 at 04:09 PM 0
Share

@Bunny83 -- THAN$$anonymous$$S! Your ObliqueFrustrum method works great! (It just didn't compile as is -- for anyone else who faces this issue, this script, with a few $$anonymous$$or tweaks, worked for me):

     using UnityEngine;
     using System.Collections;
     public class ObliqueFrustrum : $$anonymous$$onoBehaviour {
         private Camera cam;
         public Vector2 offset;
         void Start()
         {
             cam = GetComponent<Camera>();
             SetObliqueness(offset);
         }
         public void SetObliqueness(Vector2 offset)
         {
             offset = new Vector2(offset.x, offset.y);
             Set$$anonymous$$atrix(cam, offset);
         }
         
         public static void Set$$anonymous$$atrix(Camera cam, Vector2 offset)
         {
             $$anonymous$$atrix4x4 mat  = cam.projection$$anonymous$$atrix; 
             mat[0, 2] = offset.x;
             mat[1, 2] = offset.y;
             cam.projection$$anonymous$$atrix = mat;
         }
     }
     

$$anonymous$$any, many thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Create Camera Frustrum planes for specific layer 0 Answers

Weird behaviour with multiple cameras and image effects 0 Answers

Hide an object from one camera but not another 2 Answers

Sending data from multiple cameras 0 Answers

How to determine if a mesh is on screen. 1 Answer


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