Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/06/23 11:29
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
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn), 581 guests, and 0 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 2 of 4 1 2 3 4
Re: for more then 8 (lightrange) lights [Re: laethyn] #106481
01/13/07 21:08
01/13/07 21:08
Joined: Aug 2005
Posts: 1,185
Ukraine
Lion_Ts Offline
Serious User
Lion_Ts  Offline
Serious User

Joined: Aug 2005
Posts: 1,185
Ukraine
Quote:

Oh never seen that code
its prety indentical to mine
didnt know that


nevermind
all new things are forgotten one (don't know it in english right, it's the russian/ukrainian proverb)

Re: for more then 8 (lightrange) lights [Re: A.Russell] #106482
01/14/07 12:37
01/14/07 12:37
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
Code:

//fade light
temp_distance = vec_dist (my.x, player.x);
r = my.skill2 - ((temp_distance - fade_start) / fade_end) * my.skill2;
g = my.skill3 - ((temp_distance - fade_start) / fade_end) * my.skill3;
b = my.skill4 - ((temp_distance - fade_start) / fade_end) * my.skill4;
if(my.skill2 < 1)
{
my.lightrange = 0;
}else
{
my.lightrange = my.skill1;
}



Maybe a stupid question, but how does the light fade?
I don't think that the value of my.skill2 is changing.
I have tried this in a verry long corridor with several lights, but the only ones that are lit are the ones at the end of the corridor. Other lights does not go on or off when walking through the corridor.


I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Re: for more then 8 (lightrange) lights [Re: Frits] #106483
01/14/07 13:28
01/14/07 13:28
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline
Expert
A.Russell  Offline
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
As I said, it wasn't tested. I based it on a script I made for fading far entities out, and that worked perfectly.

Thanks for posting, you are obviously the onlyh person who actually tried it. Since you are interested I will go back and debug this for you. I can see a couple of problems just looking at it again now. I'm flat out at work, so I might be a few days.

Until then, you can try this. Did I get it right this time?

Code:

temp_distance = vec_dist (my.x, player.x);
fade_factor = (temp_distance - fade_start) / (fade_end * (1 - fade_start / fade_end);
r = fade_factor * my.skill2;
g = fade_factor * my.skill3;
b = fade_factor * my.skill4;

//I forgot to actually set it!
vec_set(my.red, vector(r,g,b));

//Turn off when no more light
//The previous method would have turned the light off when there was no more red only
var temp[3]; //declare this up near the top with the other variables
vec_diff(temp, my.skill2, vector(2,2,2)); //Try 1,1,1; but GS might be inaccurate

if(vec_length(temp) < 2) //Try 1, but GS might be inaccurate
{
my.lightrange = 0;
}else
{
my.lightrange = my.skill1;
}

[\code]

This is off the top of my head, but I feel quite confident about it.


Last edited by A.Russell; 01/14/07 14:14.
Re: for more then 8 (lightrange) lights [Re: A.Russell] #106484
01/14/07 15:46
01/14/07 15:46
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
Thanks for your response.
Now we have 2 times the fade_factor, one at the beginning;
Code:

//fade between LOD 2 and LOD 3
fade_factor = (d3d_lodfactor[2] / d3d_lodfactor[1]);
fade_start = camera.clip_far / fade_factor;
fade_end = fade_factor * fade_start;


and the new one in the while loop (there is a bracket missing);
Code:

fade_factor = (temp_distance - fade_start) / (fade_end * (1 - fade_start / fade_end) -->);



But inspite of that, it does not work.
The r,g,b values keeps negative (-114 to -127) and while walking the next light will not switch on and the previous not off.
I have 20 dynamic lights in the level, only seven of them are on (the limit) but these seven keeps on nomather where the player is.

The total code sofar (I have changed the skills);
Code:

// dynamiclights.wdl
//
// Triggers lights as player gets close so that more than eight dynamic lights
// can be used in the level. Smooth fades light between LOD2 and LOD3.

define range,skill1; //lightrange
define red_part,skill2; //red
define green_part,skill3; //green
define blue_part,skill4; //blue

//uses: range,red_part,green_part,blue_part
action light
{
var temp[3];
var temp_distance;
var fade_start;
var fade_end;
var fade_factor;
var r;
var g;
var b;

camera.clip_far=2000;

// fade between LOD2 and LOD3
fade_factor=(d3d_lodfactor[2]/d3d_lodfactor[1]);
fade_start=camera.clip_far/fade_factor;
fade_end=fade_factor*fade_start;

my.invisible=on;
my.passable=on;

while(1)
{
temp_distance = vec_dist (my.x, player.x);
fade_factor = (temp_distance - fade_start) / (fade_end * (1 - fade_start / fade_end));
r = fade_factor * my.red_part;
g = fade_factor * my.green_part;
b = fade_factor * my.blue_part;
vec_set(my.red, vector(r,g,b));
vec_diff(temp, my.red_part, vector(2,2,2)); //Try 1,1,1; but GS might be inaccurate
if(vec_length(temp) < 2) //Try 1, but GS might be inaccurate
{
my.lightrange = 0;
}
else
{
my.lightrange = my.range;
}

// test value's
deb_val[0]=temp_distance;
deb_val[1]=r;
deb_val[2]=g;
deb_val[3]=b;

wait(1);
}
}


Take your time.


I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Re: for more then 8 (lightrange) lights [Re: Frits] #106485
01/14/07 16:55
01/14/07 16:55
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline
Expert
A.Russell  Offline
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
I'm doing this between other things, dont have time to test.

The initial fade_actor calculation to find the start and end are wrong:

Code:

// fade between LOD2 and LOD3
fade_start = camera.clip_far/100 * d3d_lodfactor[2]; //or whatever LOD you like.
fade_end = camera.clip_far/100 * d3d_lodfactor[3]; //You can also enter values manually



I'm not 100% on vec_set(my.red, vector(r,g,b));. Should be okay as long my.red is the vector does indeed go my.red, my.green, my.blue. To be sure you could do:

my.red = r;
my.green = g;
my.blue = b;

I had my maths around backwards on this one:
// replace this: fade_factor = (temp_distance - fade_start) / (fade_end * (1 - fade_start / fade_end));

This will work:
fade_factor = ( fade_end - temp_distance) / ( fade_end - fade_start );

Isn't that much simpler and cleaner?

The only problem left with that is that the value will continue to increase as you get nearer and go into negatives as you get further. Use min/max to trim it:


r = min(my.skill2, ( max(my.skill2 * fade_factor, 0) ))


Do the same for g and b.


Looking forward to hearing how it goes.

Re: for more then 8 (lightrange) lights [Re: A.Russell] #106486
01/15/07 13:40
01/15/07 13:40
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
Sorry, can't get it to work either so I have put my thinkingcap on and came to this symplified solution ;
Code:

define fade_end,skill1; //max. visibility
define fade_in,skill2; //time to fade in
define fade_out,skill3; //time to fade out
define max_range,skill4; //max. lightrange
define red_part,skill5; //red
define green_part,skill6; //green
define blue_part,skill7; //blue

//uses: fade_end,fade_in,fade_out,max_range,red_part,green_part,blue_part
action light
{
my.invisible=on;
my.passable=on;
my.lightrange=0;
my.red=my.red_part;
my.green=my.green_part;
my.blue=my.blue_part;

while(1)
{
if(vec_dist(my.x,player.x)<my.fade_end)
{
my.lightrange+=my.fade_out;
}
else
{
my.lightrange-=my.fade_in;
}
my.lightrange=max(0,(min(my.lightrange,my.max_range)));
wait(1);
}
}


For me it works like a charm.
When approached the light(range) in the distance comes on slowly.
The value's I used:
fade_end = 1000
fade_in = 0.3
fade_out = 0.3
max_range = 100
red_part = 50
green_part = 255
blue_part = 50

And a picture where the last light had just gone on;



I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Re: for more then 8 (lightrange) lights [Re: Frits] #106487
01/15/07 15:21
01/15/07 15:21
Joined: Mar 2003
Posts: 4,427
Japan
A
A.Russell Offline
Expert
A.Russell  Offline
Expert
A

Joined: Mar 2003
Posts: 4,427
Japan
Good to hear you've made something that works. Nice simple solution, too.

I'll fix mine up and we can compare soon. Not until after Wednesday, though.

This formula does work:

fade_factor = ( fade_end - temp_distance) / ( fade_end - fade_start );

Example:

fade_start = 423;
fade_end = 967;

current distance from player (temp_distance) = 423

(967 - 423) / (967 - 423) = 1

Perfect, the light will be full on at 423 quants from the player


(967 - 967) / (967 - 423) = 0

Perfect, the light will be off


The values will continue to increase/decrease beyond that, so you just have to clip the value from going outside that range

Re: for more then 8 (lightrange) lights [Re: A.Russell] #106488
01/16/07 07:43
01/16/07 07:43
Joined: Nov 2004
Posts: 862
Australia
DavidLancaster Offline
User
DavidLancaster  Offline
User

Joined: Nov 2004
Posts: 862
Australia
I managed to create some code, which switches on the nearest 7 or 8 dynamic lights, so if you are in range of 20 dynamic lights it will only turn on those closest to the player.

Not sure if this will help, I use pointer 'last_light_ent' and a variable 'current_lights', it also uses skill19 and another skill defined as 'my.light_visible_range' which is the range the player needs to be at to turn it on, the light also turns off if the camera is farther away from the light by a distance of light_visible_range * 1.5, to avoid some weird dynamic lights randomly appearing and staying stuck on all over the place...Otherwise it might be something hard to understand, good luck

ie from an entity function in a loop call:

handle_dynamic_lights(light_amount,pulsate_speed,pulsate_amount,random_pulse)
light_amount: the amount light_range becomes, such as 200
pulsate_speed: speed at which the light pulsates along a sin wave
pulsate_amount: how large the pulsation is
random_pulse: a random amount added onto light_range which creates flickering:

I use this for torches which I place on top of WED lights.
handle_dynamic_lights(200,80,12,20);

and I use this color:
my.blue = 10;
my.green = 30;
my.red = 40;

Here's that confuzzling code:
Code:

FUNCTION handle_dynamic_lights(light_amount,pulsate_speed,pulsate_amount,random_pulse) {
IF (last_light_ent == my && my.skill19 == 0) { last_light_ent = null; }
IF (vec_dist(vector(my.x,my.y,0),vector(player.x,player.y,0)) < my.light_visible_range) && (vec_dist(my.x,camera.x) < my.light_visible_range * 1.5) && (light_amount > 0) { //if we are in range
IF (my.skill19 == 0 && current_lights < 7) { //if we are turned off and there is enough lights left for us to turn on
my.skill19 = 1;
current_lights += 1;
}
IF (my.skill19 != 0 && last_light_ent != my) { if we have been turned on
IF (last_light_ent == null) { //if no entity is stored in last_light_ent make the my entity last_light_ent
last_light_ent = my;
} ELSE {
IF (vec_dist(my.x,player.x) > vec_dist(last_light_ent.x,player.x)) { //if last_light_ent already exists if this light is further away set this light to last_light_ent
last_light_ent = my;
}
}
}
IF (last_light_ent != null && last_light_ent != my && current_lights >= 7 && my.skill19 == 0) { //if dynamic lights are maxed out, this light is current turned off
IF (vec_dist(my.x,player.x) < vec_dist(last_light_ent.x,player.x)) { //if this light is closer than the light which is farthest from the player
last_light_ent.skill19 = 0; //turn off that light
last_light_ent.lightrange = 0;
last_light_ent = my;
my.skill19 = 1; //turn on this light
}
}
} ELSE {
IF (my.skill19 == 1) { my.skill19 = 3; } //if the light is on turn it off
}
IF (my.skill19 == 1) { //light is on
my.skill18 += pulsate_speed * time_step;
my.skill18 %= 360;
my.lightrange = light_amount + fsin(my.skill18,pulsate_amount) + random(random_pulse);
// my.lightrange += 0.1 * my.skill10 * time_step; //this was an attempt at having the my.skill19 == 1 state being the light slowly appearing and my.skill19 == 2 state being when the light is on
// IF (my.lightrange > my.skill10 + fsin(my.skill12,my.skill13)) { my.skill19 = 2; }
}
IF (my.skill19 == 3) { //turn the light off
IF (my.lightrange > 0) {
my.skill19 = 0; current_lights -= 1; my.lightrange = 0;
IF (last_light_ent == my) { last_light_ent = null; }
// my.lightrange -= 0.1 * pulsate_amount * time_step;
// IF (my.lightrange <= 0) { my.skill19 = 0; current_lights -= 1; my.lightrange = 0; }
}
}
}



Re: for more then 8 (lightrange) lights [Re: DavidLancaster] #106489
01/16/07 11:34
01/16/07 11:34
Joined: Apr 2005
Posts: 2,332
Germany, BaWü
aztec Offline OP

Expert
aztec  Offline OP

Expert

Joined: Apr 2005
Posts: 2,332
Germany, BaWü
hey these scripts are all awesome thx very much

Regards
Aztec


Visit:
schwenkschuster-design.de
Re: for more then 8 (lightrange) lights [Re: aztec] #106490
01/16/07 16:42
01/16/07 16:42
Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
TripleX Offline
Expert
TripleX  Offline
Expert

Joined: Oct 2002
Posts: 4,753
Munich, Bavaria, South of Germ...
A6.6 will support an unlimited number of dynamic lights..

Quote:


X An arbitrary number of dynamic lights is now supported. The maximum number of lights can be set through the max_lights variable (default: 100 for the beta version, 8 for the release version). The light manager uses the ABT for calculating which objects lie in the ranges of which lights, and generates lists of close lights for every object. This calculation, although very fast, is an additional rendering process that can affect the frame rate, depending on the number and ranges of active lights. For overcoming the 8 lights hardware limit, light sources are dynamically switched on and off during rendering while taking care that no more than 8 lights are active at any time.
Naturally, a single entity, block, or terrain chunk can still not receive light from more than 8 sources simultaneously. If an object lies within the ranges of more than 8 lights, it is affected by the 8 most recently created lights only. This ensures that creating a new light has an immediate effect on the environment even if many dynamic lights are already around. For using the new light system, levels and map entities must be compiled in mesh mode (Create Mesh activated). Terrain should be chunked; the smaller the chunks, the less visible are light swapping effects when more than 8 lights move in or out of the range of a chunk.




Page 2 of 4 1 2 3 4

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