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
1
Question by simsimsim · Sep 11, 2013 at 02:35 PM · cameraskyboxmatrixprojection

How can I make a skybox respect oblique frustum?

I'm using this script from the Manual to set my vanishing point away from the center. http://docs.unity3d.com/Documentation/Manual/ObliqueFrustum.html It work's great, except that the skybox dosn't respect the change in the projection matrix. Can this be fixed in the skybox shader? How?

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

Answer by DMGregory · Jun 05, 2014 at 05:45 PM

I know this question is from a while ago, but I just encountered this problem recently and found a solution today.

From what I can tell, Unity passes a different projection matrix when rendering skyboxes, one that omits the obliqueness parameters.

I made a copy of the built-in skybox cubed shader and applied the obliqueness manually:

 Shader "Custom/Skybox Oblique" {
 Properties {
     _Tint ("Tint Color", Color) = (.5, .5, .5, .5)
     _Tex ("Cubemap", Cube) = "white" {}
     _Obliqueness ("Obliqueness", Vector) = (0, 0, 0, 0)
 }
 
 SubShader {
     Tags { "Queue"="Background" "RenderType"="Background" }
     Cull Off ZWrite Off Fog { Mode Off }
 
     Pass {
         
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
 
         #include "UnityCG.cginc"
 
         samplerCUBE _Tex;
         fixed4 _Tint;
         float4 _Obliqueness;
         
         struct appdata_t {
             float4 vertex : POSITION;
             float3 texcoord : TEXCOORD0;
         };
 
         struct v2f {
             float4 vertex : POSITION;
             float3 texcoord : TEXCOORD0;
         };
 
         v2f vert (appdata_t v)
         {
             v2f o;
             o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);            
             o.vertex.xy += _Obliqueness.xy * o.vertex.w;
             o.texcoord = v.texcoord;
             return o;
         }
 
         fixed4 frag (v2f i) : COLOR
         {
             fixed4 tex = texCUBE (_Tex, i.texcoord);
             fixed4 col;
             col.rgb = tex.rgb + _Tint.rgb - unity_ColorSpaceGrey;
             col.a = tex.a * _Tint.a;
             return col;
         }
         ENDCG 
     }
 }     
 
 
 Fallback Off
 
 }

Your code that sets the obliqueness on the camera projection matrix should then also provide the values to the RenderSettings.skybox material using SetVector (remember to cache a local copy of the material so you don't inadvertently modify assets on-disc), and both the skybox and camera should then stay in sync.

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

16 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

Related Questions

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

changing camera view 3 Answers

how to change progection matrix for some objects 0 Answers

How to make an Off-axis / Off-center camera ? 2 Answers

Reproduce WorldToViewportPoint function 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