Author Topic: Fog of War with transparent shader?  (Read 4216 times)

Dennis_N

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Fog of War with transparent shader?
« on: May 06, 2014, 06:16:37 PM »
I need to use fog of war on my scene where I have some transparent polygons on my terrain. Unfortunately those polygons are moving in and out of the darkness, and in-between they don't shade right. Can you give me a transparency shader that works properly with your script?
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Fog of War with transparent shader?
« Reply #1 on: May 06, 2014, 10:16:47 PM »
Fog of War works by tinting the color of each pixel after checking its depth. Transparent shaders don't write to depth, so it's not possible to shade them properly. You need to use a shader that actually writes to depth. A two-pass shader (first time to draw to depth, second time to draw the object) would do the trick -- however this is a Unity usability question at this point -- and you can find a few examples just by doing a google search.

https://www.google.ca/search?q=unity+transparent+depth&oq=unity+transparent+depth&aqs=chrome..69i57.2914j0j7&sourceid=chrome&es_sm=0&ie=UTF-8#q=unity+transparent+depth+shader

Like this for example: http://forum.unity3d.com/threads/149511-Transparent-Depth-Shader-(good-for-ghosts!)