Author Topic: Fog of War: Custom shaders in editor mode  (Read 2291 times)

garside

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Fog of War: Custom shaders in editor mode
« on: February 19, 2015, 01:58:48 PM »
So I'm using the super great Fog of War system using the custom shaders, which work great. The only issue I'm running into is when I'm in the editor, the terrain shader and all the individual items which I have the FoW style shader on are completely black.

Is there a way to get them to render as though everything were visible when the editor is open and the application is not playing?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,149
  • Toronto, Canada
    • View Profile
Re: Fog of War: Custom shaders in editor mode
« Reply #1 on: February 19, 2015, 05:42:00 PM »
I haven't had a look at custom shader-based FoW approach as I use the effect-based one in Windward, but I'm guessing it would be as simple as changing the default texture value in the shaders from "black" to "clear", or "white", depending on what the shader uses as "visible".

garside

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Fog of War: Custom shaders in editor mode
« Reply #2 on: February 26, 2015, 09:06:07 AM »
So I took a look but all the shaders seemed to already have white or clear as their default color. My knowledge of shaders is super limited, so I decided to try a different avenue and came up with some success.

Instead of addressing the shader code at all (cause I implemented like dozens of shaders to use the FOW system), I added a small utility to fix the issue.

There's likely a better way to handle it, but I'm not very experienced writing editor scripts either. For now, I just created a new game object, put it as a child of the FOWSystem, tagged it as EditorOnly, and threw the following component on it:

  1. [ExecuteInEditMode]
  2. public class FOWEditor : MonoBehaviour
  3. {
  4.         void Update ()
  5.         {
  6.                 if (!Application.isPlaying)
  7.                 {
  8.                         Shader.SetGlobalColor("_FOWUnexplored", Color.white);
  9.                         Shader.SetGlobalColor("_FOWExplored", Color.white);
  10.                         return;
  11.                 }
  12.         }
  13. }
  14.  

Edit:

I had modified the FOWSystem directly to do this originally, but it made the console whine about the textures being unused all the time, so I moved it to a separate utility to quiet the console.
« Last Edit: February 26, 2015, 12:59:32 PM by garside »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,149
  • Toronto, Canada
    • View Profile
Re: Fog of War: Custom shaders in editor mode
« Reply #3 on: February 27, 2015, 05:04:54 AM »
This seems like a good approach.