Archived

This topic is now archived and is closed to further replies.

shadows in tiles

This topic is 5582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

does anybody have an idea on how to produce realistic shadow effects on a tiled game without using the obvious 3D? in realistic shadows I mean that the shadows act like shadows, no that they are depend on light sources. I am what I am, more or less and my site rocks www.geocities.com/roam_fire I think

Share this post


Link to post
Share on other sites
Not sure what you mean by act like shadows. You mention not being dependent upon light sources but do you want it to move over objects like a shadow does - i.e. ''break'' into separate planes when falling onto things like stairs or a wall? That I don''t know how you''d do simply.

If you just want to simulate decently (on flat objects) then I''d say draw a black shadow shape for each character animation and then alpha blit it into position before you draw the character - or whatever other object you''re drawing at the time.

Hope that helps.
M

Share this post


Link to post
Share on other sites
quote:
Original post by mearrin69
... move over objects like a shadow does - i.e. ''break'' into separate planes when falling onto things like stairs or a wall...


Exactly what I want in the end, but lets start with:

quote:
Original post by mearrin69
... simulate decently (on flat objects) then I''d say draw a black shadow shape for each character animation and then alpha blit it into position before you draw the character ...


However the question is, when there are many objects on screen, and each casts a shadow, how to sort the shadow drawing so that the shadows affect the correct objects?



I am what I am, more or less
and my site rocks
www.geocities.com/roam_fire
I think

Share this post


Link to post
Share on other sites
Sorting won''t help you (unless you''re making a 2d bird-perspective game). To sort hower i usuallt make a struct like this:

struct Object {
DWORD type;
float fDistance;
void * pObject;
}

Then i count the objects use malloc to allocate memory for as many "Objects". Init the object casting the pointer to void * pObject = (void *) &vehicle; (or something). Set the type and the distance. Sort and render all objects in the array (by casting the pointer back to the original type). free memory.

I''ve figured this out myself. Maybe there''s a better way? Anyone?

.Pangplast

Share this post


Link to post
Share on other sites
quote:
Original post by pangplast
Sorting won''t help you (unless you''re making a 2d bird-perspective game). To sort hower i usuallt make a struct like this:

struct Object {
DWORD type;
float fDistance;
void * pObject;
}

Then i count the objects use malloc to allocate memory for as many "Objects". Init the object casting the pointer to void * pObject = (void *) &vehicle; (or something). Set the type and the distance. Sort and render all objects in the array (by casting the pointer back to the original type). free memory.

I''ve figured this out myself. Maybe there''s a better way? Anyone?

.Pangplast


huh ?



I am what I am, more or less
and my site rocks
www.geocities.com/roam_fire
I think

Share this post


Link to post
Share on other sites
bleh, you got me. Never played with this too much. I''m sure there''s a way but I don''t know what it is unless you''ve got 3D.

You can make them behave fine in 2D by themselves easily i.e. drawing a shadow on a floor. Try to make the thing go up a wall or fall correctly up steps and suddenly it seems you''ve got a mess.

Making shadows interact correctly in a more complex, but still 2D scene, is going to be pretty difficult because the objects in the world have no real data - they''re just window dressing. An isometrically drawn table looks good but there''s no information about where it''s top is, what it''s made of - only that it''s 64x64 at 16bpp and has a collision mask of such-and-such.

***Actually, maybe you could do something with collision masks? Use various colors to indicate the facing of the plane, essentially the normal. Then find some way to rasterize the appropriate part of the shadow sprite across them. That''s a lot of calculations, though.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Perhaps this will not help, but if you have access to a stencil buffer (opengl/directx) then you can use this to avoid potential shadow overdraw without having to worry about sorting. Or you could create your own buffer to simulate the stencil buffer''s behavior.

Good Luck

Share this post


Link to post
Share on other sites
The way i''m thinking of is:

having an extra layer (named shadow-layer).
then you put in your level editor black tiles in the shadow-layer.
In the engine you draw the shadow-layer with alphablending on top of all other layers.

Share this post


Link to post
Share on other sites
actually I have an idea about shadows walking on on walls,

since the shadow is static, ie: same angle, same length, if you know the distance between the casting object and the wall, you know how much "shadow" you''ve got left that can climb on the wall.

ex:
the shadow is 20 units long.
you are 10 units from the wall.
the wall is 5 units high.
so: the shadow covers the entire wall and still continues (disregard the wall shadow) another 10 units beyond the wall on the ground.

now we move and this time the wall is 15 units high,
so: our shadow covers 10 height units from the wall.

(units is whatever you represents distance, pixels, inches, lightyears etc.)

I am what I am, more or less
and my site rocks
www.geocities.com/roam_fire
I think

Share this post


Link to post
Share on other sites
uhh I''m hot tonight.

in the first example, the shadow should skip the 5 units from the wall and continue 5 units after the wall (where the wall''s shadow stops) for the remaining 5 units.

ie: 10 units on the ground before the wall, 5 units on the wall => skip 5 units on the ground from the wall, another 5 units on the ground.

I am what I am, more or less
and my site rocks
www.geocities.com/roam_fire
I think

Share this post


Link to post
Share on other sites
If you just want shadows on the ground for now, all you have to do is draw all shadows after drawing the ground but before drawing any objects. Order doesn''t matter. If you have shadows cast by the scenery that can affect objects, then draw these after the objects.

On the other hand, lets say you do want the shadows to affect other objects. If the shadows are cast, say, to the right, draw the objects in order from right to left. Draw each object''s shadow just before drawing the object itself.

Share this post


Link to post
Share on other sites