Author Topic: Fog of War: show an object through the fog  (Read 4915 times)

hummada23

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 45
    • View Profile
Fog of War: show an object through the fog
« on: December 07, 2014, 09:18:39 PM »
Hi,

I have a shader that renders the player object differently when it is blocked by level geometry (so that the player is always visible). I'm using a completely opaque Fog of War as well, which will sometimes cover the player as well (if, say, there's a large building between the player and the camera, and the other side of the building is covered by the fog of war). How can I modify the player's shader or the fog shader (say, by changing the render queue) to allow players to remain visible through the fog?

Here is what I think is the relevant part of the shader I'm using for the player:

Tags {"Queue"="Overlay" "RenderType"="Opaque" } 
    ZTest Equal
   ZWrite On

And here is what I think is the relevant section of the fog shader:

Pass
      {
         ZTest Always
         Cull Off
         ZWrite Off
         Fog { Mode off }

Any help would be greatly appreciated.


hummada23

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Fog of War: show an object through the fog
« Reply #1 on: December 07, 2014, 09:25:37 PM »
If it's not possible to alter either of the shaders to get the object to draw through the fog, is it possible to add a layer to an object and get the fog to not cover objects on that layer?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Fog of War: show an object through the fog
« Reply #2 on: December 09, 2014, 02:11:22 PM »
To have selective fog of war like that you can't use the post-process-based approach (FOWEffect). You need to use the custom material shader approach instead (the other example that comes with the FOW package). Basically things that you want to be affected by the fog need to have a custom shader that will sample it. Things that shouldn't be affected can keep their existing shaders. FOWEffect won't be used at all.

hummada23

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Fog of War: show an object through the fog
« Reply #3 on: December 09, 2014, 07:15:37 PM »
Thanks for this. I'll look into it.

hummada23

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Fog of War: show an object through the fog
« Reply #4 on: January 02, 2015, 11:54:24 PM »
Hi,

I've turned off the FOWEffect on the main camera, and assigned the "Fog of War/Diffuse" shader to everything except the fog revealer. But now no fog is showing at all. Is there something else I need to do in order to switch from using a post processing effect to using a shader approach?

hummada23

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Fog of War: show an object through the fog
« Reply #5 on: January 03, 2015, 12:00:13 AM »
Or, alternatively, is there absolutely no way to modify the fog shader so as to draw it behind one of the render layers- say by applying a z order to it?

hummada23

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Fog of War: show an object through the fog
« Reply #6 on: January 03, 2015, 04:41:02 AM »
I wasn't able to get this working with the shader approach, although I did finally figure out a workaround for the post processing approach. The solution was to use multiple cameras and put the fog on its own camera, then play around with the z order of the different cameras.