Search Unity

Understanding linear fog end + camera far plane relationship

Discussion in 'General Graphics' started by ChanzDog, May 14, 2020.

  1. ChanzDog

    ChanzDog

    Joined:
    Sep 28, 2017
    Posts:
    43
    I am using linear fog. The fog color matches the clear color of the camera and it looks good. I do however see some occasional weirdness where the far clip plane is cutting an object in half which means that the fog depth isn't being calculated correctly.

    I was under the impression that the fog end must match the far clip plane of the camera. This makes sense that the fragment color is an interpolation between the fragment color and the fog color given the depth. But I am seeing visual oddities.



    The trees are being visibly cut meaning that the depth calculation appears to be off somehow. I am using a custom shader, but I see the same issue with the SimpleLit shader.

    I know I can simply increase the far plane or decrease the fog distance, but I shouldn't have to. They should not produce this visual issue, unless my understanding of the math is wrong. And I am emulating an old game engine so this needs to be as accurate as possible.

    Thanks!