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 Julien-Lynge · Jun 17, 2013 at 05:46 PM · camerashaderorthographic

Shader: determine if camera is orthographic

Does anyone know of a way to determine from within a shader whether the camera currently rendering it is orthographic?

There are a number of camera parameters that can be accessed, but it looks like the ortho status, or other information that could be used to determine it like the field of view, is not among them:

http://docs.unity3d.com/Documentation/Components/SL-BuiltinValues.html

My particular use case is this: I've written code to do billboarding, and it bases the size of the billboard on the camera distance so it always appears as the same pixel size. Obviously, you don't want to do this with ortho cameras, as size doesn't change with distance from the camera.

I could do it with a shader variable, but that doesn't work if I'm rendering with multiple cameras simultaneously. I could do it with shader replacement, but that requires keeping two shaders synced with each other - not ideal.

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 equalsequals · Jun 17, 2013 at 06:02 PM 1
Share

Just a thought, and not a real answer, but maybe you could try doing matrix comparisons between the $$anonymous$$VP and a matrix that would yield orthographic. Having not done this myself, I can't say for certain that it would work but I offer it as a starting point all the same.

avatar image Julien-Lynge · Jun 17, 2013 at 06:06 PM 0
Share

Interesting idea. Couldn't do that with $$anonymous$$VP, as that would vary based on world position, but I suppose you could with the P matrix. Of course, that would vary based on near / far clip planes and ortho size, but hey, it's a start :)

Thanks for the idea!

avatar image equalsequals · Jun 17, 2013 at 07:08 PM 0
Share

Right, having actually tried that I probably would have realized that it should be P and not $$anonymous$$VP. What Jessy is proposing is likely going to be your avenue.

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Jessy · Jun 17, 2013 at 06:15 PM

The values that matter are in UNITY_MATRIX_P[3].zw. UNITY_MATRIX_P[3][3] will give you a zero for perspective and one for ortho, for example.

http://www.songho.ca/opengl/gl_projectionmatrix.html

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 Julien-Lynge · Jun 17, 2013 at 07:04 PM 1
Share

Thank you, Jessy!

I was able to integrate that seamlessly into the shader as a multiplier, and it seems to be working perfectly.

I wish my group would actually give me time to study up on shaders - there's so much to know :) At the very least I'll read through your link after work.

avatar image
0

Answer by Acegikmo · Apr 28, 2020 at 03:29 PM

a slightly more straightforward value,

unity_OrthoParams.w

0 when your camera is perspective

1 when your camera is ortho

also, when orthographic, x = width, y = height (z is unused)

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

17 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

Related Questions

Shader: get size of a pixel for orthographic camera 2 Answers

Glass Stained Bump Disort Particle System Effect Not Seen In Orthographic Camera 1 Answer

Fog/color tint shader for orthographic camera 0 Answers

Setting up a simple depth-based Shader Replacement material? 0 Answers

Animate turning orthographic camera view on and off (like in editor) 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