Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mrlabcoburg · Feb 22, 2018 at 03:49 PM · renderingdepth-buffer

Depth buffer range is 0.5 -0 instead of 1.0 - 0 as expected

I'm rendering to a depth buffer by using a standard camera and a render texture that has its format set to Depth only. I do this by calling camera.Render(); when clicking a button using a custom editor script. Near and far clipping planes are set to unrelated values (0.3 and 20, see below). Should note that the shader used to evaluate the texture doesn't specify any offset.

The values read from the depth buffer (in another shader that uses the texture) are weird: objects near the far clipping plane show values almost at 0, and values at the near clipping plane show values of 0.5.

When I compute the pixel depth manually (by constructing the cameras MVP matrix, multiplying with the vertex and dividing by w in a pixel shader), I can reproduce the expected values instead (going from 1.0 to 0.0).

The ratio seems to hold for any arbitrary value in the depth texture, too. I.e. when i read a pixel at depth 0.25 in the depth texture, the corresponding depth value from manual computation ends up as 0.5, though with certain values it's not an exact match (the factor will be slightly off from 2.0), which I assume is just due to floating point accuracy though I could be wrong there.

Any ideas what could be causing this, and how i can deal with it? It seems I can just multiply the depth from texture by 2.0, but this seems hacky and won't work on other machines if some underlying platform specific code is the cause of this.

For completeness, screenshots showing camera and render texture settings:

alt text

(spacing) alt text

screen1.png (90.1 kB)
screen2.png (51.7 kB)
Comment
Add comment · Show 1
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 MaxYari · Apr 27, 2021 at 05:47 PM 0
Share

Every time I find a question Im interested in - it has no answer :(

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

79 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

Related Questions

Depth Rendering Issue 0 Answers

Is it possible to create a depth render of scene using a replacement shader? 0 Answers

commandbuffer can't get depth buffer in forward rendering but correct in Deferred .Why? 1 Answer

Modifying shadow depth pass 0 Answers

Multiple cameras, view distances, and the depth buffer 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