Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

This weird camera glitch?

Discussion in 'General Discussion' started by Yebbes, Oct 1, 2020.

  1. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    When I use one of the VCAMs I get this weird jittering camera, it seems that the Z-depth is not functioning and as far as I know I did not change anything. Any ideas what this could be? See video attached.

    (Gameplay works great, when you zoom out using the zoom button (which enables another vcam which blends) I get this weird stuff... (check also the 3D objects (treasure chests) which glitch!)
     

    Attached Files:

  2. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    How close is everything? Looks like z fighting to me. Separate everything more.

    It looks like you are switching from perspective to orthogonal, is that the case?
     
  3. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    Well, i played with the Field of View, but even if I put it on the same as the "gameplay" camera the problem persists.
    Seperation does not seem to be the case, since also objects seem to have this issie. I see my main character glitch and see through his skull his eyeballs and tongue. Also the treasure chests show their gold through the chests.

    I have no clue! In the Unity (play) Editor the problem does not exists. On Android there is...
     
  4. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    Wheres the z buffer come from? My guess is in the editor, it’s using a Unity special buffer and on the android it’s using the native OpenGL buffer. Is your shader trying time write to the buffer? If I understand it correctly, your not supposed to write to a native buffer, your supposed to let GL do it’s own thing. my guess is that one of your shaders is writing to the depth buffer in a different unit than what it’s expecting.
     
  5. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    So i need to check all my shaders. I am quite new to Unity and did not create any shaders myself, so perhaps there is some conflict between a few ! I'll check this and come back to this thread when I found something! :) Thanks @newjerseyrunner !
     
  6. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    (By the way, does it not seem weird that only a VMCam change does "trigger" this behaviour? There are not objects added or removed from the environment when changing the vcam....)
     
  7. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    I think I removed all shaders that are suspicious and still no solution or improvements. I even seperated more but that does not explain the behaviour of objects showing their inners.
     

    Attached Files:

  8. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    What's the clear flag on your camera? Maybe it's not clearing the buffer between frames? In fact, post a screenshot of the settings for both the camera that works and the one that doesn't. It certainly looks like a depth issue, but it could be something else like not double buffering?

    Can you just dump the depth buffer to a bitmap? I feel like the difference between your Editor and your device is some quirk between DirectX and OpenGL.
     
  9. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    I send here by my camera settings. The flag in the maincamera (which holds the cinemachine brain) is set to Skybox since... well, the game holds a skybox? But vcams cannot hold a camera flag since its virtual?
    I have NO idea how to dump the depth buffer to a bitmap; I am too young in Unity to understand this yet....
     

    Attached Files:

  10. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    (And thank you soooo much you read my panic post and hope you (or soneone else reading this) have a solution)
     
  11. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    I replaced cameras and 2 of 3 cameras did fix. the third is gliching again. So weird! Does not make sense (see image)
     

    Attached Files:

  12. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,324
    This kind of thing happens when your objects are VERY far away, and you're using low resolution zbuffer. Pretty much if you make a scene with centimeter scale, put a cube several kilometers away and look at it, if it doesn't have backface culling, you might observe similar behavior.

    It's been ages since I saw this glitch live, though.

    Do you really need far plane at 5000 units away? How do you zoom in?

    Are you, perhaps rendering onto a render target?
     
    angrypenguin and Joe-Censored like this.
  13. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    The stages are grids of 11x11 tiles. Every tile is 10f wide. But what is the definition of "far away" ? 5000 is the default setting on Unity.
     
  14. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,324
    "Far away" is "Where precision of depth buffer is not enough to resolve it".

    Like I said, looking at a small object through binoculars is very likely to trigger this artifact,

    In your case it looks like the grid is floating above the ground at close distance, and that's why it is clipping through it when it is far away. Same deal with the fences that are burried in the ground and so on.

    Increasing distance of "near clip plane" and decreasing "far clip plane" should fix this problem by the way. Just put the clipplane to original setting when you're done zooming.
     
  15. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    Yeah, 5000 seems a little insane. The default camera settings are designed to be just the most general purpose camera that you can slap in any scene and have it work. This is true for most default settings, each time you add one, you should go through every setting. You don’t have to fine tune it or anything, just look for values that are wildly too general purpose for your particular scene.
     
  16. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    Well, its getting weirder and weirder. The new cameras also do not work and also glitch the hell out of Android. When I compile the game for Windows I get another wird behaviour with the cameras but that has to do with the shadowing. It shiffers a lot. Perhaps the "same issue" with different results due the compilation for another system? See GIF.
     

    Attached Files:

  17. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    I wonder, what is the position of the objects? Are you keep them close to 0 origin. Or somehow 10k units distance away?
    Or, 2hat is the scale unit, you use as default?
     
  18. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    The fun fact is that normal game camera works perfectly, and even while blending to the virtual cameras its working great. when it reaches the virtual camera (end of the blending) it starts jittering.

    The position of the objects? Well, the grid is 11x11 with cubes of 10fx10f each, so a total of 110f by 110f.
    But does that matter since the invention of floats? ;-) So, its close-by (not 10K units)
     
  19. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18

    I Fixed the Near Clip (set to 50) and Far Clip Plane (set to 150) but too bad, no results or changes in behaviour. :(
     
  20. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,580
    In your case is not, since you are working with small distances.
    But range of glitches may start occurring, for both physics and rendering, when distance increase well beyond 10k.
    That is why I asked.
     
  21. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,324
    Here's fun thing. Depth Buffer is definitely stored as an integer number. 16-24 bit, usually, sometimes 32.

    Floats will start glitching 8 kilometers away from origin. Due to precision loss.

    Can you maks a small demo which reproduces this glitch and upload it somewhere?
    http://sscce.org/
     
  22. Yebbes

    Yebbes

    Joined:
    Jul 16, 2020
    Posts:
    18
    I checked the settings of the camera's again and now it seems to work and it has to due with... Near Clip (set to 1) and Far Clip Plane (set to 250 max). Weird also is that it at first did not work. But first I had the "disable depth and stencil" option disabled, then enabled (which made it even worse) and then disabled it again and thén is started working! Weird? But for now this issue is resolved.

    I would say the solution as follows:
    - Set the "Disable Depth and Stencil" setting to enable (player settings)
    - Fix the near clip and far clip plane to good reasonable values
    - Disable the "Disable Depth and Stencil" settings

    Fixed! (for me at least..)

    I would like to thank @neginfinity , @Antypodish and first responder @newjerseyrunner for their support on this case! Thank you all so much everyone! Please check the trailer that I shared on this forum on this URL: https://forum.unity.com/threads/my-first-game-build-what-do-you-think.981660/