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 SpookyCat · May 14, 2010 at 09:38 AM · camerashadowsperspectiveprojectionmatrix

Off centre projection matrix breaks cascaded shadows

I have an off centre projection matrix in my game but while it works if the offset is on the x axis if there is any y offset then cascaded shadows get offset in the opposite direction, and example can be seen in the picture, can anyone offer a solution to fix this? alt text

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 Joshua 3 · Oct 25, 2010 at 08:02 PM

I have the same problem and I am using the PerspectiveOffCenter method found here http://unity3d.com/support/documentation/ScriptReference/Camera-projectionMatrix.html

Anyone have a solution?

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 BjornVTI · Oct 31, 2012 at 01:19 PM

I found a solution to this problem. You will need to calculate the aspect ratio and field of view before setting the new projection matrix.

Lets use the PerspectiveOffCenter example found here: http://docs.unity3d.com/Documentation/ScriptReference/Camera-projectionMatrix.html

And extend it with code to calculate and set the aspect ratio and field of view:

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 public class OffProjection : MonoBehaviour {
     public float left = -0.2F;
     public float right = 0.2F;
     public float top = 0.2F;
     public float bottom = -0.2F;
     
     void LateUpdate() {
         Camera cam = camera;
         float width = (right - left);
         float height = (top - bottom);
         cam.aspect = width/height;
         float fov = (Mathf.Atan(top/cam.nearClipPlane) - Mathf.Atan(bottom/cam.nearClipPlane)) * 57.2957795f;
         cam.fieldOfView = fov;
 
         Matrix4x4 m = PerspectiveOffCenter(left, right, bottom, top, cam.nearClipPlane, cam.farClipPlane);
         cam.projectionMatrix = m;
     }
     
     static Matrix4x4 PerspectiveOffCenter(float left, float right, float bottom, float top, float near, float far) {
         float x = 2.0F * near / (right - left);
         float y = 2.0F * near / (top - bottom);
         float a = (right + left) / (right - left);
         float b = (top + bottom) / (top - bottom);
         float c = -(far + near) / (far - near);
         float d = -(2.0F * far * near) / (far - near);
         float e = -1.0F;
         Matrix4x4 m = new Matrix4x4();
         m[0, 0] = x;
         m[0, 1] = 0;
         m[0, 2] = a;
         m[0, 3] = 0;
         m[1, 0] = 0;
         m[1, 1] = y;
         m[1, 2] = b;
         m[1, 3] = 0;
         m[2, 0] = 0;
         m[2, 1] = 0;
         m[2, 2] = c;
         m[2, 3] = d;
         m[3, 0] = 0;
         m[3, 1] = 0;
         m[3, 2] = e;
         m[3, 3] = 0;
         return m;
     }
 }
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

1 Person is following this question.

avatar image

Related Questions

Orthographic position to Perspective position 0 Answers

How to do perspective camera zoom? 1 Answer

How to implement a 3/4 perspective camera 1 Answer

Projetion Mapping on Unity 1 Answer

Sphere turns oval at edge of viewport 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