Author Topic: [Solved] FoW - Make the fog white  (Read 6128 times)

Zyte

  • Guest
[Solved] FoW - Make the fog white
« on: November 18, 2013, 06:00:28 AM »
I've been staring at FOW.shader for an hour, and I just can't figure out how to invert the opacity so that I can have a white fog, and that blacker colors make it more transparent instead.

Could anyone help me out? :-\
« Last Edit: November 20, 2013, 08:00:43 PM by Zyte »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: FoW - Make the fog white
« Reply #1 on: November 18, 2013, 11:54:21 AM »
The shader tints the existing color by using multiplication. What you'd want to do is replace that part with another operation instead -- such as a color lerp(white color, original color, fowFactor);

Zyte

  • Guest
Re: FoW - Make the fog white
« Reply #2 on: November 18, 2013, 03:00:49 PM »
Thank you, it's getting closer:

  1. lerp(_Explored, original, fog.r);
With this code, I can put white or any color on the fog, but I can't find any way to control the opacity.


  1. lerp(_Explored, original, 0.5);
And with this code, everything gets fogged at 50% opacity. There is no "explored" area around the character.

Is there a simple way of doing this that I'm not seeing? I don't really know what I'm doing, I'm basically just going by trial and error.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: FoW - Make the fog white
« Reply #3 on: November 19, 2013, 09:53:10 PM »
Currently it is:
  1. return lerp(lerp(original * _Unexplored, original * _Explored, fog.g), original, fog.r);
Which is, when simplified:
  1. half4 tinted = lerp(original * _Unexplored, original * _Explored, fog.g);
  2. return = lerp(tinted, original, fog.r);
The first line blends between the unexplored (black) and explored (gray) colors.

The second line blends between the result of the previous, and the original (untinted) color.

As you can see, in the first line we use multiplication which simply tints the color. In your case what you want is to use just white color instead:
  1. half4 tinted = lerp(half4(1.0, 1.0, 1.0, 1.0), original * _Explored, fog.g);
  2. return = lerp(tinted, original, fog.r);

Zyte

  • Guest
Re: FoW - Make the fog white
« Reply #4 on: November 20, 2013, 06:44:59 AM »
Thank you for helping, Aren.

  1. half4 tinted = lerp(half4(1.0, 1.0, 1.0, 1.0), original * _Explored, fog.g);
  2. return lerp(tinted, original, fog.r);
The last code you wrote gives me this result:


What I'm trying to achieve is this:

(this is just photoshopped)

Would this be doable with some minor code tweaks? Otherwise I guess I'll just let it go, because I can't wrap my head around this Shader language. :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: FoW - Make the fog white
« Reply #5 on: November 20, 2013, 03:34:44 PM »
If you don't want the pillars to be affected by the fog, then you have to either write a shader that only affects the terrain, or draw your pillars using a separate camera that's drawn after the terrain. Both approaches have their own drawbacks.

Zyte

  • Guest
Re: FoW - Make the fog white
« Reply #6 on: November 20, 2013, 04:15:29 PM »
Oh, sorry for being unclear. Ignore the pillars - I just put them there so that it wouldn't just look like grey-colored fog.

I simply want white fog at 50% opacity. :-\

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: FoW - Make the fog white
« Reply #7 on: November 20, 2013, 07:32:14 PM »
  1. half4 tinted = lerp(half4(1.0, 1.0, 1.0, 1.0), original * _Explored, fog.g * 0.5 + 0.5);
  2. return = lerp(tinted, original, fog.r);

Zyte

  • Guest
Re: FoW - Make the fog white
« Reply #8 on: November 20, 2013, 07:59:32 PM »
Perfect! Haha, thank you so much!

Sorry for being such a dummy. ;D