Jump to content
Sign in to follow this  
thasundancekid

Trigger dif color effects when weather changing/time of day

Recommended Posts

So i was figuring, it would be awesome to trigger different color effects depending on what time of day and what weather it is.

Think a more blue/gray at rain, and a more orange/purple at sunset etc.

I´ve manage to get pretty amazing setups with the 'effect viewer'

http://www.armaholic.com/page.php?id=10164

And to take it even further, would it be possible to add effects when you use different vehicles, when shots are fired or the lightning strikes...

I can think of two problems;

1) when say, the time has come for sunset, the effect will be trigger on the second and it likes baaam all orange and purple. I mean i want a smooth transfer...

2) will the vehicle effects work together with the world effects? if say,hmm, its all red outside, and its all blue inside a vehicle, will the result be purple

(i hope you understand what im trying to say here) :p

And last

What do you say? will it be a hugepainintheassproject for a newbie?

Share this post


Link to post
Share on other sites

¨Thanks, i think its a nice idea to :ok:

And i dont mind if anyone wants to steal the idea from me ;):D

Share this post


Link to post
Share on other sites

I use these to control the amount of blue night effect depending on suns azimuth, which also controls how readable the map is (covering it with black markers, but can be countered by using a "flashlight", but that's another story I guess).

Get the suns azimuth, not 100% true to the engine code, but seems to do the trick. If you're interrested in trying, by accident I recently found the BIS code here.

fn_SunElev = {
private ["_lat", "_day", "_hour", "_angle", "_isday"]; //Not 100% correct to BIS own code, but it does the trick.
_lat = -1 * getNumber(configFile >> "CfgWorlds" >> worldName >> "latitude"); //Arma latitude is negated for some odd reason.
_day = 360 * (dateToNumber date); //Convert current day to 360 for trigonometric calculations.
_hour = (daytime / 24) * 360; //Convert current hours to 360 for trigonometric calculations.
_angle = ((12 * cos(_day) - 78) * cos(_lat) * cos(_hour)) - (24 * sin(_lat) * cos(_day)); //New one liner magic.
_angle
};

Function to normalize a value, with clamping and safety checking against "bad" values. You might want to reconsider failsafing is you know all your inputs will be valid.

fn_Normalize = {
/*'
Examples:
[15] call fn_Normalize gives an error message.
[15, 1, 9] call fn_Normalize gives 1, since clamping is by default on.
[15, 1, 9, true] call fn_Normalize gives 1, obviously same as above.
[15, 1, 9, false] fn_Normalize gives 1.75 when clamping is turned off.

Practical example:
[-14, -1, sunelevation] call fn_Normalize will scale the suns angle from -14° to -1° into
a 0-1 value which can be used to control a night post effect. If clamping was turned off,
you could get values the post effect system could not handle well. With clamping on, even
if the sun goes 50° below the horizon, you will get 0 in output instead of a negative value.
'*/
private ["_normalized","_min","_max","_failsafe","_clamp","_s"];
_normalized = _this select 0;
if (count _this < 3) exitWith {
	_s = format ["fn_normalize requires three parameters, only %1 given", count _this];
	if (bDebug) then {format ["fn_Normalize - %1", _s] call debugChat};
	_normalized
};
_min = _this select 1;
_max = _this select 2;
_clamp = if (count _this > 3) then {_this select 3} else {true};	//Optional parameter, default true. If false, answer may be outside 0-1 range.
_failsafe = if (_min == _max) then {0.0001} else {_min - _max};		//Avoids division by zero errors in the event of equal inputs.
_normalized= 1 - ((_normalized - _min) * (1 / _failsafe) +1);		//Scales the input parameter to 0-1.
if (_clamp) then {_normalized = _normalized max 0 min 1};			//And clamps outside values if not actively set to false.
_normalized
};

This one returns the parameter you plug right into the post processing effect.

fn_BlueNight = {
private ["_ret","_amount","_bgtcontrast","_color"];
_amount = call fn_SunElev;
_amount = [_amount, -14, -1] call fn_Normalize;
_amount = _amount min 1;
_amount = _amount max 0;
_amount = 1 - _amount; //Max effect when sun is -10° below horizon (or lower), no effect when sun is -1° below horizon (or higher).
_bgtcontrast = 1.0 - 0.25 * _amount;
_color = -0.06 * _amount;
//	format ["fn_BlueNight - amount = %1, bgtcontrast = %2, color = %3", _amount, _bgtcontrast, _color] call debugChat;
_ret = [ _bgtcontrast, _bgtcontrast, 0, [0, 0, _color, _color],[0, 0, 0, 1],[0, 0, 0, 0]];
_ret
};

Just for fun, I throw in the map thing too, though it's not fine tuned yet. If you have GPS, you need to remove the filter so the map can be seen:

fn_UpdateMapFilter = {
private ["_amount"];
_amount = call fn_SunElev;
_amount = [_amount, -14, -1] call fn_Normalize;
_amount = _amount min 1;
_amount = _amount max 0;
_amount = 1- _amount;
if (!visibleMap) then {
	{_x setMarkerAlpha _amount} forEach ["mFilterBlack1","mFilterBlack2","mFilterBlack3","mFilterBlack4","mFilterBlack5","mFilterBlack6"];
	{_x setMarkerAlpha 0} forEach ["mFilterRed1","mFilterRed2"];
	nFlashAmount = 0;
	liFlashlight setLightBrightness 0;
};
};

Script that adjusts the actual flashlight, based on input from a radio trigger, which is nicely available when you're in the map. Note that it must be turned off when map is not open, so the function above must be run in a loop in order for GPS and other displays that uses the default map to work.

_direction = _this select 0;
_marker = markerAlpha "mFilterBlack1";
_black = 0;
_red = 0;
_val = 0;
_maxfx = 0;
_maxfx = call fn_SunElev;
_maxfx = [_maxfx, -14, -1] call fn_Normalize;
_maxfx = _maxfx min 1;
_maxfx = _maxfx max 0;
_maxfx = 1 - _maxfx;

liFlashlight attachTo [player, [0.05, 0.12, 0.8]];
switch (_direction) do {
case "increase" : {
	if (nFlashAmount <10) then {
		nFlashAmount = (nFlashAmount + 1) min 10;
		player say "FlashLightClick";
	};
};
case "decrease" : {
	if (nFlashAmount>0) then {
		nFlashAmount = (nFlashAmount - 1) max 0;
		player say "FlashLightClick";
	};
};
};
_val = 0.1 * nFlashAmount;
_red = 0.6 * (_val min _maxfx);
_black = (1 - _red) min _maxfx;
liFlashlight setLightBrightness nFlashAmount * 0.025;

{_x setMarkerAlpha _red} forEach ["mFilterRed1","mFilterRed2"];
{_x setMarkerAlpha _black} forEach ["mFilterBlack1","mFilterBlack2","mFilterBlack3","mFilterBlack4","mFilterBlack5","mFilterBlack6"];

if (bDebug) then {format ["Flashlight - %1",_black] call debugChat};

Warning, this color correction thing it will only work "good" in missions where you don't get to have NVGoggles, as color corrections doesn't seem to work with NVGs (appears to have its own). So, it does have limited use.

These are only the functions, I'm sure you can figure out how to use them, simple stuff, but adds a lot of immersion to missions. Why do I use it? I like dark night missions where you may have problem seeing anything (just as I remember from my time in the Army). The moon provides too much light, and when there is no moon, you have zero visibility which naturally is unplayable. And the atmosphere doesn't provide any lighting whatsoever to the landscape during sunsets and dawns. I want a challenge, not an impossibility.

There are probably some bugs there as well. I prefer to not write bugfree code, it sometimes appears :D

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×