Interesting. So it's basically what I mentioned, except with an added standard depth check.CABAListic wrote:That's right (in fact that's part of the technique I'm refering to), but you're losing the depth information and may therefore have backprojection of shadows and such things. This only works if your shadow receiver is always behind (seen from the light) any potential shadow caster.nullsquared wrote:@ CABAListic: You can get away in simple scenes with no self shadowing by blurring a white/black texture (white is viewport background, black is any objects), and projecting that onto receiving geometry...
Anyway, I didn't succeed to find the paper I got it from, if I remember correctly, its title was "Simple soft shadows", but that didn't show up on Google. I'll keep looking and post the link, but in the meantime, the technique works like this:
You need a 2-channel shadow texture. In the first channel you store the depth from the light like with occasional shadow mapping, and in the second channel you store exactly that white/black image, except in the paper they do it reverse (i. e. they assume that the shadow texture defaults to black and store a 1 in the second channel for every caster. Naturally you can do it the other way, just need to remember to adjust the formula later). Then you blur both channels of the texture (might want to use a box filter instead of gaussian, since this is supposed to be a fallback for not-so-good hardware), and in your receiver shader, you extract the actual depth from the shadow map via this code:
If the depth check says the area is shadowed, then you use the second channel to determine the amount of shadowing.Code: Select all
float4 shadow = tex2D(shadowTex, shadowUV); float depth = (shadow.x-1) / shadow.y + 1;
Though, if you ask me, actually you could just NOT blur the first channel (only the second one) and save the calculation above, that should work equally well, I think.
Soft Shadows (w/o EA) Demo (99% done, released)
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
-
dEspadas
- Gnoblar
- Posts: 12
- Joined: Sat Mar 15, 2008 7:58 am
Great work! 
Just to let you know, it runs on my FX5200, but I should spare us both from the FPS.
Anyway, I succeed in adding 3 lights before it was just to hard for my poor GPU to move the camera at all. I need an upgrade urgently.
The only thing was that I got some artifacts on the shadows, just don't know if it's something expected due to the oldness of my GPU.
Just to let you know, it runs on my FX5200, but I should spare us both from the FPS.
Anyway, I succeed in adding 3 lights before it was just to hard for my poor GPU to move the camera at all. I need an upgrade urgently.
The only thing was that I got some artifacts on the shadows, just don't know if it's something expected due to the oldness of my GPU.
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Artifacts such as:dEspadas wrote:Great work!
Just to let you know, it runs on my FX5200, but I should spare us both from the FPS.![]()
Anyway, I succeed in adding 3 lights before it was just to hard for my poor GPU to move the camera at all. I need an upgrade urgently.![]()
The only thing was that I got some artifacts on the shadows, just don't know if it's something expected due to the oldness of my GPU.
- pixelized shadows, not "smooth" but more like "rough PCF"? I know about this - I still need to add manual bilinear filtering. The idea is that you need a bilinear filter on the floating point textures, and only recent (GF6000+, HD2000+) cards can do that.
- "wrong" shadows? That's probably your card falling back to byte-based textures if it can't support floating point textures. You can't really store both depth and depth² correctly in a byte texture.
-
dEspadas
- Gnoblar
- Posts: 12
- Joined: Sat Mar 15, 2008 7:58 am
Hmmm, I would say "Yep" to both. If you like i can post a screenshot, but I think you already know the issues.Artifacts such as:
- pixelized shadows, not "smooth" but more like "rough PCF"? I know about this - I still need to add manual bilinear filtering. The idea is that you need a bilinear filter on the floating point textures, and only recent (GF6000+, HD2000+) cards can do that.
- "wrong" shadows? That's probably your card falling back to byte-based textures if it can't support floating point textures. You can't really store both depth and depth² correctly in a byte texture.
Next week I will test it on a 7600GS also, I want to see it runs a little more smoothly.
- pjcast
- OGRE Retired Team Member

- Posts: 2543
- Joined: Fri Oct 24, 2003 2:53 am
- Location: San Diego, Ca
- x 2
- Contact:
Heh, I got it to compile & run on a MacBook Pro (Radeon X1600), and while it runs fast, there are no shadows and rendering looks a little distorted. Unfortunately, I'm not up to speed on shaders, so not sure where to look 
(Only required some minor changes to read media path out of application bundle instead of relative path as before). As well as setting project settings.
(Only required some minor changes to read media path out of application bundle instead of relative path as before). As well as setting project settings.
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/
- pjcast
- OGRE Retired Team Member

- Posts: 2543
- Joined: Fri Oct 24, 2003 2:53 am
- Location: San Diego, Ca
- x 2
- Contact:
And, to show some of the rendering issues:

This is with pressing space a few times to light up the level, and turning off flash light. With the flash light lamp thingy on, there was a slighty different artifiact like some green freckles. I had captured a video, but was 80MB and I didn't want to upload or grab tools to reencode on the Mac.

This is with pressing space a few times to light up the level, and turning off flash light. With the flash light lamp thingy on, there was a slighty different artifiact like some green freckles. I had captured a video, but was 80MB and I didn't want to upload or grab tools to reencode on the Mac.
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Woah! Hm. Looks like the shadow texture is incorrectly sampled/rendered. Can you show me a screen shot of what it looks like with 1 shadowing light?pjcast wrote:And, to show some of the rendering issues:
This is with pressing space a few times to light up the level, and turning off flash light. With the flash light lamp thingy on, there was a slighty different artifiact like some green freckles. I had captured a video, but was 80MB and I didn't want to upload or grab tools to reencode on the Mac.
- pjcast
- OGRE Retired Team Member

- Posts: 2543
- Joined: Fri Oct 24, 2003 2:53 am
- Location: San Diego, Ca
- x 2
- Contact:
This is the demo just starting off (with just flash light):

This is after adding one light:

This is after backing up a little bit:


This is after adding one light:

This is after backing up a little bit:

Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Yup, looks like some kind of shadow map problem. Can you check the format of the shadow textures Ogre makes? It almost looks like you're not getting the type of texture you're asking for.
Something to try: what happens if you comment "btex2D_rg" and uncomment "tex2D" in the shadow() function, where it says "float2 moments =" (in diffuse.cg)? This'll stop the 3x3 blur of the shadow map, which might be causing some type of problem. Also, try switching 00diffuse.material from bilinear filtering to none filtering for the shadow map texture unit. X1600s don't support bilinear floating point filtering either way.
-
Vectrex
- Ogre Magi
- Posts: 1266
- Joined: Tue Aug 12, 2003 1:53 am
- Location: Melbourne, Australia
- x 1
- Contact:
runs great on my 8800GT (about 70 fps with all lights on and 2048 sm), but when anti-aliasing is on (8x) it goes down to 20-30. In fact it doesn't matter what the shadowmap res is, it's still 30, even at 64x64. Whereas a low shadowmap res speeds things up without AA.
I assume something to do with fill-rate?
I assume something to do with fill-rate?
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
With more FSAA you're basically rendering to a framebuffer that's N times bigger than your screen resolution - meaning, you have to process N times more pixels for the lighting shader (done completely per-pixel if you look in diffuse.cg). Since the shadow map stays a fixed resolution, it doesn't really have much to do with the AA.Vectrex wrote:runs great on my 8800GT (about 70 fps with all lights on and 2048 sm), but when anti-aliasing is on (8x) it goes down to 20-30. In fact it doesn't matter what the shadowmap res is, it's still 30, even at 64x64. Whereas a low shadowmap res speeds things up without AA.
I assume something to do with fill-rate?
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
I was actually thinking of that myself, but more like a plugin rather than integrated. Why? Because it's not that simple. The usual Ogre texture shadows are projected, and easily mixed into the fixed function pipeline. However, with these, you need shaders. And your lighting shaders need to manually accept the shadow map and do the shadow themselves. Of course, this is relatively simple since I put all of the shadowing code in a simple "shadow()" function. However, there are still things you need to take into consideration, such as passing in texture_viewproj_matrix, inverse_texture_size, and so on.Angus5 wrote:This should be one of the shadow techniques like "setShadowTechnique(SHADOWTYPE_TEXTURE_SOFT);" or something.
-
jjp
- Silver Sponsor

- Posts: 597
- Joined: Sun Jan 07, 2007 11:55 pm
- Location: Cologne, Germany
- Contact:
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
That's what F.E.A.R. did with it's stencil based "soft" shadows.jjp wrote:What you could do is to vary the position of each light source a few times and render a shadow map for every variation. But that means the shadow for each light will cost a lot more for a reasonable penumbra effect. And it leads to banding artifacts.
- extremely slow, at least on my machine
- extremely ugly at the same time
With shadow mapping there are so many efficient ways to make soft shadows (VSM, implemented in this demo, being one of the fastest), there's no point in "wiggled" shadows.
- sinbad
- OGRE Retired Team Member

- Posts: 19269
- Joined: Sun Oct 06, 2002 11:19 pm
- Location: Guernsey, Channel Islands
- x 67
- Contact:
- twilight17
- Goblin
- Posts: 297
- Joined: Thu Aug 23, 2007 3:47 am
- x 1
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
That'd be me. I know, I sometimes behave like an a55 on the Irrlicht forumstwilight17 wrote:Hey Nullsquared.. are you Agi_Shi from Irrlicht Forums?
and also
Agi_Shi from Newton forums?
- twilight17
- Goblin
- Posts: 297
- Joined: Thu Aug 23, 2007 3:47 am
- x 1
Ahh lol, I see. xDnullsquared wrote:That'd be me. I know, I sometimes behave like an a55 on the Irrlicht forumstwilight17 wrote:Hey Nullsquared.. are you Agi_Shi from Irrlicht Forums?
and also
Agi_Shi from Newton forums?
- eugen
- OGRE Expert User

- Posts: 1422
- Joined: Sat May 22, 2004 5:28 am
- Location: Bucharest
- x 8
- Contact:
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Not out of the box.eugen wrote:is this technique supporting alpha based transparency shdows for casters?
- alpha rejection would be relatively simple
- alpha blending would be relatively the opposite of the simple. The thing with this, is that one object might modulate the colour of the shadow, but another occlude it. So we'd need 2 layers of shadow maps. But what if we had 2 transparent objects and 1 complete occluder? That's 3 layers. Not to mention that we'd need some heavy-a55 compression of the right colours into the floating point textures, unless we make them from RGB to RGBA.
-
mklann
- Kobold
- Posts: 33
- Joined: Sun Jan 21, 2007 7:24 pm
problem with self shadowing and question about other shaders
Hi all,
thanks for this very interesting contribution! I tried the demo and got 70+ fps for a scene with about 200k polygons on my notebook with Quadro FX 570M.
I have three questions though, maybe because I know very little about shaders.
1) When I tried the scene with my own mesh, self-shadowing worked for the flash-light. But when I hit space to create a light at some location, self-shadowing did not work for this light. I also noticed that some surfaces of the mesh received light although they should be shadowed.
I am wondering whether the mesh has to have certain properties to work with this shader?
2) I noticed that when you get very close to a wall, the spot does not stay in the centre (that is where the flash light is pointed at) but wanders off to a corner of the screen. Is that supposed to be like that?
3) We are already using shaders for our models that work with normal and specular maps. What's the best way to combine existing shaders with this one? As I said, I know little about shaders. Is there a way to chain them? Or would we have to extend every shader we might use with the code from this one?
Thanks a lot!
thanks for this very interesting contribution! I tried the demo and got 70+ fps for a scene with about 200k polygons on my notebook with Quadro FX 570M.
I have three questions though, maybe because I know very little about shaders.
1) When I tried the scene with my own mesh, self-shadowing worked for the flash-light. But when I hit space to create a light at some location, self-shadowing did not work for this light. I also noticed that some surfaces of the mesh received light although they should be shadowed.
I am wondering whether the mesh has to have certain properties to work with this shader?
2) I noticed that when you get very close to a wall, the spot does not stay in the centre (that is where the flash light is pointed at) but wanders off to a corner of the screen. Is that supposed to be like that?
3) We are already using shaders for our models that work with normal and specular maps. What's the best way to combine existing shaders with this one? As I said, I know little about shaders. Is there a way to chain them? Or would we have to extend every shader we might use with the code from this one?
Thanks a lot!
- nullsquared
- Old One
- Posts: 3245
- Joined: Tue Apr 24, 2007 8:23 pm
- Location: NY, NY, USA
- x 11
Re: problem with self shadowing and question about other sha
Many factors can result in this... What unit scale is your model? (centimeters/meters/feet/etc.?) It shouldn't really matter, but I've always gotten the best results with models in meters. How complex was it? What was your shadow map resolution? This is really the most basic of basic variance shadow mapping - while it looks really neat and is quite scalable, it doesn't work everywheremklann wrote:Hi all,
thanks for this very interesting contribution! I tried the demo and got 70+ fps for a scene with about 200k polygons on my notebook with Quadro FX 570M.
I have three questions though, maybe because I know very little about shaders.
1) When I tried the scene with my own mesh, self-shadowing worked for the flash-light. But when I hit space to create a light at some location, self-shadowing did not work for this light. I also noticed that some surfaces of the mesh received light although they should be shadowed.
I am wondering whether the mesh has to have certain properties to work with this shader?
If you look at the main.cpp file and handleScene(), you'll notice I always offset the flash light a bit to the lower right of the camera. Otherwise, the shadows wouldn't be visible if the light was 100% matched up with the camera - notice how the shadows of the flash light are always to the left, since it's offset to the right. And this results in the light going off into the corner when up close.2) I noticed that when you get very close to a wall, the spot does not stay in the centre (that is where the flash light is pointed at) but wanders off to a corner of the screen. Is that supposed to be like that?
It shouldn't be too hard. You need to modify your material files to pull in a shadow texture (content_type shadow), just as the demo shows. Then you need to make sure each shader gets the right parameters for the shadowing... after that, it's just a simple matter of copying shadow(...) (and btex2D_rg(...), if used) and modulating your final light be whatever shadow(...) returns.3) We are already using shaders for our models that work with normal and specular maps. What's the best way to combine existing shaders with this one? As I said, I know little about shaders. Is there a way to chain them? Or would we have to extend every shader we might use with the code from this one?
