Chaosforge Forum

  • March 29, 2024, 01:14
  • Welcome, Guest
Please login or register.



Login with username, password and session length
Pages: [1]

Author Topic: Vision code. Need help=)  (Read 4043 times)

Cora

  • Private FC
  • *
  • Offline Offline
  • Posts: 15
    • View Profile
Vision code. Need help=)
« on: October 17, 2007, 04:38 »

Khem, I have no idea were to write my question (if you want call it idea, minds etc.), so I write here

I need help to deal with damned vision code in RPG RL-based(square field+trun based) graphic MMORPG (still project anyway=))

so here is the problem:

We have - transparency rate (0..10000 where 10000 is fully transparent and 0 is no light pass)
Also - light sources, such as lamp, torch... even candle in the hand of player=) which have light power and light range
And... mirrors)
This all in 2d array

Need to get a lumen array (how much is each square is lighted), and vision array (with counting of range - so more distant objects will have less value then close ones).

PS transparency and mirrors work for light in the same way than for player

I know that this is madness... but I need it) So any Ideas?
Logged

TFoN

  • Colonel
  • *
  • Offline Offline
  • Posts: 562
  • Gleefully antisocial!
    • View Profile
Re: Vision code. Need help=)
« Reply #1 on: October 17, 2007, 04:53 »

http://www.roguelikedevelopment.org/
They have all kinds of ideas, and LOS's on the literal top of the list - top left corner of the homepage.
I hope it's of any help to you.

Cora

  • Private FC
  • *
  • Offline Offline
  • Posts: 15
    • View Profile
Re: Vision code. Need help=)
« Reply #2 on: October 17, 2007, 05:40 »

LOS is quite easy and mirrors too(but not so). But light... I used LOS algoritm for light, and it quite working, until you use small number of spotlights. But when it just Line Of Light on map (like sun) or when there is a lot of spotlights...=D
Logged

Rabiat

  • Sergeant
  • *
  • Offline Offline
  • Posts: 98
    • View Profile
Re: Vision code. Need help=)
« Reply #3 on: October 18, 2007, 14:51 »

I'm not sure I understand the exact problem, but it's interesting enough. Here's how I'd go about it.

Every light source has a given brightness. The basic idea is that a light ray scatters, and therefore its brightness decreases, as it is further removed from the light source. If you use ray tracing, divide the light source's brightness by the light source's radius to obtain the standard brightness decrement for a fully transparent square (I'm assuming the loss in brightness is linear to distance).

Now initialize a 'lumen' array to all zeroes (darkness). For each light source, trace rays outward from the light source to cover each square in its radius. For each square, increase the square's brightness value by the light ray's brightness. Lower the ray's brightness by its standard decrement (as above) multiplied by the relative transparency of the square. Then move outward one more square and increase the next square's brightness value by the light ray's remaining brightness. Continue until the ray's brightness hits zero. For mirroring, deflect the light ray by the angle with which it hits the surface of the mirror, and continue as above.

So if you have a circular ray trace and a method to deflect rays;

Initialize all Square.Brightness = 0
For each LightSource
  DeltaBrightness = LightSource.Brightness / LightSource.Radius
  Ray.Brightness = LightSource.Brightness
  For each square outward, repeat
    Square.Brightness = Square.Brightness + Ray.Brightness
    Ray.Brightness = Ray.Brightness - DeltaBrightness * (Square.Transparency / 10000)
  until Ray.Brightness <= 0

Different rays coming straight from the same light source should not increment a square's brightness more than once. Rays coming from different light sources, as well as reflected rays, should further increase a square's brightness.

Hope this helps.
Logged
0.9.9.2 - [22/8/2/0/0] - Mancubus Scrap Metal Collector

Cora

  • Private FC
  • *
  • Offline Offline
  • Posts: 15
    • View Profile
Re: Vision code. Need help=)
« Reply #4 on: October 19, 2007, 07:16 »

Raytracing? hmmmm)))good idea. But lights are dynamic) so if I will do recounting for each move it will be buggy ver)

I have an idea about precounting one time and then only deleting old and adding new light sources. But still need test
Logged
Pages: [1]