[contribution] Fog code Lite-C

Posted By: Helghast

[contribution] Fog code Lite-C - 02/19/10 17:03

I have update my fog script from old A6 wdl to new A7 lite-c.
Wanted to share it with people.
It's made after silent hill 2, but eats away at your FPS, since it uses several function for each fog sprite.
At the time I had no trouble with it, since it was a big part of the gameplay and feeling.

You can use the code for free, and the dust particles i made (they were a 2 minute creation last night :P) as well.



downloadlink (~45kb): http://www.designorhea.com/3DGS/Fog.rar
have fun with it wink
Posted By: zeusk

Re: [contribution] Fog code Lite-C - 02/19/10 17:54

thanks man just got finished reading the original post. this'll be great for my current project.
Posted By: mikaldinho

Re: [contribution] Fog code Lite-C - 02/19/10 17:59

as said before it will look great in my project.

have you noticed how something as simple as fog is such a big thing in games?
Posted By: zeusk

Re: [contribution] Fog code Lite-C - 02/19/10 18:17

yeah the demo im making for joquan games is almost done but i couldnt get the fog right.
Posted By: mikaldinho

Re: [contribution] Fog code Lite-C - 02/19/10 18:21

and now you can!
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/01/10 01:21

Thanks Helghast! If you did share this contribution 2 years ago, this would be "best contribution of the year" for me. smile
But anyway, rain and fog are the major components of the game atmosphere and your fog effect is great!

Posted By: Widi

Re: [contribution] Fog code Lite-C - 04/01/10 04:14

Great, download it, start it and includet at my Project. Thanks
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/01/10 08:10

I'm glad it's usefull to all you guys laugh
Again, im not sure on the speed of it, but if it's a major part of the ambience, then I think it's no issue. Let me know how it impacts performance.

I might indeed try some rain next time, haha tongue

regards,
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/01/10 10:38

request. do you still have the c-script version? I can really use it.
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/01/10 11:12

Originally Posted By: Blink
request. do you still have the c-script version? I can really use it.


I think I accidentally overwrote that when updating it to lite-c xD I'll have a look tonight.
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/01/10 22:01

thanks, i will keep my fingers crossed,lol.
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/02/10 23:00

Hey Helghast & folks, look at the video. i have create an animated sprite. it's not perfectly but looks pretty good. (looks really like silent hill 2 now grin )
Sprites are here. (Alternative here )
And some hints to explain how to use it;
Code:
function animate_for_fog()
{
	wait(-integer(random(3)));
	my.frame =0;
	while (1) 
	{ 
		my.frame += 0.6*time_step; 
		if (my.frame >= 32) { my.frame = 1; }
		wait(1); 
	} 
}
void autofog()
{
..........
animate_for_fog();
	if(integer(random(10))>5)
	{
		vec_scale(my.scale_x, 7.8);	
	}
	else
	{
		vec_scale(my.scale_x, random(4));	
	}
..........
}
void generate_fog()
{
..........
if(randint == 0){ ent_create("dust+32.tga", pos_place, autofog); }
if(randint == 1){ ent_create("dustdense+32.tga", pos_place, autofog); }
..........
}


but we need better sprite than my sprite anyway .


Posted By: ncc1701d

Re: [contribution] Fog code Lite-C - 04/02/10 23:42

I liked the video. I have the sprites and code here now. Where are the tips on how to use it?
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/03/10 00:36

i like it a lot! i need a c-script version, has anyone converted it or have the original fog code?
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/03/10 22:03

Originally Posted By: Blink
i like it a lot! i need a c-script version, has anyone converted it or have the original fog code?


Haven't been home to look on my HDD yet! xD
Will have to wait after easter, but mind you, I have the feeling I lost it... I think though it's easy to convert back to c-script. I might as well do that at some point then, I have had more c-script requests.

I like the movie alot, shows the effect of quite well indeed grin
I'll put that in my portfolio, hope you dont mind me using that movie laugh

regards,
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/04/10 00:44

of course you can use it wink
and if you want upload it to your youtube channel, you can download from here
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/04/10 01:30

Thanks, Helghast, I will wait for it. i hope its still on your hdd.
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/04/10 05:00

Forget it, forget animated sprite, forget first video. I've created a shader now. Also there is ash effect with shader like silent hill.
Watch this video. cool

I need to sleep now.
See you later friends.
Posted By: 3run

Re: [contribution] Fog code Lite-C - 04/04/10 05:16

Ohh! DAMN!!! THAT LOOKS SO GREAT!! Do hope that you'll share this sweet with us)))
Posted By: Nidhogg

Re: [contribution] Fog code Lite-C - 04/04/10 06:41

@Emre
Look great, hows the FPS
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/04/10 08:23

Originally Posted By: Emre
Forget it, forget animated sprite, forget first video. I've created a shader now. Also there is ash effect with shader like silent hill.
Watch this video. cool

I need to sleep now.
See you later friends.


That looks marvelous! I like it when people take things to a next level, great job! Hope you want to contribute that, I can upload it for you to my webserver laugh

regards,
Posted By: bart_the_13th

Re: [contribution] Fog code Lite-C - 04/04/10 09:27

OMG, that's soooo Cool... I see that the dust and debris changed their direction, how did you manage that?
Oh, one thing I noticed is that the fog move trough the ground, maybe you can avoid this by fade it out when the height is very low.
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/04/10 10:31

Originally Posted By: bart_the_13th
OMG, that's soooo Cool... I see that the dust and debris changed their direction, how did you manage that?
Oh, one thing I noticed is that the fog move trough the ground, maybe you can avoid this by fade it out when the height is very low.


I was thinking about that too, but that would EAT framerate...
Maybe i can borrow some Shade-c another day and make them soft particles.. But i dont know how that would impact the framerate tongue will try that some other time laugh

regards,
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/04/10 19:32

i am so amazed! i hope this gets a c-script version!
Posted By: EvilSOB

Re: [contribution] Fog code Lite-C - 04/05/10 06:57

Emre,

you'd better post this as a contribution somewhere dude,
or Im gunna hunt you down and stalk your mother!

(or can I just say please? Cheaper than airfare...)
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/05/10 16:05

wow, i rally hope there is a c-script version too, emre. Looks awesome! I am really jealous that all the best code snippets are lite-c only,lol.
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/05/10 17:47

Originally Posted By: Blink
wow, i rally hope there is a c-script version too, emre. Looks awesome! I am really jealous that all the best code snippets are lite-c only,lol.


I've just looked on my HDD, I havent got the .wdl anymore unfortunately. But if you give me a little bit longer, i'll convert it for you laugh

kind regards,
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/05/10 18:41

THANKS!!!! That would be awesome, you are a good man, Helghast.
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/05/10 20:25

Hello again,
i want to share it today but i'm still working on it.Because framerate is very low for now.
I have to make some arrangements for the best framerate.
it will be completed soon, just give me a few day.
There will be two versions: The original(in the video) and the optimized version.

@EvilSOB
Maybe you are right, but this is Helghast's contribution, i just developed it.
When i finished, I'll be sharing here firstly. wink
Posted By: EvilSOB

Re: [contribution] Fog code Lite-C - 04/05/10 20:32

Ive already gotten Helghasts but from this threads initial post, so I dont need his part anymore.
(plus the kids in his avatar are scary, so I aint gunna stalk him...)

I am looking forward to comparing the two at a code level, to learn a bit more
about converting lite-c processes to shader processes.
It looks to be a very educational shader... Hopefully its well commented...
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/07/10 22:17

Originally Posted By: Helghast

I was thinking about that too, but that would EAT framerate...
Maybe i can borrow some Shade-c another day and make them soft particles.. But i dont know how that would impact the framerate tongue will try that some other time laugh
regards,

I worked on it a bit. I am not knowledgeable about softparticle. Because i am not shader programmer.
I tried a different way with depth rendering. i don't know how can i explain it with my poor english.
I'll try to show few pictures....
before;


after;




Also thanks for your suggestion of webserver.
I already have my own webserver. wink
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/07/10 22:31

thats beautiful.
Posted By: Redeemer

Re: [contribution] Fog code Lite-C - 04/07/10 22:33

That looks really nice. You could use that effect in a Silent Hill type game, or just as a neat Warzone effect. laugh
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/07/10 22:48

i know, thats why i want it sooo bad,lol!
Posted By: Helghast

Re: [contribution] Fog code Lite-C - 04/08/10 07:57

wow Emre... you're taking my contribution to a whole new level.
I could never do this, as i have NO knowledge of shaders at all.

I'm hoping you can send me these codes so i can make some movies with it to upload to my own portfolio website. Also, sharing it with the community ofcourse would be best wink

I'm wondering now though, how much is changed from the original code i uploaded?
Just curious wink

regards,
Posted By: Quad

Re: [contribution] Fog code Lite-C - 04/08/10 09:15

oh man, that looks awesome!
(frame rate impact of the shader?)
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/09/10 10:14

@Helghast; Your code is best, i don't see any reason for changing your code. I've just created shader, and i've just add some minor codes for shader performance, just this. And of course i will share it with community, and send to you firstly. wink
@Quadraxas; bad, i am working for best framerate wink
Posted By: DLively

Re: [contribution] Fog code Lite-C - 04/09/10 21:11

Wow Helghast's version was amazing.. not that it isn't now!
But Now.. it looks Really Amazing with the new shader and particle adjustments.

Very, very good work, both of you!

I too can't wait for a c-script version!
Posted By: Hummel

Re: [contribution] Fog code Lite-C - 04/10/10 19:04

@Emre: a promising method to speed up particle rendering is descriped in GPU Gems 3 with 'off-screen particles' but I dont now how far it is understandable for you...nevertheless, look really cool so far. Would like to see it in motion wink
Posted By: bart_the_13th

Re: [contribution] Fog code Lite-C - 04/11/10 13:34

Looks cool but it seems you're using z depth to modulate the fog. It made it no difference with simple z fog I think.
Posted By: Emre

Re: [contribution] Fog code Lite-C - 04/11/10 16:30

@Hummel; yes it's not understandable for me. But thanks for information. wink
@bart; Yes as you say.
------------------------
i wont be at home for a few days. So i'm not going to work about this fog more. I'm tired anyway.
You can download from here friends.
Greetings.
Posted By: PietroNifosi

Re: [contribution] Fog code Lite-C - 04/11/10 17:23

I like it a lot, thanks for the contribution, although it kills the framerate -.-
Posted By: Nidhogg

Re: [contribution] Fog code Lite-C - 04/11/10 23:59

Thankyou very much Emre
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/12/10 00:52

still awaiting a c-script version....hoping one is being made.....please?
Posted By: Redeemer

Re: [contribution] Fog code Lite-C - 04/12/10 01:53

It's not hard to convert from Lite-C to C-Script. With a little effort you could do it yourself...

Besides, this way you can learn Lite-C too. wink
Posted By: Blink

Re: [contribution] Fog code Lite-C - 04/12/10 04:27

no time right now, and to be honest, i just kinda got a hold on c-script, so convert isnt an option for me. if you want to take a crack at it, be my guest.
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/12/10 08:02

Here is the C-Script version Fog C-Script version download , Only took me about 10 minutes.
I am using A7.840 Pro beta but hopefully it will work with
the A6.5 versions.

If not you will have to wait until somebody kind hearted enough does a compatable version.

Good luck.
Posted By: Helghast

Re: [contribution] Fog code C-Script version - 04/12/10 09:16

Originally Posted By: Nidhogg
Here is the C-Script version Fog C-Script version download , Only took me about 10 minutes.
I am using A7.840 Pro beta but hopefully it will work with
the A6.5 versions.

If not you will have to wait until somebody kind hearted enough does a compatable version.

Good luck.


Damn, you beat me to it! xD I was gonna do that tonight tongue hahahhaa.
Good thing my contribution sparks so much interest tho!
I'll host your version on my webspace when i get home if you dont mind laugh

regards,
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/12/10 10:28

np! Helghast glad I was able to help out.
Posted By: MPQ

Re: [contribution] Fog code C-Script version - 04/12/10 13:47

wow the fog looks really great! espacially the hq version
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 16:08

i tried to get it working. i got an error, empty function non existing function: random_seed(); thats in the main of the fog.wdl.

edit: ok, i changed it to random(); and it worked, but its doesnt look like the examples. i am going to play around with some settings.
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 16:17

there are these huge blobs of speckled black dust floating around, and the framerate is awful. i am lost.

ok, reduced a couple of settings to clear some fog, to get framerate back, worked fine, but the dust particles that are shown in the original emre sample are just blurs, thats what thoses"speckled blobs" were. i amn alos getting an error saying "no level" on auto fog and pos_place.
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/12/10 16:33

@Blink, For your version you needed to change random_seed(0) to randomize().

Don't know if that will help with your framerate or not though.
Also there maybe a couple of other things that may not be compatable with your version. You may have to browse through the code and see if anything looks out of place.
It shouldn't take you long as there really isn't that much code to it. I wouldn't touch anything in the fog.fx though laugh
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 16:41

@Nidhogg, I added randomize in the main of a test level. I am still getting the "no level" on auto fog and pos_place error when the level runs. i guess i am just making things worse trying to modify it.
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 17:14

ok, i have officially turned a great contribution into a mess, I hope someone tests it and makes it work, i am just destroying it.
Posted By: Logitek

Re: [contribution] Fog code C-Script version - 04/12/10 17:19

Hello,

I have tried it also for C-Script and there is no problem.
7.80 Com.

How old is your graphic card?
Maybe the shader is the problem for you?

Have you tried to compile the level in WED again?

The only one thing that is different to the Lite-C Version that i can see is: That the fps is much slower than with the 4 times faster Edition of Emre for Lite-C.

regards,

Logitek
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 17:50

are you using A7 to compile a A6 script? its not my graphics card, the shader would show at all if it was. i did compile the level in wed and no change.
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/12/10 18:04

@Blink, Have a go with the A7 trial if that works than I reckon it's time you bit the bullet and update to A7. You can still use C-Script with A7 as I know that's what you are familure with.
Posted By: Logitek

Re: [contribution] Fog code C-Script version - 04/12/10 18:13

Hello,

yes. I scripting the most time in C-Script.

I donīt know A6. I have A7 Com. And in some days the Pro.

It works with A7.

In C-Script it is much slower. You have to reduce the ent_create procedure. And you must also change the (while) instruction. Otherwise it would create endless functions.

I have changed it. And it works. But I like the Lite-C Version more, because it is much faster.

I have changed some parameters.
Now I have 60 fps with a maxfog value of 80 with C-Script.
I am sure it is possible to speed it up more, but I am not really interessted in it at the moment.

regards,

Logitek.
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/12/10 18:21

@Logitek, Could you please post your changes for others to see.
It would be a great help to them.

I also use Lite-c I mainly converted the code to C-Script to give those users
something benificial. Sorry for the couple of mistakes.

But yeah it ran ok on my machine.
Posted By: Logitek

Re: [contribution] Fog code C-Script version - 04/12/10 18:38

Hello,

okay, no problem. I am sure the code can be optimized.

But here are the first changings that I have made.

First you can make it fullscreen if you wish with:

In main.wdl under var v_DepotMore:

var video_mode = 9; (or 8) (I have a widescreen).
var video_screen = 1; (Full screen).

So you can see the effects better.

There are no changes in the shader.

Now open fog.wdl.

5: Line
Replace define mag_fog,100; into ...
define mag_fog, 10; (Donīt know if you really need it. I have tried some things)

44: Line

Replace wait(-5 + ....
with wait(-8 + ....

52: Line

Replace var fog_speed = 20;
If you wish.
If you do it, then the code is faster: Reduce it and try it.
I have also tried 1 instead of 20. But you must try this.

81: Line

Replace 5,8 with 2 (It will be faster with it) You have to try it.

88: Line

Replace my.Translucent (Lite-C syntax)
with my.transparent

Line 115:
And now the problem with the C-Script: It generates endless functions without changes and slows down until 3 fps or something like that.

First make a new variable under the line var fogcount.

Like: var max_fogus = 80; (The name is not important)

Replace the line:
while(fogcount > 0 || fogcount < max_fog)

with
while(fogcount < max_fogus)


I am sure, you can make the code better. I have tried it only a few minutes.

regards,

Logitek
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 20:15

@logitek, i made your changes and it works better and the framrate is good. but because i added it to another level, i am now getting that no level error in generate_fog.
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/12/10 20:29

fixed the problem, i placed the camera clip, fog color, etc. in the wrong place, i was supposed to put it below the level_load. it works great now.
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/13/10 01:10

Ok I have uploaded a new version that include comments as to where changes can be made.
Fog C-Script version

Still coded for A7 but I commented where changes need to be made for A6 users. (Only two changes need to be made.)

I had it running for around 20 minutes with no problems.
framerate was steady at 60 and that's with 50 entities.

After configuring my Graphics Driver proper I thought i'd recheck the framerate.
It now states an average of around 400fps with a max of around 750fps using the C-Script version.

All the best to you all.


Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/13/10 14:20

it works ok, but the debris in the shader is blurry, not as clear as the examples.
Posted By: Nidhogg

Re: [contribution] Fog code C-Script version - 04/13/10 15:44

Well change the scale then of them then. But it will slow it down though.
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/13/10 16:02

ok, i will give it a shot.
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/14/10 00:51

well, i tried the fog on all of my levels for my project, and i am getting different results. i will have to mosify for each level or abandon the fog all together.
Posted By: Helghast

Re: [contribution] Fog code C-Script version - 04/14/10 07:47

Originally Posted By: Blink
well, i tried the fog on all of my levels for my project, and i am getting different results. i will have to mosify for each level or abandon the fog all together.


Or use the none shader variant tongue
Posted By: Blink

Re: [contribution] Fog code C-Script version - 04/14/10 13:46

but the shader is so cool. i love the fog, its a little too much on some of my levels, but when i modify, it should be ok. messes with the framerate when i modify sometimes.
Posted By: Anonymous

Re: [contribution] Fog code C-Script version - 11/06/10 20:15

can someone upload the C-Script version of the Fog again please?
Many THanks!
Edit: or better, just write the wdl code here in the forum!
Posted By: 3run

Re: [contribution] Fog code C-Script version - 08/18/11 07:54

Chris do you still need this one?
Posted By: Helghast

Re: [contribution] Fog code C-Script version - 08/18/11 14:54

I came across this WDL the other day on a backup disk.
Here it is to anyone interested in the old code;

Code:
DEFINE max_alpha, SKILL1;

var cam_fog = 1800;
var wind[3];

function set_alpha
{
	my.alpha=0;
	wait(1);
	my.max_alpha = INT(random(25));
	if(my.max_alpha < 10){ my.max_alpha = 15; }
	while(my.alpha < my.max_alpha)
	{
		my.alpha += 0.5*time;
		wait(1);
	}
	my.alpha = my.max_alpha;
}

function fog_wind
{
	while(1)
	{
		wind.x = (random(1) - .5)*1.5;//*.4;
		wind.y = (random(1) - .5)*1.5;//*.4;
		wind.z = random(1)*.4;//*.1;
		sleep(5+random(3));
	}
}

function move_fog
{
	var roll_speed;
	var fade_distance = 500;
	
	roll_speed = random(2)-1; 
	
	while(me)
	{
		my.roll += roll_speed*time; //roll this sprite
		
		my.x += random(20)*wind.x*time;
		my.y += random(20)*wind.y*time;
		
		if(vec_dist(my.x, camera.x) < fade_distance) 
		{
			my.alpha = min(my.max_alpha,  vec_dist(camera.x, my.x) *my.max_alpha / fade_distance);
		}
		
		wait(1);
	}
}

function autofog
{
	my.scale_x = 2.8;
	my.scale_y = my.scale_x;
	my.scale_z = my.scale_x;
	
	var cam_pos[3];
	var randint;
	
	my.passable = on;
	my.transparent = on;
	my.bright = on;
	
	//fade in slowly
	set_alpha();

   //set orientation style
	my.oriented = off;
	my.facing = on;
	
	move_fog();
	
	while(me)
	{
		if(my.alpha < my.max_alpha) { my.alpha += time; }
	//	my.invisible = off;
		vec_set(cam_pos, camera.x);
		cam_pos.z = my.z;
		
		if(vec_dist(my.x, cam_pos) >= cam_fog)
		{
		//	my.invisible = on;
			while(my.alpha > 0) { my.alpha -= time; wait(1); }
			
			my.x = cycle(my.x, camera.x - cam_fog, camera.x + cam_fog);
			my.y = cycle(my.y, camera.y - cam_fog, camera.y + cam_fog);
			my.z = camera.z - random(100) + random (200);
		}
		
		wait(5);
	}
}

function generate_fog
{
	var randint;
	var fogcount=0;
	
	var pos_place[3];
	fog_wind();
	
	while(fogcount < 250)
	{
		fogcount+=1;
		
		pos_place.x = (camera.x - random(2500)) + (camera.x + random (2500));
		pos_place.y = (camera.y - random(2500)) + (camera.y + random (2500));
		pos_place.z = camera.z - random(100) + random (200);
		
		randint = INT(Random(2));
		if(randint == 0){ ent_create("dust1.tga", pos_place, autofog); }
		if(randint == 1){ ent_create("dust2.tga", pos_place, autofog); }
	//	wait(1);
	}
}



All you need to do is call generate_fog() in your main function, and done!

regards,
Posted By: Blink

Re: [contribution] Fog code C-Script version - 08/18/11 16:05

This is a great code, guys! Thanks again for it, Dennis.
Posted By: DAVIDMORETON

Re: [contribution] Fog code Lite-C - 12/04/13 12:27

Hello Helghast,
Did you find the old c-script data for fog following the player?
I am working in c-script as most of the game is in c-script(over the years!)
If you have it, I would be most grateful for a copy.
David
JUST FOUND THE CODE ABOVE-DON'T KNOW HOW I MISSED IT !!

david@davidmoreton1.wanadoo.co.uk
Posted By: DLively

Re: [contribution] Fog code Lite-C - 01/18/14 20:03

So I went to the first Page of this thread and just downloaded the Lite-C version not knowing there was already a C-Script version on this page.. Whatever. I converted it back to C-Script laugh. It now looks as good as it should with the newer updated Lite-C version. I couldn't tell you for sure cause I don't program with it ^_^ Here is the code.

Edit: I also wanted to mention the FPS is great, on my low end staples pc.. Never tested it on my good pc yet wink

Code:
define max_alpha, skill1;
define max_fog, 250;

var cam_fog = 500; // needs to be a variable so it can get closer and further away to the camera as needed
var wind[3];

function set_alpha() 
{
	var fade_speed = 0.5;
	// fade model in
	my.alpha=0;
	my.max_alpha = integer(random(30));
	if(my.max_alpha < 10){ my.max_alpha = 15; }
	
	while(my.alpha < my.max_alpha)
	{
		my.alpha += fade_speed*time_step;
		wait(1);
	}
	my.alpha = my.max_alpha;
}

function fog_wind()
{
	while(1)
	{
		// new wind direction...
		vec_set(wind.x, vector((random(0.5) - .25)*1.5, (random(0.5) - .25)*1.5, random(1)*.4));
		//wait(-1 + random(3));
		wait(1);
	}
}

function move_fog()
{
	var roll_speed;
	var fade_distance;
	fade_distance = cam_fog+(cam_fog/7);
	var fog_speed = 20;
	
	roll_speed = random(2)-1; 
	
	while(me)
	{
		my.roll += roll_speed*time_step; //roll this sprite
		
		// update position globally
		c_move(my, nullvector, vector(random(fog_speed)*wind.x*time_step, random(fog_speed)*wind.y*time_step, 0), IGNORE_PASSABLE);
		
		// fade sprite when close to camera
		if(vec_dist(my.x, camera.x) < fade_distance) 
		{
			my.alpha = minv(my.max_alpha, vec_dist(camera.x, my.x) * my.max_alpha / fade_distance);
		}
		
		wait(1);
	}
}

function autofog()
{
	var cam_pos[3];
	var randint;
	
	vec_scale(my.scale_x, 0.8);
	my.passable = on;
	my.transparent = on;
	//fade in slowly
	set_alpha();
	move_fog();
	
	while(me)
	{
		if(my.alpha < my.max_alpha) { my.alpha += time_step; }
		
		vec_set(cam_pos, camera.x);
		cam_pos.z = my.z;
		
		if(vec_dist(my.x, cam_pos) >= cam_fog)
		{
			// fade the fog out
			while(my.alpha > 0) { my.alpha -= time_step; wait(1); }
			
			// set on new position at edge of fog distance
			vec_set(my.x, vector(cycle(my.x, camera.x - cam_fog, camera.x + cam_fog), cycle(my.y, camera.y - cam_fog, camera.y + cam_fog), camera.z - random(100) + random (200)));
		}
		
		wait(5);
	}
}

var fogcount;
function generate_fog()
{
	var randint; // random fog sprite
	
	var pos_place[3];
	
	fog_wind(); // sets a random fog position every so often
	
	if(fogcount<250)
	{
		// set random position around camera
		vec_set(pos_place.x, vector(((camera.x - random(cam_fog)) + (camera.x + random(cam_fog))), ((camera.y - random(cam_fog)) + (camera.y + random(cam_fog))), ((camera.z - random(cam_fog/8)) + random(cam_fog/4))));
//		vec_set(pos_place.x, nullvector);
		
		// get a random number
		randint = integer(random(2));
		// create different fog, based on random number
		if(randint == 0){you=ent_create("Dust_1.tga", pos_place, autofog);you.passable = on;}
		if(randint == 1){you=ent_create("Dust_2.tga", pos_place, autofog);you.passable = on;}
		fogcount += 1;
	}
	else{return;}
}


And in the function main()
Code:
function main(){
...
while(1){wait(1);
if(fogcount<250){generate_fog();}
}
}



If anyone could help make it better so that it doesn't update so slowly, that would be cool. I find that when my player moves away it doesn't update around him fast enough.
© 2024 lite-C Forums