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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Fog of War flicker

Discussion in 'General Graphics' started by abductor, Nov 28, 2019.

  1. abductor

    abductor

    Joined:
    Apr 19, 2017
    Posts:
    18
    Hello,

    I am building a top down stealth game for mobile and having issues with fog of war. I am using a camera which is capturing a mesh, representing the visible area of my player. This camera updates a rendertexture which is then picked up by a projector.

    Since my levels can potentially be very large, I do not want the projector and camera to cover the whole map. This would result in either very blurry edges of the visible area or a very large resolution of the rendertexture. So I only use a small area for the camera and projector and made them following my player.

    At first glance, everything is working well. But then I realized a flicker effect on the vertical faces of my obstacles. I assume that this is caused by the moving projector and/or camera.

    Has anyone encountered similar issues? Is my approach wrong? Please help


    flicker.gif
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
    This is your basic case of aliasing. You have a texture moving across the scene where the edge of the geometry moving through the pixels of the texture, so sometimes it’s “inside” the view shadow, and sometimes it’s “outside” depending on how the fog shadow texture and world geometry line up. You can fix the flicker by keeping the fog camera and projection locked to a fixed grid that matches the world space resolution. This makes sure that geometry always lines up with the texels of the fog shadow texture the same way. But this won’t fix some edges being dark.

    Ideally you want to have your “shadow caster” geometry to be slightly smaller than the objects casting the “shadows” for the fog of war texture. That way surfaces that are supposed to be visible won’t be self shadowing. Your idea of blurring is actually a fine way of handling this too, but you’re missing one last step, you need to adjust the curves of the shadow after you’ve done the blur so that the dark areas start further in. Assuming the texture in use is actually black for in shadow and white for in view, try just multiplying the blurred texture by 3 and clamping between 0 and 1 (
    saturate()
    ).
     
  3. abductor

    abductor

    Joined:
    Apr 19, 2017
    Posts:
    18
    Hi bgolus,

    thank you for your detailed answer. I already tried to shrink the size of my "visible area" mesh to avoid this effect but it still occurred. You are right: I think adjusting the shadow curves is the way to go.

    Meanwhile I changed the layer mask of my fow projector. Now only the ground is affected which turned out to come much closer to the effect I wanted to have ;)

    But just out of curiosity, I will try a little bit around with the saturate approach. fow.gif
     
    bgolus likes this.