Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global Fog Fade-In/Out Functionality
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#1
Global Fog Fade-In/Out Functionality

This was an idea I had a long while ago but never completed finished -- and the earlier versions of it weren't ideal for a true custom story -- if you exited the game during the fading sequence and returned later, wonky stuff was bound to happen, due to how global variables (with respect to the scope of each script file) are re-declared (essentially, they reset) whenever the map is loaded up, whether it be entering the map via a level door or loading up a save, etc. This caused some issues, naturally. As a result, this version is much longer due to the long-winded method of declaring and changing the variables with HPL2's API.

Anyways. Download the HPS file at the end of this post. Here's what you need to know about the functions to use.


PHP Code: (Select All)
void FadeGlobalFog(float fadeTimefloat Rfloat Gfloat Bfloat Abool skyBoxInclude); 

fadeTime: how long it takes the fog to fade to its target RGBA color. Not 100% accurate, so don't chain multiple fog fading sequences directly after one another. e.g. Don't script a fog fading in for 5 seconds, and add a timer to run a second fog fade exactly 5 seconds later. There might be a small overlap, and there is a countermeasure to prevent fading the fog while a fade sequence is already in execution.

float R, G, B, A: The color values for the fog. Don't use negative values, I haven't added a countermeasure against this yet. But that should be common knowledge -- if you seek to bug things out, you'll succeed (especially with such intimate access to the source behind the function)


bool skyBoxInclude: Whether the skybox color fades with the fog. You'll almost always want this set to true. It causes completely fogged areas to become the same color as the fog itself. This way you won't see a nice grey fog gradient which abruptly ends in a black area.




PHP Code: (Select All)
void FadeGlobalFogProperties(float fadeTimefloat startDistancefloat endDistancefloat fallOffExponentbool cullAtDistance); 

float fadeTime: Same as above.

float startDistance: The distance from the player that the fog starts.

float endDistance: The distance from the player that the fog ends. Don't set this below startDistance, or else the entire screen while become 100% fogged. No countermeasure yet. Be smart!
float fallOffExponent: How quickly the fog thickens. The smaller the value, the thicker the fog gets (and quicker). Don't set to 0, I'm pretty sure this will cause problems. No countermeasures.


bool cullAtDistance: Whether objects in 100% fogged out areas should be rendered on-screen or not. Unless your skybox is a different color than the fog (resulting in you being able to see the silhouettes of objects in 100% fog), you'll want this as true. I didn't merge the two into a single Boolean value on purpose.




PHP Code: (Select All)
void FadeGlobalFogExt(    float fadeTimefloat Rfloat Gfloat Bfloat Abool skyBoxInclude,        
         
float startDistancefloat endDistancefloat fallOffExponentbool cullAtDistance

See above for info on the parameters. This function just combines the two into a single fade event.




PHP Code: (Select All)
void FogDefault(); 

This function resets all of the variables used in the fog fading functionality and sets the fog and skybox color ACTIVE. Feel free to change the default values, but do take note of the variable names and make sure your script doesn't interfere with them. You most likely won't have to worry about it though.



More Info
````````
How to use in your script - Copy the two lines into your script. I've compressed them so they don't take up a large amount of the whitespace in your scripts. Just be sure to mark it with a comment or something so you know you've already included them! If you're already using Apjjm's parsing functions, don't copy the second line. Then, use any of the three above functions as you would any other HPL2 API function. Just be aware of the fact that you can only run 1 fade-in sequence at a time for now, inclusive of each other. Also, make sure you call FogDefault() in your map's OnStart. You can either change the values in the code block under FogDefault() or simply call FadeGlobalFog with a fade time of 0 seconds to instantly change the fog and/or skybox to the color of your choice. As an alternative to that, you can use the native API function SetFogColor / SetSkyboxColor, which also changes the color instantly.


Future versions will contain more countermeasures, perhaps some cleaner and easier to modify/read code. But for now it's basically just for functionality. Enjoy.


If you're worried about interfering with the local variables in your own script, look at the function FogDefault() -- it contains the default values for the fog and the names for all the variables involved in the fog fading.







Attached Files
.rar   fogfade-2.0.0.rar (Size: 1.24 KB / Downloads: 163)

(This post was last modified: 04-06-2012, 01:28 AM by palistov.)
04-02-2012, 02:49 AM
Find
Kman Offline
Posting Freak

Posts: 4,187
Threads: 25
Joined: Jul 2011
Reputation: 219
#2
RE: Global Fog Fade-In/Out Functionality

Saw this on palistov's livestream earlier today, and I have to say it reeeeeally improves the look of fog areas. I'd definitely recommend using it if you're doing any sort of outside area.

Posting Freak
04-02-2012, 07:14 AM
Website Find
JetlinerX Offline
Senior Member

Posts: 599
Threads: 49
Joined: Jun 2011
Reputation: 19
#3
RE: Global Fog Fade-In/Out Functionality

What exactly does this do? Fade fog in and out?

Lead Developer of "The Attic"
~Slade Mitchell

Chapter 3 (REL)

04-05-2012, 09:18 PM
Website Find
Miss Rigi Offline
Member

Posts: 240
Threads: 3
Joined: Aug 2011
Reputation: 31
#4
RE: Global Fog Fade-In/Out Functionality

(04-05-2012, 09:18 PM)JetlinerX Wrote: What exactly does this do? Fade fog in and out?
I think it makes dead cats rain from the sky.

Vos rapio meus spiritus absentis.
Voice Actress
04-05-2012, 10:31 PM
Find
JetlinerX Offline
Senior Member

Posts: 599
Threads: 49
Joined: Jun 2011
Reputation: 19
#5
RE: Global Fog Fade-In/Out Functionality

>_>'

Ugh

Lead Developer of "The Attic"
~Slade Mitchell

Chapter 3 (REL)

04-05-2012, 11:00 PM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#6
RE: Global Fog Fade-In/Out Functionality

JetlinerX, it operates the same way FadeLightTo does in the native API for HPL2. The attached script file contains three functions, compressed into a single line to make it easy to implement without taking up a huge amount of the whitespace in your file.

You should read the description of the functions and their parameters in the original post. That should clear up any questions.

04-06-2012, 01:16 AM
Find
JetlinerX Offline
Senior Member

Posts: 599
Threads: 49
Joined: Jun 2011
Reputation: 19
#7
RE: Global Fog Fade-In/Out Functionality

Awesome, thanks! We will experiment with this in our outdoor environments!

Lead Developer of "The Attic"
~Slade Mitchell

Chapter 3 (REL)

04-06-2012, 04:25 AM
Website Find




Users browsing this thread: 1 Guest(s)