Fog fade thing...

Posted By: Loopix

Fog fade thing... - 06/06/07 15:21

Because there are so many helpfull and n00b-friendly people on this forum, I'll ask my next question

I'm fading my fogcolor from evening to night and use now a single "fog_fade_speed" variable for the fade-speed. Logicaly this gives bad results because the count-down/count-up to the night fogcolors is different for each fogcolor(rgb). Now I'd need a formula that calculates the fog_fade_speed var for each fogcolor-shifting...you know what I mean?

Here what I have so far (just crap!!!):
Code:
//evening
var fog_eve_r = 250;
var fog_eve_g = 120;
var fog_eve_b = 60;

//night
var fog_night_r = 4;
var fog_night_g = 9;
var fog_night_b = 14;


var fog_fade_speed = 0.08; //...multiplied by time_speed

function suneve_fog_fade{

if d3d_fogcolor1.red > fog_eve_r {d3d_fogcolor1.red -= fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.green > fog_eve_g {d3d_fogcolor1.green -= fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.blue > fog_eve_b {d3d_fogcolor1.blue -= fog_fade_speed*time_step*time_speed;}

if d3d_fogcolor1.red < fog_eve_r {d3d_fogcolor1.red += fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.green < fog_eve_g {d3d_fogcolor1.green += fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.blue < fog_eve_b {d3d_fogcolor1.blue += fog_fade_speed*time_step*time_speed;}
}

function sunset_fog_fade{

if d3d_fogcolor1.red > fog_night_r {d3d_fogcolor1.red -= fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.green > fog_night_g {d3d_fogcolor1.green -= fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.blue > fog_night_b {d3d_fogcolor1.blue -= fog_fade_speed*time_step*time_speed;}

if d3d_fogcolor1.red < fog_night_r {d3d_fogcolor1.red += fog_fade_speed*time_step*time_speed);}
if d3d_fogcolor1.green < fog_night_g {d3d_fogcolor1.green += fog_fade_speed*time_step*time_speed;}
if d3d_fogcolor1.blue < fog_night_b {d3d_fogcolor1.blue += fog_fade_speed*time_step*time_speed;}
}


Posted By: nipx

Re: Fog fade thing... - 06/06/07 15:40

make it relative to the difference of the colors. Means something like

Code:

if d3d_fogcolor1.red < fog_eve_r {d3d_fogcolor1.red += (abs(fog_eve_r-fog_night_r)/25)*time_step*time_speed;} //play with 25




Haven tested anything but sounds logical imao


nipx
Posted By: Loopix

Re: Fog fade thing... - 06/06/07 15:55

Thanks! I'll try that...sounds indeed logical
Posted By: xXxGuitar511

Re: Fog fade thing... - 06/06/07 16:12

Use a vec_lerp()...

vec_lerp(d3d_fogcolor1, fromColor, toColor, percent/100);
Posted By: Loopix

Re: Fog fade thing... - 06/06/07 16:59

sounds even better But I don't quite see how to implement it for my use Would you mind to give me some more hints?

Thanks
Posted By: xXxGuitar511

Re: Fog fade thing... - 06/06/07 17:58

the first parameter is the vector to put the result in. For this, I used d3d_fogcolor1

the second and third are the vectors to mix between. First vector is the source color, and the second is the target color.

the fourth vector is the interpolation factor (0 - 1). This is the percentage to mix each color. At 0, the first color will be used. At 1, then second color will be used. 0.5 would be a perfect mix between the two...


Code:

//evening
var fog_eve[3] = 250, 120, 60;

//night
var fog_night[3] = 4, 9, 14;

var fog_fade_speed = 0.08;

function fadeColors(&colTarget, &col1, &col2)
{
var i = 0;
while(i < 100)
{
i = min(i + fog_fade_speed*time_step, 100);
vec_lerp(colTarget, col1, col2, i/100);
wait(1);
}
}

var currentColor[3];
Function etc_startup()
{
fog_color = 1;
//
vec_set(currentColor, d3d_fogcolor1);
fadeColors(d3d_fogcolor1, currentColor, fog_eve);
//
wait(-2);
//
vec_set(currentColor, d3d_fogcolor1);
fadeColors(d3d_fogcolor1, currentColor, fog_night);
}



This code would fade the current fog color to the evening fog color, then wait 2 seconds, and then fade to the night colors.
Posted By: Loopix

Re: Fog fade thing... - 06/06/07 18:06

Oh...thanks! Now this looks indeed promissing. I'll try ASAP and let you know if I got it to work

Thanks for your input!
Posted By: Loopix

Re: Fog fade thing... - 06/06/07 19:38

I get a crash in vec_lerp(colTarget, col1, col2, i/100);

I think function parameters don't take vectors Do you know a quick and dirty workaround?
Posted By: xXxGuitar511

Re: Fog fade thing... - 06/06/07 20:33

oh, sorry... fixed the above code
Posted By: Loopix

Re: Fog fade thing... - 06/06/07 22:49

Works perfect now THX!
Posted By: xXxGuitar511

Re: Fog fade thing... - 06/07/07 02:35

np...

..always time to help out Loopix
© 2024 lite-C Forums