Hi, I have a problem with my DirectX9 game.
I created some Real-Time Shadows, but the shadow will pass through objects/terrain, and I don't know why… (my character will also have the shadow on him, in front)
Any ideeas ? Thanks.
Hi, I have a problem with my DirectX9 game.
I created some Real-Time Shadows, but the shadow will pass through objects/terrain, and I don't know why… (my character will also have the shadow on him, in front)
Any ideeas ? Thanks.
This was a problem often seen when shadows was a new feature.
To prevent it, you would need to cast shadows from the terrain as well, not just from the characters. That's the correct solution. For static lights, the SM from static environment ca be precomputed, so at runtime you still only render the character e.g. into a copy of this baked SM.
Another option would be to have some falloff so shadows have limited range. But likely some glitches remain at some spots.
[edit] Ninja'd by JoeJ! [/edit]
It looks to me like the terrain-shadow problem is that your terrain isn't casting a shadow. That is, that presuming that these shadows are produced via shadow-mapping, the terrain isn't being rendered into the shadow-map and thus when shadows are applied to the terrain only the character is present in the shadow-map and so that character-shadow is rendered.
Regarding the shadows on the front of the character, I would guess that a bias in the shadow-mapping might help there, such that shadows are treated as being a little further from the light-source than the surfaces than generate them.
MWAHAHAHAHAHAHA!!!
My Twitter Account: @EbornIan
eduard_ionut said:
(my character will also have the shadow on him, in front)
Well, this sounds like you just project the shadow, but do not compare SM depth with the fragment position to see if it's in front or behind the shadow caster. I would fix this first.
Edit: In case it's just a bias problem, i'm ninja'd too : )
@JoeJ My character will also have his own shadow on him. There will be an infinite shadows from the shadow vector direction..
eduard_ionut said:
My character will also have his own shadow on him. There will be an infinite shadows from the shadow vector direction..
Yeah, that's why you need the depth test.
This image should help:
Basically, the front side of the character which should not be shadowed by itself is the case of the X in the image.
If we look up X in the SM, we get depth values drawn from the green block.
But just because there is something, it does not mean it causes shadow. It causes shadow only behind it, not in front of it. (as seen from the light)
We also have the special case of the X being exactly at the surface of the green block. But we consider this case a front case to prevent self shadowing, and need some small tolerance value called bias to classify this case. Any SM tutorial should help with those details.
I assume what you do is this: Render Character into SM, project SM to scene (all correct), paint everything black where the SM is not empty (wrong, because it misses the front / back classification from depth comparison). Adding this should be pretty easy, and after that you get to the real usual problems like peter panning etc.