Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Camera Clear Flags to Depth Only not behaving as expected.

Discussion in 'Scripting' started by ihgyug, Mar 16, 2019.

  1. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    145
    Hi there,
    I am working on a 2D game and I am trying to have 2 cameras at the same time, first camera that renders the background (a particle system of stars) full size, and the second one that is forced at 16:9, that renders the rest.
    The first camera, has Clear Flags to Depth Only, and a greater Depth compared to the second camera.
    The second camera, has Clear Flags to Solid Color.
    They both have Rendering Path set to Forward, and Projection set to Ortographic.

    The issue I am having is that, the first camera that has Clear Flags to Depth Only doesn't clear the previous frame...which in time makes the whole screen white.
    I wonder what could cause such issue?
    Thank you all in advance
     
  2. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    873
    Are the layers all set up right? Do you have some screens of your inspector/setup?
     
  3. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    145
    Even having only this camera in an empty project (only with the particles to test) causes the same issue.

    upload_2019-3-17_15-6-50.png
     
  4. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    873
    Clearing depth only will flood your screen with the last pixels, or am I getting it wrong? So what happens if you have a camera with depth 0 and clear flags color everything?
     
  5. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    145
    For simplicity sake I just have this camera for now, once I manage to fix this camera I'll work on the setup with second camera (second camera have nothing to do with the issue as far as I saw, since having it or not having it produces the same issue on first camera).
    You are getting it right, the last pixels remain on screen, flooding the screen overtime, so no clearing is happening I suppose. It's behaving like a "Camera Clear Flags : Don't Clear" but it's not, as shown in the screenshot.
    I suppose you are suggesting to have a second camera with depth 0 and clear flags to solid color, which I already tried and it doesn't work.
    The issue is with this simple camera, and I can't figure out what's wrong. Using Unity 2018.3.8 by the way.
     
  6. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    873
    The camera which das clear depth only only updates the pixels where some depth change happens. From what I understand you writing, it is doing what it is supposed to do. You have to have something clearing the screen behind your camera. So if I set the camera(1) to depth 0, clear solid color and only cull default layer, I can above set camera(2) to depth clear and culling mask to only "myCustomLayer" and put my gameobject (in my case test sphere) on that layer too, it will render and clear. If you onl yhave that one camera, you will always fill up the screen, maybe you getting "depth clear" wrong.
     
  7. ihgyug

    ihgyug

    Joined:
    Aug 5, 2017
    Posts:
    145
    Same setup, doesn't work.
    I weirdly had Warning Log messages to "closed" and I now notice a warning :
    "Tiled GPU perf. warning: RenderTexture color surface (720x1280) was not cleared/discarded. See TiledGPUPerformanceWarning.ColorSurface label in Profiler for info".
    Must be that...
    EDIT : The warning appears when changing the camera Viewport Rect...seems I can't do anything but report to Unity.
     
    Last edited: Mar 17, 2019
  8. asd234w4r5

    asd234w4r5

    Joined:
    Oct 4, 2012
    Posts:
    873
    Oh okay, ya that sounds like a bug I guess. Did you try to build the same setup in another version of Unity? Just to be sure, because I am working on 2018.3.3f and can throw in as many cameras with those settings as I want, so I guess it is a TileGPU thing, you are sure its not your GPU? Maybe also try to update the drivers, just some guesses.