Jump to content
Eternal Lands Official Forums
Guest Zeplin

Depth Buffer Shadows Vs Stencil Buffer

Recommended Posts

Guest Zeplin

Im not much of a graphics guy so could Someone explain the advantages of Depth over Stencil? Or can point me to a document?

 

Currently im aware we use Stencil, And Ent wants to change it over? Id be keen to learn a bit about this.

 

on a side note i did a search, And found a million docs explaining Stencil, and not the other technique lol.

Share this post


Link to post
Share on other sites

The advantages?

Soft shadows, everything casts a shadow on everything, no more artefacts with shadows floating in the air on higher grounds, and just a little slower than the current method.

Share this post


Link to post
Share on other sites
Guest Zeplin

ah interesting, Still looking for a tutorial. Guess thats why you were looking to pay someone to do it. Fair enough.

Share this post


Link to post
Share on other sites

Check out Nvidia's site - I think they have a paper (or perhaps a few papers) on it.

I'll see if I can try to implement it next week or so.. I still don't know how I'd handle omnidirectional lights though...

Share this post


Link to post
Share on other sites

We can't have omni lights, that would require rendering the scene 4 times/lightsource. Just want some shadows from the sun, the night lights can go without shadows.

Share this post


Link to post
Share on other sites

Well, I started working on it today, but I have nothing to show yet. I'm not sure how I'll do soft shadows yet, but I guess I'll start by getting hard shadows to work.

I've been thinking a bit about this, and we should avoid artifacts quite well, since camera and light source will be well placed for this.

Also, I think that this should work great regarding performance, since people with slower machines could simply render smaller depth maps.

I'll hopefully have something working later this week, wednesday or so :huh:

Share this post


Link to post
Share on other sites

The soft shadows are a byproduct of this technique, due to the alising in the deepth map. Nvidia has a tutorial (source included) on how to do it, and they have soft shadows in there.

Share this post


Link to post
Share on other sites
The soft shadows are a byproduct of this technique, due to the alising in the deepth map. Nvidia has a tutorial (source included) on how to do it, and they have soft shadows in there.

I'm not sure which tutorial you're referring too... A link would be nice :P

The basic method doesn't give soft shadows - every pixel is either in shadow or not - but I'm sure it can be extended.

 

Anyway, I don't have much time today to work on this, but what I have so far is that the scene is rendered from the light's viewpoint to create a depth map, and I also have setup texture coordinate generation to project this depth map correctly onto the scene.

 

I'll continue with this tomorrow (or tonight if I'm not too tired when I get home.) :D

Share this post


Link to post
Share on other sites

Hmm.. I can't say I see any soft shadows there.. Perhaps they would show up if I had all the optional extensions (I haven't had the time to read up on exactly what they do.)

 

Anyway, I have somewhat working shadow mapping in the game now. Nothing that's ready to be released, though, it's still buggy and slow... But I'm getting there :P

Share this post


Link to post
Share on other sites

Oh, this was fun. If you add glPushAttrib/glPopAttrib around display_actors(), like this

	glPushAttrib(GL_ALL_ATTRIB_BITS);
display_actors();
glPopAttrib();

the chat (and fps etc.) text will get distorted. :wacko: I just wasted so much time on this one - I thought I made something really wrong in the shadow code... :rolleyes:

 

It's still a bit too slow, I think. And there are some problems with z buffer precision (and polygon offsets and so on.) When I get this working to my satisfaction, I'll add support for extensions like pbuffers, non-power of two textures, and so on..

 

More work on this tomorrow or friday, I think...

Share this post


Link to post
Share on other sites

BTW, I think that the old shadows (my code) should be removed, since it's buggy and even tho it works on some cards the deepth buffer shadows won't work, it's still too slow for those cards anyway.

Share this post


Link to post
Share on other sites
Great :blink: Can you please post some preliminary screenshots? And what about the current speed, how low is it?

Ok :angry:

I've made the shadows red, just so it's easier to see them. First is a picture of shadows with the old system:

planeproj.jpg

And here's the new one:

depthmap.jpg

As you can see, the depth map resolution is quite bad.. I'll figure out some good way to calculate the light frustum based on sun position. I'll also see if I can get better results with a linear mapping (the depth buffer isn't linear, as you know.)

I'll also have to make a special case for objects with transparency - I think I'll have to make two passes for them...

 

And the speed loss; it varies - about 10-15 fps lost compared to the planar projected shadows (I usually have 20-30 fps in EL, lower if there are lots of people there.) Of course, this is with an unoptimized debug/profiling build...

 

I'm keeping the old code for now - it's good to have something to compare to :o (But yeah, we might remove them later. It would keep the code a lot cleaner too, if there was only one type of shadows.)

Share this post


Link to post
Share on other sites

those new shadows look way better. and keep the low resolution. those sharp shadows of the old system are unreal. on earth (cause we have an atmosphere) sun shadows edges are blurred anyways.

 

and why is there shadow on the name and health bar? o.0

Share this post


Link to post
Share on other sites
those new shadows look way better. and keep the low resolution. those sharp shadows of the old system are unreal. on earth (cause we have an atmosphere) sun shadows edges are blurred anyways.

I think I'll make the resolution of the depth texture a setting, so that low-end systems can have cheaper (and blockier) shadows. The thing with low resolution here, is that shadows from small details might pop up and vanish in a way that can be annoying. This, of course, isn't visible in a screenshot :)

 

and why is there shadow on the name and health bar? o.0

Umm... Good question. Next! ;)

(Those won't be shaded in the final version, of course.)

Share this post


Link to post
Share on other sites

Here's another one:

shadowmap2.jpg

(Picture taken moments before poor Elrood got eaten by a Grue.)

 

If you look closely, you can see the problem I mentioned (objects with transparency.)

More specifically, the pixels that are covered by the roads polygon, but not by its visible pixels get shaded twice. It looks a bit worse on some places.

I'm not sure how to solve this; it's either destination alpha or stencil. The former has the problem that I already use alpha test and blending, while the latter has the problem that I'd need to clear (parts of) the stencil buffer several times... I'll have to think about it some more...

Share this post


Link to post
Share on other sites

I think it looks GREAT! What's the shadow texture resolution you are using in this screenshot?

Also, why exactly does the transparent pixels get shadowed twice?

Share this post


Link to post
Share on other sites

I would guess it's because the shadow is being cast on both the transparent pixels and the pixels under them, thus "doubling" the shadow.

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×