Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
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
6 registered members (Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn), 584 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dynamic light for a torch #58237
10/30/05 09:50
10/30/05 09:50
Joined: Aug 2004
Posts: 17
P
PaulHuckstepp Offline OP
Newbie
PaulHuckstepp  Offline OP
Newbie
P

Joined: Aug 2004
Posts: 17
I integrated a flashlight c-script from one of the AUM magazine articles but the effect isn't very good. The torch produces vertex based lighting which looks very angular.

Is there a better way of producing a torch? something that would be circular? perhaps some sort of shader or sprite trick?

Re: Dynamic light for a torch [Re: PaulHuckstepp] #58238
10/31/05 21:17
10/31/05 21:17
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
It is possible to use per-pixel-light via a shader, which is the best-looking way to display dynamic lights as far as I know (I'm really no expert when it comes to shaders :P - besides, what could look better anyway?)


I spent hours upon hours to search for this link. Yay


Last edited by Error014; 10/31/05 21:24.

Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: Dynamic light for a torch [Re: Error014] #58239
11/01/05 08:09
11/01/05 08:09
Joined: Aug 2004
Posts: 17
P
PaulHuckstepp Offline OP
Newbie
PaulHuckstepp  Offline OP
Newbie
P

Joined: Aug 2004
Posts: 17
Thanks for that.

I have managed to work out a sneaky way of using a panel instead which gives a much better quality light without shaders.

Seems to do the trick and looks like the same method that FEAR uses.

Re: Dynamic light for a torch [Re: PaulHuckstepp] #58240
11/01/05 11:08
11/01/05 11:08
Joined: Dec 2003
Posts: 401
Germany, Bonn
VampireLord Offline
Senior Member
VampireLord  Offline
Senior Member

Joined: Dec 2003
Posts: 401
Germany, Bonn
Hi Paul, would you care to share this method with the community?
This might help other people

Greetings
Sven


"Feathers shall raise men even as they do birds, toward heaven; that is by letter written with their quills." - Leonardo da Vinci

Wer mir eine e-mail schicken will ersetze ANTISPAM durch @
If you want to send me an email replace ANTISPAM by @
Re: Dynamic light for a torch [Re: VampireLord] #58241
11/02/05 11:58
11/02/05 11:58
Joined: Dec 2003
Posts: 1,220
Just down the road from Raven
BlueBeast Offline
Serious User
BlueBeast  Offline
Serious User

Joined: Dec 2003
Posts: 1,220
Just down the road from Raven
Yes! Please share!

Jason


Gamestudio Pro 6.4
Pentium 4 3.0 GHz 800MHz BUS
AtiRadeon 9800 pro 256Mb 21" Monitor
1 Gig DDR RAM
36 Gig RAPTOR SATA+ 120 Gig SATA
SB Audigy 2 w/ 450 watt Logitech Z680 5.1

www.nordicepitaph.com
Re: Dynamic light for a torch [Re: BlueBeast] #58242
11/02/05 18:51
11/02/05 18:51
Joined: Aug 2004
Posts: 17
P
PaulHuckstepp Offline OP
Newbie
PaulHuckstepp  Offline OP
Newbie
P

Joined: Aug 2004
Posts: 17
Heres how I put it together (screenshot link at bottom of post):

First you'll need to create a spot light image. I used Photoshop.

Create a new document at the size of the resolution your game is going to use (or various sizes for multi res).

Then ensure that the background is transparent. Make a circular selection in the middle of the document the size you want the spot light. Feather the selection so that it has a nice faded edge.

Select the contents of the spot light layer and create an alpha channel of the contents. To avoid the spot light from being extremely bright I then faded the alpha channel down 40% and added a weak spot with the black brush for the centre.

Save as a 32Bit alpha channeled Tga.

For the next bit you'll need an entity placed in WED somewhere.

In your script for the level add the following variable declarations and actions:

var torchEnergy=1000;
var gotFlashlight=0;
entity* lightBlob;

panel flashlight
{
pos_X =0; pos_Y=0;
bmap=<lightBeam.tga>; //load tga image
flags=d3d;
}
panel* flashLightEnt = flashLight; //assign panel to a pointer

action flashlight_control
{
while (player == null) {wait (1);}
//wait for pickup
while (vec_dist (player.y, my.y) > 150) {
wait (1);
}
gotFlashlight = 1; //player has now got the flashlight
my.invisible = on; //hide entity
my.passable = on;

//prepare the bmap panel
// the 302 is half the width of the lightspot image
var sx;
sx = (screen_size.x/2)-302;
// the 300 is half the height of the lightspot image
var sy;
sy = (screen_size.y/2)-300;

//position the image in the panel ready to show
flashLightEnt.pos_x = sx;
flashLightEnt.pos_y = sy;


var torchOn;

while (1)
{
if(key_f==1){ //has the F key been pressed?
while(key_f==1){wait(1);} //ensure the F Key has been released
if(torchOn==0){torchOn=1;}else{torchOn=0;}
}

while (torchEnergy > 0 && torchOn==1) // press the "F" key to use the flashlight
{
flashLightEnt.visible=on; //show the torch
torchEnergy -= 0.5 * time; //reduce battery power in torch
wait (1);
if(key_f==1){ //if the F key is pressed again break the loop
while(key_f==1){wait(1);}
break;
}
}
torchOn=0;
flashLightEnt.visible=off; //switch light off and wait for F key again
wait (1);
}
}

The battery for the torch uses the following action taken from an AUM issue:

action battery_pickup {
var battery=1000;
my.passable = on;
while (player == null) {wait (1);}
while (vec_dist (player.x, my.x) > 100) {wait (1);}
torchEnergy += battery;
ent_remove (me);
}


and thats about it. Assign the 'flashlight_control' action to your flashlight entity, then when testing pick it up and press F to switch it on and off.

You can see the implementation in a rough screen grab below:
http://www.arsoftware.co.uk/products/asylum/asylum9.jpg

Because this method uses a panel you may need to change the zOrders of your HUD elements to ensure they appear over the spot light, which I'm assuming is possible (I haven't got to that point of my game development yet). Also, theres no collision problems as its a 2D trick.

Hope it helps, have fun.


Paul Huckstepp

Last edited by PaulHuckstepp; 11/02/05 19:05.
Re: Dynamic light for a torch [Re: PaulHuckstepp] #58243
11/03/05 09:20
11/03/05 09:20
Joined: Oct 2002
Posts: 799
Germany->Bavaria->Nuremberg
C
Christian__A Offline
User
Christian__A  Offline
User
C

Joined: Oct 2002
Posts: 799
Germany->Bavaria->Nuremberg
Hi!
Would you show a screenshot of your method ?


MfG, Christian__A. Visit my Site: www.chris-a.de


Re: Dynamic light for a torch [Re: Christian__A] #58244
11/03/05 16:40
11/03/05 16:40

A
Anonymous
Unregistered
Anonymous
Unregistered
A



He already mentioned a link to a screenshot.

Re: Dynamic light for a torch #58245
11/06/05 17:33
11/06/05 17:33
Joined: Nov 2004
Posts: 595
127.0.0.1
K
KoH Offline
Developer
KoH  Offline
Developer
K

Joined: Nov 2004
Posts: 595
127.0.0.1
The panel you used in the screenshot looks a bit basic. However, this does look like a good method to use. The only problem would come when you entered a pitch black room.

Looks good anyway though.


I am no longer a member of these boards.
Re: Dynamic light for a torch [Re: KoH] #58246
11/06/05 20:13
11/06/05 20:13
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
From a mathematical point of view, think of it this way. When it's dark, use a panel that is black and have a high alpha for it. When using a flashlight, however, have black around the area where the light is minimal, but fully transparent in the area that isn't. This'll provide the greatest accuracy and realism. Black is subtractive of colors and the best for lighting.

If you used red (FF0000), and applied something 2/3 transparent (alpha of 170) of a black color, you'd see a very dark red (550000) instead*. If you used a transparent white color of the same alpha of 170 (2/3 transparent), you'd actually get a very light grayish red, or FFAAAA. Gamestudio uses white for lights which damages textures by washing them out. If Gamestudio used a lighting system where if lights were on something, it'd be full intensity as the texture was originally made, but if unlit, it'd be a highly subtractive black color. If partially lit, the texture would just be darkened. White, just being another shade of gray, will gray things out so avoid using a transparent white color as lighting.



Footnotes:
* I know this as I've studied color and found how to mix colors (in terms of light) mathematically. The formula for mixing colors is merely a compound average and rather simple:

MCOL = (COLA×RATA+COLB×RATB)÷(RATA+RATB)

This formula is used to calculate the resulting color. You apply it three times, one for red, then green, and blue after that. COLA and RATA refer to the first color, normally the background. COLB and RATB refer to the second color, the foreground color (normally transparent). You can add (and multiply) in any order, so it doesn't matter, but this is how I do it. Calculating a transparent color on a transparent color is a bit more tricky, but I have that formula as well (not fully tested though as it's newly figured out). This is sort of how the alpha channel's transparency works and the colors you get from that. RATA and RATB add up to 255 in this case. For an alpha of 170, RATB, the transparent color, would have 170. RATA, to make 255, has to be 85. COLA, your background behind the transparent color, is 255. COLB is 0. Working out the formula, you'll get 85 for red. If you used white, however, the color you get for red would still be 255, but green (where COLA was 0) becomes 170 (AA in hex) and the same goes for blue. Further details on this and all I know about colors are in the color system report on my site.


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials

Moderated by  HeelX, Spirit 

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