Soft Edged Shadows article on GameDev from Jan 2005

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Soft Edged Shadows article on GameDev from Jan 2005

Post by Falagard »

http://www.gamedev.net/reference/articl ... le2193.asp

I guess this question is for Sinbad:

Based on Ogre's current method of doing texture based shadows, how much work would it take me to put together a tech demo using the above processes?

I'm likely going to only allow DirectX in my game initially so I don't have to support varying types of shaders, so it's possible if Ogre doesn't support certain features like floating point textures (does it?) or whatnot that I can add it specifically for the DirectX renderer for my game.

I'm not entirely worried about the shaders because Ogre has magnificent material scripts and support for shaders, but it's the render pipeline that has me a bit worried. I realize Ogre supports render to texture, and texture based shadows. Ogre already has some nice features for texture based shadows, such as fading them out after a specified distance so that only close objects need to be shadowed, etc, and would like to leverage that.

I also assume Ogre is already rendering to texture for the texture based shadows. The problem probably lies from the fact that this article renders the scene depth to the floating point texture, whereas texture shadows in Ogre actually render the geometry as black onto a white texture (or vice versa or whatever).

Anyhow, just thought I'd ask.

Clay

User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

We do support floating point textures, and rendering to them, since 1.0.0. Rendering the scene depth is just a matter of rendering the geometry, but with a shader that interpolates the depth in a texture coordinate (as I've seen).

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

You can override lots of things for how texture shadows are organised:

SceneManager::setShadowTexturePixelFormat
Allows you to define the pixel format of the shadow textures. You'll have to be using shaders if you change this.

SceneManager::setShadowTextureSelfShadow
Sets whether OGRE tries to render self-shadows when using texture shadows. The default is 'false' since that's all that will work with fixed-function shadows. If you implement a depth shadowmap using shaders, you can set this to 'true'.

SceneManager::setShadowTextureCasterMaterial
Sets the shader used to render shadow casters into a texture. Here's one place where you plug in your shaders.

SceneManager::setShadowTextureReceiverMaterial
The other end of the texture shadow rendering pipe, where receivers are re-rendered. Here's where you can do nifty effects, like using the depth map to properly self-shadow, or you could do some filtering.

I never had time to use these myself, but I was sure people would want to do stuff like this, which is why they're provided.

HTH

User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
x 3
Contact:

Post by Falagard »

Excellent, I've seen some of those options and it sounds like you have many of the bases (if not all of them) covered.

Thanks Sinbad,

Clay

User avatar
Injector
Gremlin
Posts: 174
Joined: Wed Jan 21, 2004 2:42 pm
Location: Frankfurt, Germany

Post by Injector »

Is there a way to get a "real" depth texture without using floating point texture formats? I noticed there is a format called PF_DEPTH, but it is not used throughout Ogre (if my VS search function isn't fooling me).

edit: I might add that I implemented shadow mapping some 2 years ago and used the GL_ARB_depth extension (iirc).

Also, I would like to know another thing: How/Where can I hook up a shader driven material to blur the generated shadow texture (preferably using two passes, one blurring horizontally, one blurring vertically to save some performance). I think the best way to do this would be to do that as a separate rendertarget update before the texture is applied onto the shadow receiving geometry, so using the shadow receiver material is not an option, or am I mistaken here?

Thanks for your input.

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Here's the thing - 'depth' textures are probably the worst example of lack of standardisation in graphics coding today, which makes supporting them properly across all cards and APIs a total pain in the arse. Here's why:

- D3D has no ability to use depth textures without floating point textures and shaders. It's possible to do it with nVidia cards, which have a 'magic' feature meaning that you can create depth-only textures and bind them to a texture unit, and 'magically' get a depth compare op. This is completely non-standard and is not documented in D3D, only on nVidias site. It doesn't work with any other manufacturers cards.

- GL does have a vendor-independent extension which both nVidia and ATI have implemented. But that would mean you can only use it on GL, not D3D.

If you look on nVidia and ATI's site you will find conflicting approaches for 'simple' shadowmaps under D3D. nVidia uses the 'magic' features (and makes no comment about that fact that it won't work on anyone elses cards, thanks guys) and ATI uses floating point textures and shaders. The latter works on all vendors cards and on all APIs, which is why it's our recommended approach.

As for the blurring, you should be able to create a receiver material that does this. You can bind the shadow texture ("Ogre/ShadowTexture0" etc) into all 4 texture units and then render the receiver pass with a pixel shader that averages using jittered texture coordinates. This should work on ps_1_1 with one texel access per unit, in higher models you can do multiple accesses per unit if you want for better filtering.

User avatar
Injector
Gremlin
Posts: 174
Joined: Wed Jan 21, 2004 2:42 pm
Location: Frankfurt, Germany

Post by Injector »

Thanks for your elaborate answer. It was not the one I was hoping for, though :cry:. I am afraid floating point textures are no option for us, considering the minimum hardware requirements for our game.

I will try blurring the texture using the shadow receiver material then, thanks for this.

User avatar
vastor
Halfling
Posts: 62
Joined: Wed Jun 08, 2005 10:23 am
Location: Germany

Post by vastor »

Has anyone implemented this by now?

I have some problems to implement it.

Post Reply