PDA

View Full Version : Lights in Powerdraw



Cataclysm
02-05-2003, 11:06 AM
Hi all!

Does anybody have any tips on how to implement dynamic lights in Powerdraw? Especially to apply fast lighting on TAGFImages. Any help would be welcome!

Coen

Paulius
02-05-2003, 04:51 PM
Not really dynamic light, but should be fast: simply draw an image composed with one bright rgb color and an alpha gradient, which should go from almost opaque at the lights center to totally transparent at its end over whatever you wish to seem lit.

Cataclysm
03-05-2003, 01:35 PM
Hmmm... that might work, but don't you need an image filling the entire screen to do that then? I mean, you need to cover the parts of the screen you don't want lit. Another problem then occurs when you want to use more than 1 light... the lights (images) will cover (and thus darken) each other.

An example of the thing we want to do is to create a dark cave with the player holding a flashlight that lights the area in front of the player and (if possible) multiple (red-colored) lights on the walls for the torches. The rest of the cave (that isn't lit by one of the lights) should be completely dark. How can we create the effect that in the area of the flashlight, the images on the screen have their normal colors and the rest of the area (except the parts with the torchlights) dark.... all of this using alpha gradients for he light's edges, as you said :wink:

I think I was wrong when I said lighting in the first message :oops: The thing we actually want here is darkening rather than lighting, because we want to darken the unlit parts and leave the lit parts as is.

Any suggestions on this one? :)

Coen

Paulius
03-05-2003, 08:07 PM
I don't think theres a fast way of doing this, but you could try locking the shadow texture and editing it pixel by pixel. It should look something like this asuming you use 32bit color:

var
LRect: TD3DLocked_Rect;
x, y, Distance: Integer;
SrcPtr: Pointer;
begin
if Image.Lock(0,LRect)<> 0 then//texture lock and error check, Image is TAGFimage - the shadow texture
begin
//TODO: finalise everything
ShowMessage('Texture lock failed!')
Application.Terminate();
Exit;
end;

for y:= 0 to ImageHeight-1 do
begin
SrcPtr:= Pointer(Integer(LRect.Bits) +Integer(LRect.Pitch * y));//Get the pointer to the pixel at 0,y coordinates
for x:= 0 to ImageWidth-1 do
begin
//todo: find pixels at x,y Distance to the nearest light
if Distance>245 then // asuming 245 this is the farthest the light reaches
LongWord(SrcPtr^):=LongWord(245 shl 24)//if the point is far from the light then make it black with some transparency
else LongWord(SrcPtr^):=LongWord(distance shl 24);//here we only set alpha leaveing rgb on 0
Inc(Integer(SrcPtr), 4);//move the pointer to the next pixel
end;
end;
image.Unlock(0);//Don't forget to unlock the texture
end

Warning: not tested.

mindplay
10-12-2003, 09:02 AM
I'm not deep into PowerDraw yet (only just started playing with it last night), but I would suggest something like this: render the lights as white-to-black gradient spheres on a VScreen, using additive blending; you don't need alpha for this, since you'll blend them additively. What I would do then, is draw that entire VScreen onto the main display (after rendering your background tiles or whatever you have there) with multiply blending, so that areas with no light in them get dimmed out.

The special lights (e.g. for toches and such), I would render afterwards, for example as yellow-to-black gradient spheres with additive blending (again, no alpha necessary) ...

Not sure if it's at all possible to draw a VScreen onto the main display with filtering options though - although I suppose it ought to be? ... anyone?