Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Newbie Questions
by AndrewAMD. 12/04/23 11:14
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (TipmyPip, izorro), 556 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Light beams and dust effects #54651
09/11/05 01:27
09/11/05 01:27
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
I've been working in some visible light effects.
You can see these in action in my Cathedral Level in this Showcase thread.

The scripts are relatively simple.

The lightbeamFX is suppossed to be used with an image of lightbeams, going tru a window. The script basically fades the sprite away when the camera gets close to its PLANE, thus making the effect more subtle and real than just allowing the camera to break tru the sprites.
This can be controled by the fade_distance skill, which is how close the camera is for the sprite start fading. if you don't want it to fade, set this to 0.

The lightdustFX is suppossed to be applied to cloud-like images, which should be aligned to match the light entering tru a window. (Or around a lava pit, or wherever you want them).
It sets the sprites to face the camera by default. It fades the sprites away when the camera gets closer, and it also adds a very slow time-based rolling to these clouds, to give the very subtle dust-twirling effect.
The fade_distance skill works the same as lightbeam. Additionally you can set a positive or negative roll speed. If you leave it as zero, the script will assign a random value (very slow, CW or CWW).

Here is the script:

Code:

//light effects (c) 2005 Emilio Le Roux
//Free for personal or commercial use



//used by lightbeam and lightdust effects
DEFINE max_alpha, SKILL1;
DEFINE fade_distance, SKILL2;
DEFINE face_camera, flag1;
DEFINE pan_only, flag2;
DEFINE roll_speed,SKILL3;


/////////////////////////////////////////
// LIGHTBEAM FX

// Add this behavior to a light beams TGA image. No alpha channel needed.

// uses max_alpha,fade_distance,face_camera,pan_only
// skill1: max_alpha 25.0
// skill2: fade_distance 500.0
// flag1: face_camera 0
// flag2: pan_only 0
ACTION lightbeamFX
{

me.alpha=me.max_alpha;
me.bright=on;
me.transparent=on;
me.passable = on;
//user should set ambiance and other desired flags/values in WED

//set orientation style
if (me.face_camera)
{
my.oriented = off;
if (me.pan_only)
{
my.facing = off;
}
else
{
my.facing = on;
}
}
else
{
my.oriented = on;
my.facing = off;
}

var vnormal[3];
var fadefactor;

while (1)
{

if (me.fade_distance > 0)
{

//calculate sprite normal after its angle
vec_for_angle(vnormal,me.pan);


//calculate distance from camera to plane of the sprite (dot product)
fadefactor = vec_dot( vnormal.x, Vector(camera.x-me.x,camera.y-me.y,camera.z-me.z));

//convert the distance to a fade factor
fadefactor = min( abs(fadefactor) * me.max_alpha / me.fade_distance, me.max_alpha);

me.alpha = fadefactor; //set transparency
}

wait(1); //(could be wait(more) for speed?
}

}



/////////////////////////////////////////
// LIGHTDUST FX

// Add this behavior to several cloud-like TGA images. No alpha channel needed.

// uses max_alpha,fade_distance,face_camera,pan_only,roll_speed
// skill1: max_alpha 25.0
// skill2: fade_distance 500.0
// skill3: roll_speed 0.0
// flag1: face_camera 1
// flag2: pan_only 0
ACTION lightdustFX
{
my.passable = on;
me.transparent = on;
me.bright = on;

me.alpha = me.max_alpha;


//set orientation style
if (me.face_camera)
{
my.oriented = off;
if (me.pan_only)
{
my.facing = off;
}
else
{
my.facing = on;
}
}
else
{
my.oriented = on;
my.facing = off;
}


if (me.roll_speed == 0)
{

// set roll speed for this sprite to a very low pos/neg value
me.roll_speed = random(2)-1;
}


while(1)
{
me.roll += me.roll_speed*time; //roll this sprite

if (me.fade_distance>0)
{
//fade this sprite from max_alpha to zero, as it comes close to camera by fade_distance value.
me.alpha = min (me.max_alpha, vec_dist(camera.x,me.x) *me.max_alpha / me.fade_distance);
}

wait(1); //could wait more?
}
}




In both actions, the max_alpha skill defines the maximum opacity. I recommend values from 10 to 25. You have to be careful, since the sprites ADD to the background, so too many stacked sprites with a high alpha value will shine too much.

Emilio

Re: Light beams and dust effects [Re: eleroux] #54652
09/11/05 03:19
09/11/05 03:19
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline
Expert
XNASorcerer  Offline
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Thanks!!!

Re: Light beams and dust effects [Re: XNASorcerer] #54653
09/11/05 05:22
09/11/05 05:22
Joined: Oct 2003
Posts: 206
N
nkl Offline
Member
nkl  Offline
Member
N

Joined: Oct 2003
Posts: 206
Your screen shot is very nice.
But how do I use your code?
Would you mind to provide a level that how to use your code?
Thanks already

Re: Light beams and dust effects [Re: nkl] #54654
09/11/05 05:33
09/11/05 05:33
Joined: Jul 2002
Posts: 5,181
Austria
Blattsalat Offline
Senior Expert
Blattsalat  Offline
Senior Expert

Joined: Jul 2002
Posts: 5,181
Austria
i was always afraid to create such effects because they combine two very bad things for an engine: alpha transparence and frequent to player tracing ...though times change

thanks for the script and very nice level you got there!
i especially like how you cared about the lightning a lot. The front looks excellent from the outside.


how to use: he wrote it above...."Add this behavior to several cloud-like TGA images. No alpha channel needed."

cheers


Models, Textures and Levels at:
http://www.blattsalat.com/
portfolio:
http://showcase.blattsalat.com/
Re: Light beams and dust effects [Re: Blattsalat] #54655
09/11/05 06:03
09/11/05 06:03
Joined: Jul 2005
Posts: 366
eleroux Offline OP
Senior Member
eleroux  Offline OP
Senior Member

Joined: Jul 2005
Posts: 366
It's easy to use.



Here is an image I use for light beams:


Just position the image in the level and apply the LightbeamFX to it.

And two of the images I use for dust:




Assign the LightdustFX to them and position several copies as a cluster of dust or smoke. For instance, you can distribute loosely some 8 to 12 of them along a light beam.

Don't forget to convert these images to TGA first.

As a complement, I'll say this code doesn't include (the dreaded?) alpha channel transparency, nor any kind of tracing. The methods used here are very fast. The distance to plane for the beams and distance to sprite for the dust are simple and quick math.

We don't need alpha channels because we are using the BRIGHT flag, which adds the image to the background. This means that the darker areas won't show.

Re: Light beams and dust effects [Re: eleroux] #54656
09/11/05 06:49
09/11/05 06:49
Joined: Jul 2002
Posts: 5,181
Austria
Blattsalat Offline
Senior Expert
Blattsalat  Offline
Senior Expert

Joined: Jul 2002
Posts: 5,181
Austria
there is no difference between tracing and vector calculations, because you will ignore anything unneeded from the trace anyway

anything with none solid texels is not good for a fast game. If you have to sort things its worse but no matter if transparent or the overlay bright flag, they can hit the framrate very bad. Worst are big and lots of tga sprites fast loaded and displayed (explosions) or lots of semi transparence in a row.

but thats way to off topic.
But some connection would be some sort of trigger that turns the dust effect on and off (independent from the cliprange). So instead of trac....well, "vecotoring" for all dustmaps whenever they get loaded into the cliprange. It might be an idea to just check some "activation" point in the middle of the dust area and whenever you can close enough to it the particle effects will be turned on or vica verse turned off.

It might be no biggy for 4 dust effects but imagine having 2000 of them all over the place....a 4th (500) is still a lot less then 2000

cheers and sorry for going off topic to much


Models, Textures and Levels at:
http://www.blattsalat.com/
portfolio:
http://showcase.blattsalat.com/
Re: Light beams and dust effects [Re: eleroux] #54657
09/11/05 06:50
09/11/05 06:50
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Fantastic looking and easy to insert effect! Thanks for both: the script and the walkthrough!

Re: Light beams and dust effects [Re: Pappenheimer] #54658
09/12/05 07:25
09/12/05 07:25
Joined: Apr 2005
Posts: 3,815
Finland
Inestical Offline
Rabbit Developer
Inestical  Offline
Rabbit Developer

Joined: Apr 2005
Posts: 3,815
Finland
omg! I NEED IT,,but i'm at school and dementic :/ (I know! I add reminder in my mobile ^^ )


"Yesterday was once today's tomorrow."
Re: Light beams and dust effects [Re: eleroux] #54659
09/12/05 07:59
09/12/05 07:59
Joined: Mar 2005
Posts: 969
ch
Loopix Offline
User
Loopix  Offline
User

Joined: Mar 2005
Posts: 969
ch
Thanks eleroux for sharing your scripts! It makes it easy for noobs -like me- to implement nice effects for an awesome atmosphere. Great contribution, 5 stars because you obeyed my request!

Re: Light beams and dust effects [Re: Loopix] #54660
09/14/05 15:18
09/14/05 15:18
Joined: May 2005
Posts: 819
U.S.
Why_Do_I_Die Offline
Warned
Why_Do_I_Die  Offline
Warned

Joined: May 2005
Posts: 819
U.S.
Thnx a lot , the demo looked amazing.

Page 1 of 2 1 2

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1