Sign in to follow this  

"fake" soft shadows?

This topic is 3403 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

I've got a 2d sprite running around on a 3d terrain and I'd like to put a fake shadow under it; kind of like a soft circular shadow. I guess it would require projecting a 2d circle onto the floor/terrain with alpha blending somehow, but im not quite sure how i would do this... If you need an example of what I mean, I guess its how games in the '95-'00 era would fake shadowing. Something like this: http://www.armchairempire.com/images/feature-articles/ps2-ff7/final-fantasy-vii-2.jpg http://i151.photobucket.com/albums/s146/Chaoticgamer/star_ocean_first_departure-2_qjprev.jpg http://psp.absolute-playstation.com/pspimages/final-fantasy-tactics-war-of-the-lions-psp-l3.jpg

Share this post


Link to post
Share on other sites
This seems so easy I may be missing your question...

But...if your sprite chracter moves on the terrain I assume you have some kind of collision algorithm available...all you need then is the ability to find the normal of the polygon directly underneath your character.

Then you:
1) make a shadow sprite
2) place it at the ground level at the center of the characters feet
3) rotate it to match the normal of the polygon (offset it bit from the terain to prevent z-fighting)
4) use alpha blending

Remember --always update the position of the shadow as the last thing in the frame, after the character has been moved and so on.

Share this post


Link to post
Share on other sites
ah, it does potentially seem easy, but then the terrain isnt necessarily flat! so a flat shadow wont work in every case. Even if you take the normal, if you're at a bend in the terrain, you'll get part of the sprite cutoff. I don't *think* disabling the z buffer would make it look right in this kind of case either.

Share this post


Link to post
Share on other sites
Quote:
Original post by sqpat
ah, it does potentially seem easy, but then the terrain isnt necessarily flat! so a flat shadow wont work in every case.

Then you're no longer looking for a "fake" shadow, you're looking for a real one! I don't think any of the screenshots you've posted have interaction with the terrain, do they? What kind of terrain are you dealing with? Are you looking for a method that involves subdividing a textured quad and then displacing it based on the terrain somehow?

Share this post


Link to post
Share on other sites
i cant make it part of the sprite because of jumping, etc that would place it off the size of the sprite texture/graphic. Also because of other dynamic effects i want to have with these shadows.

also i thought it was fake because i was dealing with shadows of 'sprites'? anyways, breaking up a textured quad onto the terrain might work i suppose... hm. I'll think about the normal suggestion some more, i suppose.

Share this post


Link to post
Share on other sites
http://sqpat.com/project/mysample31-buggyshadows.PNG

hmm... im not too happy with this, even before making a decent graphic, and before adding the normal checks. I guess im still happy because i implemented the backbone of the animation framework, but... does anyone know of a good way to fake this soft shadowing thing so that it deals with terrain better? maybe placing a directional light above four little circles that'll only show on the terrain... i dunno. i dont have a great understanding of lights and keeping them from affecting everything in the scene.

Share this post


Link to post
Share on other sites
You can just grab the polgons underneath the character and draw a textured alpha blended circle onto it which then will conform to the terrain. Since most terrain engines will give u collision points upon request, there isn't any need to try and traverse the terrain's geometry just sample it using a regualr grid and apply the texture onto that grid, to avoid zbuffer artifacts either offset it or draw with some sort of zordering bias, or u can just render it after the terraain but before any characters without any zbuffing at all.

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
hmmm.... I wrote the terrain engine myself. I think I get what you're saying, but it'd be hard to just 'draw' a circle onto the terrain. Did you mean perhaps to grab several spots instead of just one, then I can draw like 9 little circles to approximate one big circle? That might work, I suppose.


EDIT: okay, even I if I do a ton of samples there'll probably be noticable jagged mini-shadows sticking up over the bends of the terrain. And if I chose to set a custom texture stage over the terrain... because its done indexed and it has a special algorithm to cut down on draw calls, it'd just not be feasible.

I thought it would be easy to project a circle onto a surface without using an actual light, but maybe I think I'll be using an actual light. Perhaps a vertical directional light and I'll render some transparent circles and not write them to the z buffer... then maybe this way it'll shadow onto the terrain? Does this sound right? I'm not sure. Man, time to hit up a tutorial

[Edited by - sqpat on August 17, 2008 2:22:53 AM]

Share this post


Link to post
Share on other sites
no, i think what he means is this:

- you grab all the triangles below your object from the terrain. may be just one, may be several.

- you bind a shadow-circle texture with projective texturing from top

- you draw those grabbed triangles again, but without the grass, and the shadow-circle texture instead. you use alpha-blending to fit it on the grass

Share this post


Link to post
Share on other sites
oh, and, because of z-fighting. make them a bit higher (or closer to you), or disable z-test just for the shadows (and draw your characters after the shadows)..

i've seen this in quite some older games, where shadows of characters are still visible when characters walked behind some hill :)

Share this post


Link to post
Share on other sites
Yes I was planning on messing with the alpha channels on the PNG but I'm not too sure how I'll go about doing that (maybe use a blur effect on the original one, fit it inside the shadow shape, then set that as the alpha channel or something) but I'm pretty happy with the results. I still want to combine all of the shadow draws into a single drawIndexedPrimitive, they're done with a bunch of separate drawIndexedPrimitives at the moment. But otherwise they're working fine.

Share this post


Link to post
Share on other sites
Here's probably the best way to make shadows for sprites that conform to arbitrary terrain:

Switch to a seperate render-target, clear to white, set an orthgonal projection matrix and a top-down view and then render all visible shadow caster sprites as all black blob sprites (or you can even make special shadow sprites for each type or whatever)..

Then just project this on your terrain using the same worldviewprojection matrix plus screen adjustment offset (per usual texture projection)..this method should be fast even on older cards and look good in all cases.

Its little slower than simple shadow sprites but much more robust.

Share this post


Link to post
Share on other sites
just use that texture:



(link) .. first result on google with "shadow texture" :)

this, of course, with the right alpha blending.


overlapping shadows are an issue with that algorithm.. blending them in a secondary buffer and then drop them back would be a way.. but actually, it isn't a big problem in your case i'd guess.

the other solution by "Matt Aufderheide" is a good one, too. but may get too complicated for you..

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
Here's probably the best way to make shadows for sprites that conform to arbitrary terrain:

Switch to a seperate render-target, clear to white, set an orthgonal projection matrix and a top-down view and then render all visible shadow caster sprites as all black blob sprites (or you can even make special shadow sprites for each type or whatever)..

Then just project this on your terrain using the same worldviewprojection matrix plus screen adjustment offset (per usual texture projection)..this method should be fast even on older cards and look good in all cases.

Its little slower than simple shadow sprites but much more robust.


I use this method for some of my shadows in one game, I render the player models into the shadow though, the beauty of it is because its a texture you can use a Gaussian blur or something similar to get nice soft edges with a relatively low resolution render target. and because you using a projected texture the shadow texture wraps nicely around the shadow receiver objects.

If its just onto terrain you should get no issues becuase the terrain will be below the player, but I had some issues with casting the shadow onto world objects because the shadow projects onto roof's and things which shouldn't be in shadow that are in between the lights view and the player but there are many ways to solve this, (I use stencil buffer and clip planes in OpenGL).



Share this post


Link to post
Share on other sites
this is another screenshot but you can see that i've got the shadows to look softer now:

http://sqpat.com/project/mysample36-comparisonplussoftshadow.PNG

thanks for the graphic, davepermen. I used a modified version of that one in the alpha channel to a PNG.

Share this post


Link to post
Share on other sites
you know what? Ive had 3 people tell me point/non filtered is better. I prefer the filtered sprites myself. In the end its like 8 lines of code worth of difference, so I'll probably just offer both options!

Share this post


Link to post
Share on other sites
you're using xna? i've seen yesterday that there are more filtering options than just pointsample and linear. no clue how they look on your sprites, haven't tested them yet myself, but they may be even bether than the ordinary filtered image.

8 lines? that's 6 lines too much :) anyways, i really like your work.

Share this post


Link to post
Share on other sites

This topic is 3403 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this