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
0
Question by EJSainz · Feb 28, 2017 at 07:46 AM · shadereditordevelopment build

Differences in Depth Buffer inside the editor and outside the editor

Hello!

I'm working on a VR Project (Gappo's Legacy) and so far everything was working pretty well, but recently we discovered that our raymarched explosions fail to work properly on a MSI GE62VR. Even worst: they only fail on a non-developer build (in the editor everything works great).

(On non-laptop computers with 1060 and 1080 everything works fine).

After some tests, we have determined that the error is in the depth check we perform so opaque objects will oclude the raymarched explosions. Basically, in the GE62VR Build the explosión would only be visible when happening really, really close.

I've read a lot about different formats and clip space Z values depending on platform, and I'm evaluating coding my own distance check, but considering that everything works fine in the editor, I believe that locating the difference in both cases will be simpler.

But so far I haven't had any luck finding out what the difference is and so how to force it to happen.

Also, to depth check we are using the LinearEyeDepth() function which, according to the manuals, is already handling the platform differences ok.

 // Using this to get the Scene Depth
 float sceneZ = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(v2fIn.projPos)).r);    
 
 // Using this comparison to stop raymarching
 if (distanceToCameraAtWorldSpace > sceneZ)
 {
     break;
 }

Any idea on what can be causing this different behaviour inside and outside the editor? Thanks!


Edit:

I've run some tests, and have discarded that the Z-Inverse and the OpenGL Z-Range as the origin for the problem. So far, it looks like the error has something to do with unproper Z values when running the Build.

I prepared this shader:

 float sceneZ = Linear01Depth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(v2fIn.projPos)).r));
         sceneZ *= _ProjectionParams.z;
         sceneZ += _ProjectionParams.y;
 
         if (sceneZ < 1)
         {
             return float4(1, 0, 0, 1);
         }
         if (sceneZ < 2)
         {
             return float4(0, 1, 0, 1);
         }
         if (sceneZ < 3)
         {
             return float4(0, 0, 1, 1);
         }
         if (sceneZ < 4)
         {
             return float4(1, 1, 0, 1);
         }
         if (sceneZ < 5)
         {
             return float4(1, 0, 1, 1);
         }
         if (sceneZ < 6)
         {
             return float4(0, 1, 1, 1);
         }
         return float4(1, 1, 1, 1);

And the result in the editor was this: alt text

The result in the build was this: alt text

So, clearly, in the build versión the return values for Linear01Depth() are different, and in fact under 1.

Am I doing something wrong? My next test will be checking for more little values.


Edit 2:

Ok, after some work, I've nailed down the problem. Looks like Linear01Depth() is returning the same value all the time, something between 0,565 and 0,57.

I found this through this shader:

     float sceneZ = Linear01Depth(UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(v2fIn.projPos)).r));
     sceneZ *= _ProjectionParams.z;
     sceneZ += _ProjectionParams.y;

     if (sceneZ < 0.56)
     {
         return float4(1, 0, 0, 1);
     }
     if (sceneZ < 0.565)
     {
         return float4(0, 1, 0, 1);
     }
     if (sceneZ < 0.570)
     {
         return float4(0, 0, 1, 1);
     }
     if (sceneZ < 0.575)
     {
         return float4(1, 1, 0, 1);
     }
     if (sceneZ < 0.580)
     {
         return float4(1, 0, 1, 1);
     }
     if (sceneZ < 0.60)
     {
         return float4(0, 1, 1, 1);
     }
     return float4(1, 1, 1, 1);

Which yields a green square. What can be happening here?

lineareyedepthinbuild.jpg (432.5 kB)
lineareyedepthineditor.jpg (386.4 kB)
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
0
Best Answer

Answer by EJSainz · Feb 28, 2017 at 03:32 PM

Ooooook, looks like the default graphics setting (Fastest) won't generate a proper Depth Texture in the GE62VR, but it will on our other non-laptop computers.

Solved.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is it possible to change the shader of collision bodies in editor? 1 Answer

Wheres the snap to pixel option in the shader/material editor? 1 Answer

Shader not refreshing after changes 0 Answers

Find all materials using a specific shader 1 Answer

Gfx.waitForPresent causing massive lag spikes in editor 8 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