Game Development Community

dev|Pro Game Development Curriculum

fxLight (Dynamic Light with Flare)

by Melv May · 05/13/2002 (10:52 am) · 51 comments

Download Code File

Hi People,

I started messing with the lighting system yesterday and thought it was a good idea to cut my teeth on a real object using it ... and here it is for you nice folks. :)

It's a light that you can place anywhere in the scene using the editor. It provides a nice little billboard icon so that you can identify it easily.

Ok, so what can it do?

Well, you can do the most basic thing and have it as a static light. Move it around your scene and the light moves with it. You can control all the settings on the fly without restarting.

The basic settings are colour, brightness, radius and an on/off switch.

Now for the fun bit! You can get the light to do some pretty sophisticated animation to produce all sorts of useful effects from simple flashing lights to even moving runways lights. Perhaps even lights whizzing up the sides of buildings, whatever your imagination!

Things you can animate are colours (individual rgb channels if you require), brightness, radius and positional offsets. You can set animation times against a key-frame animation system using alpha-strings as the animation control e.g something like 'ABZAB'.

You will find that you can attach the fxLightDB to any GameBase object. I give you an example of how to attach this thing to a projectile to give you lens flares on your weapon projectiles.

Anyway, full instructions are in the attached file so give it a go and let me know if you have any problems.

Enjoy.



There have been many updates since this original resource post so you may want to read: www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=5291 & www.garagegames.com/index.php?sec=mg&mod=forums&page=result.thread&qt=5042.

The 'light.zip' file on the GG site contains both the original 'fxlight' and the 'fxlightDB' (Datablock) versions.

You can also find this file @ www.melv.may.btinternet.co.uk/garagegames/light.zip

You can find a demo terrain/mission file @ www.melv.may.btinternet.co.uk/garagegames/disco.zip

- Melv.

EDIT: 13/5/2002 - "Misc Changes"

EDIT: 19/5/2002 - "Misc Changes"

EDIT: 19/05/02 - "Fixed attachment to object problem"

EDIT: 20/05/02 - "Added the facility to animate the rotation of the flare. Added a much more intuitive method to control the flare size/distance ratio"

EDIT: 20/05/02 - "Added an ability to turn off the flares in the third-person view"

EDIT: 23/05/02 - "Now works correctly in 3rd person view e.g player shape occludes flares."

EDIT: 24/05/02 - "Now has the ability to act like a distant sun that you can never reach with Azimuth/Elevation settings".

EDIT: 25/05/02 - "All configuration commands added"

EDIT: 28/05/02 - "Resolved problem with attachment to other GameBase Objects"

EDIT: 30/08/02 - "Removed the ability to act like a sunlight. Created another resource fxSunLight to do this better"

EDIT: 01/02/03 - "Moved hosting web-site."

- Melv.
Page «Previous 1 2 3 Last »
#1
05/13/2002 (10:36 pm)
Can you make spot lights with this?
#2
05/13/2002 (10:50 pm)
Hi Joseph,

There seems to be some problems with the way Torque handles the SpotLight case so I'm looking at this right now.

If you follow the forum-link there is a more comprehensive explanation I think.

All the best,

- Melv.
#3
05/14/2002 (11:09 pm)
Thanks Melv, I will look into that. Let us know what you figure out about the spot lights as they will be very useful to me in my current project, as I am sure others will be highly interested also. Great work on the lights btw.

Joe
#4
05/18/2002 (5:35 pm)
I have made serious modifications to this object. There is now a much better system in place to control the object plus a highly configrable flare system with LOS testing etc.

My personal hosting link file contains a bonus terrain/mission file whereas the GarageGames link does not due to filesize restrictions.

Have Fun.

- Melv.
#5
05/19/2002 (12:29 am)
Cool Man. It's awesome!!!! Two thumbs up!
#6
05/19/2002 (12:23 pm)
I have updated this object. There was a problem attaching the fxLightDB object to other objects. It should now track any GameBase type object *without* sending any data over the wire. :)

- Melv.
#7
05/20/2002 (11:57 pm)
I've made further amendments upon requests to this object.
#8
05/23/2002 (1:13 pm)
Everyone,

I've just updated it to include the ability to be occluded by the player shape in third-person view (I couldn't wait until the weekend to do this).

I'm not really up on the collision code itself but I think that it's just a bounding-box collision on the player (but I could be wrong) so you don't exactly get pixel perfect occlusion.

- Melv.
#9
05/24/2002 (2:46 pm)
Everyone,

I've just update it to include the ability to act like a distant, non-reachable Sun.

The new fields are explained in the attached files but for your information they are:-

[SunLight] - Turns the thing on/off
[SunAzimuth] - Polar Z-Axis angle of sun.
[SunElevation] - Height in sky from the ground-plane (angle).

The file on my site contains an updated version of a mission with two fxlights configured as suns. Yep, don't forget that you can have multiple layers to the sun by simply configuring multiple fxlights.

My next and hopefully final task is to add in all the console/script static control functions so that it can be configured in realtime.

Enjoy.

- Melv.
#10
05/25/2002 (7:46 am)
Everyone,

Before I begin, I got up early this morning so that I could get this thing finished like I promised. I'm going out boozing tonight and I didn't want to do it on Sunday with a hangover!

I've added *all* the configuration commands for C++ / Script that I said I would.

There is a problem, which I need to sort out, in that attachment no longer works and may cause it to bomb! I will sort that out on Sunday.

Anyway, here are the new commands:-

// *********************************
// Script entries ....
// *********************************

// Light.
fxobj.setEnable(status)
fxobj.setLightOn(status)
fxobj.setRadius(radius)
fxobj.setBrightness(brightness)
fxobj.setColour(r,g,b)

// Sunlight.
fxobj.setSunLightOn(status)
fxobj.setSunAzimuth(azimuth)
fxobj.setSunElevation(elevation)

// Flare.
fxobj.setFlareOn(status)
fxobj.setFlareTP(status)
fxobj.setFlareBitmap(bitmap)
fxobj.setColour(r,g,b)
fxobj.setConstantSizeOn(status)
fxobj.setConstantSize(size)
fxobj.setNearSize(size)
fxobj.setFarSize(size)
fxobj.setNearDistance(distance)
fxobj.setFarDistance(distance)
fxobj.setFadeTime(time)
fxobj.setBlendMode(mode)
fxobj.setLinkFlare(status)
fxobj.setLinkFlareSize(status)

// Animation.
fxobj.setMinColour(r,g,b)
fxobj.setMaxColour(r,g,b)
fxobj.setMinBrightness(brightness)
fxobj.setMaxBrightness(brightness)
fxobj.setMinRadius(radius)
fxobj.setMaxRadius(radius)
fxobj.setStartOffset(x,y,z)
fxobj.setEndOffset(x,y,z)
fxobj.setMinRotation(rotation)
fxobj.setMaxRotation(rotation)
fxobj.setSingleColourKeys(status)
fxobj.setRedKeys(keys)
fxobj.setGreenKeys(keys)
fxobj.setBlueKeys(keys)
fxobj.setBrightnessKeys(keys)
fxobj.setRadiusKeys(keys)
fxobj.setOffsetKeys(keys)
fxobj.setRotationKeys(keys)
fxobj.setColourTime(time)
fxobj.setBrightnessTime(time)
fxobj.setRadiusTime(time)
fxobj.setOffsetTime(time)
fxobj.setRotationTime(time)
fxobj.setLerpColour(status)
fxobj.setLerpBrightness(status)
fxobj.setLerpRadius(status)
fxobj.setLerpOffset(status)
fxobj.setLerpRotation(status)
fxobj.setUseColour(status)
fxobj.setUseBrightness(status)
fxobj.setUseRadius(status)
fxobj.setUseOffsets(status)
fxobj.setUseRotation(status)

// Misc.
fxobj.reset()
fxobj.attachToObject(object)
fxobj.detachFromObject(object)

// *********************************
// C++ entries ....
// *********************************

// Light.
void setEnable(bool Status);
void setLightOn(bool Status);
void setRadius(F32 Radius);
void setBrightness(F32 Brightness);
void setColour(ColorF Colour);

// Sunlight.
void setSunLightOn(bool Status);
void setSunAzimuth(F32 Azimuth);
void setSunElevation(F32 Elevation);

// Flare.
void setFlareOn(bool Status);
void setFlareTP(bool Status);
void setFlareBitmap(const char* Name);
void setFlareColour(ColorF Colour);
void setConstantSizeOn(bool Status);
void setConstantSize(F32 Size);
void setNearSize(F32 Size);
void setFarSize(F32 Size);
void setNearDistance(F32 Distance);
void setFarDistance(F32 Distance);
void setFadeTime(F32 Time);
void setBlendMode(U32 Mode);
void setLinkFlare(bool Status);
void setLinkFlareSize(bool Status);

// Animation.
void setMinColour(ColorF Colour);
void setMaxColour(ColorF Colour);
void setMinBrightness(F32 Brightness);
void setMaxBrightness(F32 Brightness);
void setMinRadius(F32 Radius);
void setMaxRadius(F32 Radius);
void setStartOffset(Point3F Offset);
void setEndOffset(Point3F Offset);
void setMinRotation(F32 Rotation);
void setMaxRotation(F32 Rotation);
void setSingleColourKeys(bool Status);
void setRedKeys(const char* Keys);
void setGreenKeys(const char* Keys);
void setBlueKeys(const char* Keys);
void setBrightnessKeys(const char* Keys);
void setRadiusKeys(const char* Keys);
void setOffsetKeys(const char* Keys);
void setRotationKeys(const char* Keys);
void setColourTime(F32 Time);
void setBrightnessTime(F32 Time);
void setRadiusTime(F32 Time);
void setOffsetTime(F32 Time);
void setRotationTime(F32 Time);
void setLerpColour(bool Status);
void setLerpBrightness(bool Status);
void setLerpRadius(bool Status);
void setLerpOffset(bool Status);
void setLerpRotation(bool Status);
void setUseColour(bool Status);
void setUseBrightness(bool Status);
void setUseRadius(bool Status);
void setUseOffsets(bool Status);
void setUseRotation(bool Status);

// Misc,
void reset(void);
void attachToObject(const char* ObjectName);
void detachFromObject(void);


Sorry for the attachement thing but I just ran out of time today.

Enjoy!

- Melv.
#12
06/07/2002 (9:59 pm)
Very very nice effect. One thing I did want to add because I am not a programmer by nature is the fact that I did struggle to get the editor back up and running after installing this plugin.
For people like me who are trying to modify the engine without much programing experience, the instructions state:
- Put this in "/example/common/editor/EditorGui.cs" in [function Creator::init( %this )]
   %Environment_Item[<next item-index in list>] = "fxLight";  <-- ADD THIS.
Or for the FxLightDB
- Put this in "/example/common/editor/EditorGui.cs" in [function Creator::init( %this )]
   %Environment_Item[<next item-index in list>] = "fxLightDB";  <-- ADD THIS.
When using stock or close to stock code look for this part:
%Environment_Item[0] = "Sky";
   %Environment_Item[1] = "Sun";
   %Environment_Item[2] = "Lightning";
   %Environment_Item[3] = "Water";
   %Environment_Item[4] = "Terrain";
   %Environment_Item[5] = "AudioEmitter";
   %Environment_Item[6] = "Precipitation";
   %Environment_Item[7] = "ParticleEmitter";
Add this after:
%Environment_Item[8] = "fxLight";////added for lighting improvement
   %Environment_Item[9] = "fxLightDB";////added for lighting improvement
You could search through the almost endless thread and figure this out but this might help someone get on the road a little faster.
Thanks Melv for this great upgrade
#13
06/08/2002 (3:31 am)
Glad you find it useful Matthew.

With regards to the instructions, I must admit that I do them as an after-thought, normally when I'm excited at getting the work out after it's finally finished and I accept that it could be done better. ;)

Sometimes though, the instructions for inclusions of code within the existing C++/Script codebase can be difficult as you never know exact line numbers of code and, in the case of the %Environment_Item[x] stuff, you don't know what else the person has installed. This was the reason I didn't want to be explicit about the index numbers as others have many of these already used so I wanted it to be as abstract as possible.

As a side note, I want to start doing instructions in HTML as well as create a web-page to present these in a more accessable fashion.

Thanks for the advice though. 8)

- Melv.
#14
08/15/2002 (8:25 am)
If I place a light in my map outside of a building (dts interior), should the light seep into the building or not? I added a light to the outside wall of a building, but the light seems to be affecting the interior as well.
#15
08/15/2002 (9:10 am)
That's what lighting does as standard. Any faces that are facing and within the lights effective radius will be lit. This is not done by me or by the engine but rather OpenGL/DirectX.

Lights are not ray-traced and do not analyse the geometry for occlusion. Without using various other techniques you will always get this.

Typically the map can be designed in such a way so that you don't see this.

With that said, the lighting and rendering pipeline really needs a lot more work doing to it.

- Melv.
#16
08/30/2002 (11:14 am)
Okay,

I've removed the ability to act light a sun from this resource and have just submitted a new resource "fxSunLight".

I did this because having the single object act in two different ways was causing problems.

I've also fixed-up some problems that I have been meaning to sort out for ages!

Enjoy,

- Melv.
#17
09/11/2002 (12:58 am)
For some reason I cannot seem to get fxLightDB datablocks put into the game. It doesn't matter where I put the example one you put in the zipfile in like newobjects.cs of example/newobjects.cs or place it in it's own .cs file like fxlightdbs.cs and of course link it in init.cs of /example/fps/client/

It all compiles fine, but when I attemp to create a new fxLightDB object, the datablock list is empty!
#18
09/11/2002 (7:17 am)
Nathan,

Before we start, can you manage to do what you are doing with other script objects?

- Melv.
#19
09/11/2002 (1:54 pm)
I guess not, where am I suppose to do the datablocks then? This is confusing!
#20
09/13/2002 (10:04 am)
Melv,
Not sure if this is related to Nathans question, but I get a "Could not get game connection!!!" message when I'm in a networked game using a fxLightDB attached to a projectile. It works fine on a single server game. I'm currently using the most up to date version before the grouping one that you made. I have the example from the DrinkMe fxLightDB in there now just to try it out. The engine is based on the Stable 1.1.2 release. Does the attached fxLightDB on projectiles work for you using a dedicated server with a client connection? I noticed on a previous post you said you haven't tried it on a dedicated server yet. BTW, it seems really cool from what I've seen so far using it on a single game.

Edit: It appears to have the same problem with networked games in general not just dedicated servers (for me at least).
Page «Previous 1 2 3 Last »