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 de-Rooij · Nov 18, 2013 at 01:03 PM · cameraskyboxmatrix

Camera matrix shifting is moving my skydome

Dear community,

I'm using a script on my camera that moves the projectionMatrix so my perspective changes with the player moving in front of a big screen. I've simplified the script so only the matrix bit is still there instead of boring you with the details.

The problem is that my world reacts normally to the matrix shift, but my skydome moves along with the camera. This results in a weird effect. I've tried to put a skybox on a sphere and that works fine. I've got all my lighting setup and don't feel like making a new scene if any of you know a fix.

I feel like the problem is in the skydome script, but I don't have much knowledge about the shader scripting, apart form culling and lighting.

 public var cameraPerspectiveAmount : float = 0.3;
 public var range : float;
 public var myCamera : Camera;
 
 
 function Awake () {
 
 }
 
 function Update(){
 
                 
     var xPos : float = Input.GetAxis("Horizontal");
     
     SetVanishingPoint(camera.main, Vector2(xPos * cameraPerspectiveAmount, 0.0));
     transform.localPosition.x = xPos * range;  
    
    }
 
 function SetVanishingPoint (cam : Camera, perspectiveOffset : Vector2) {
     var m = cam.projectionMatrix;
     var w = 2*cam.nearClipPlane/m.m00;
     var h = 2*cam.nearClipPlane/m.m11;
  
     var left = -w/2 - perspectiveOffset.x;
     var right = left+w;
     var bottom = -h/2 - perspectiveOffset.y;
     var top = bottom+h;
  
     cam.projectionMatrix = PerspectiveOffCenter(left, right, bottom, top, cam.nearClipPlane, cam.farClipPlane);
 }
  
 static function PerspectiveOffCenter (
     left : float, right : float,
     bottom : float, top : float,
     near : float, far : float ) : Matrix4x4
 {
     var x =  (2.0 * near)        / (right - left);
     var y =  (2.0 * near)        / (top - bottom);
     var a =  (right + left)        / (right - left);
     var b =  (top + bottom)        / (top - bottom);
     var c = -(far + near)        / (far - near);
     var d = -(2.0 * far * near) / (far - near);
     var e = -1.0;
  
     var m : Matrix4x4;
     m[0,0] =   x;  m[0,1] = 0.0;  m[0,2] = a;   m[0,3] = 0.0;
     m[1,0] = 0.0;  m[1,1] =   y;  m[1,2] = b;   m[1,3] = 0.0;
     m[2,0] = 0.0;  m[2,1] = 0.0;  m[2,2] = c;   m[2,3] =   d;
     m[3,0] = 0.0;  m[3,1] = 0.0;  m[3,2] = e;   m[3,3] = 0.0;
     return m;
 }


Thank you for helping out!

Comment
Add comment · Show 3
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 de-Rooij · Nov 18, 2013 at 12:57 PM 0
Share

It seems other people are looking for the same answer:

http://answers.unity3d.com/questions/54090/changing-cameraprojectionmatrix-doesnt-affect-skyb.html

http://answers.unity3d.com/questions/534838/how-can-i-make-a-skybox-respect-oblique-frustum.html

avatar image DMGregory · Jun 05, 2014 at 05:51 PM 0
Share

I modified the skybox shader to deal with this, and posted the code in one of the answers you linked above:

http://answers.unity3d.com/questions/534838/how-can-i-make-a-skybox-respect-oblique-frustum.html

For my purposes I only needed the parameters you've labelled a and b above, but the basic idea can be extended to include the full matrix.

avatar image de-Rooij · Jul 16, 2014 at 01:46 PM 0
Share

Thank you D$$anonymous$$G,

I've also found that changing the near camera clipping planes to a higher value greatly decreases the shifting effect.

However the modified shader eli$$anonymous$$ates the problem altogether.

Cheers!

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Changing camera.projectionMatrix doesn't affect skyboxes? 0 Answers

How can I make a skybox respect oblique frustum? 1 Answer

How to make camera position relative to a specific target. 1 Answer

SSI Gold Box/Divine Divinity perspective? 1 Answer

Separate camera for skybox. Skybox won't show. 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