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 /
  • Help Room /
avatar image
0
Question by heyx3 · Nov 16, 2017 at 05:14 AM · shadergraphicsdepth-bufferplatform-support

How do I get the exact values of the near and far planes in clip space, both in a shader and in C#?

I'm playing around with a plugin idea that manually does something similar to shadow-maps, and I need to know the values for the near and far Z bounds in clip space -- depending on the graphics API, they could be 0 to 1, -1 to 1, or possibly 1 to 0 (and maybe even 1 to -1?). Unity docs mention the macros UNITY_NEAR_CLIP_VALUE and UNITY_REVERSED_Z, but there are two problems:

  1. It doesn't give a concrete example of actually defining the near/far values in a fully platform-agnostic way.

  2. It only explains how to find these values in a shader, not in a C# script.

If you can answer either of these two issues, I'd appreciate it!

I have an idea for how to get the near/far values in a shader, but there's no way to know if it's platform-agnostic without testing every concievable platform, which is unfeasible:

 #if defined(UNITY_REVERSED_Z)
     const float nearPlane = 1.0,
                 farPlane = UNITY_NEAR_CLIP_VALUE;
 #else
     const float nearPlane = UNITY_NEAR_CLIP_VALUE,
                 farPlane = 1.0;
 #endif



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 Dragate · Nov 16, 2017 at 09:22 AM 0
Share

Are you looking for

  • https://docs.unity3d.com/ScriptReference/Camera-farClipPlane.html

  • https://docs.unity3d.com/ScriptReference/Camera-nearClipPlane.html

?

avatar image insominx Dragate · Nov 16, 2017 at 04:55 PM 0
Share

I believe he wants the values in clip space which can vary depending on the graphics API.

avatar image insominx · Nov 16, 2017 at 04:59 PM 0
Share

There's probably a better way than this but you can probably multiply the projection matrix in C# by the forward vector with z at both near and far and see what you get (don't forget perspective divide by w). Then again, that probably doesn't account for UNITY_REVERSED_Z but I think if you can deter$$anonymous$$e if that's being used, just swap near and far.

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

169 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to reduce gradient banding? 0 Answers

Elements missing on Galaxy S4 (value edition) 1 Answer

9 slice Image and Shader UV Coordinates 1 Answer

How would you go about panning and zooming like Google Maps using SetTextureOffset & SetTextureScale ? 1 Answer

Sprite Occlusion with Stencil Buffer for Surface Shader? 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