Frictional Games Forum (read-only)
Global Fog Fade-In/Out Functionality - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Articles (https://www.frictionalgames.com/forum/forum-40.html)
+---- Thread: Global Fog Fade-In/Out Functionality (/thread-14426.html)



Global Fog Fade-In/Out Functionality - palistov - 04-02-2012

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:
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:
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:
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:
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.








RE: Global Fog Fade-In/Out Functionality - Kman - 04-02-2012

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.


RE: Global Fog Fade-In/Out Functionality - JetlinerX - 04-05-2012

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



RE: Global Fog Fade-In/Out Functionality - Miss Rigi - 04-05-2012

(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.



RE: Global Fog Fade-In/Out Functionality - JetlinerX - 04-05-2012

>_>'

Ugh



RE: Global Fog Fade-In/Out Functionality - palistov - 04-06-2012

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.


RE: Global Fog Fade-In/Out Functionality - JetlinerX - 04-06-2012

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