🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

DirectX 9 shadow going to infinity bug (front/back)

Started by
12 comments, last by Thaumaturge 2 years, 3 months ago

Hi, I have a weird bug with my DX9 Shadow, without using HLSL:
The shadow will go to infinity, and it will be placed on the entire vector direction of the sun direction. (in front/ back of my objects)

Is there any way of fixing it, any idea ?
Thanks !

DX9 shadow going to infinity bug
Advertisement

Judging by the screenshot, it looks like you're using a shadow-map. Given that, the one thing that comes to mind is that your shadow-buffer is somehow ending up with very small (perhaps zero) depth-values (or maximal depth-values, if DirectX handles depth the other way around) where objects are rendered to it, leading to all objects being considered to be “further away” than the shadow, and thus treated as shadowed.

You say that you're not using HLSL--how, then, are you implementing your shadows, if I may ask?

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

@Thaumaturge 

https://pastebin.com/UkZT48xv

@Thaumaturge That is the original game shadow, using DX8. In my version, I have 2 shadow maps with DX9, but the bug is the same (is easier to watch that original version)

Okay, I think that I see.

In your PasteBin, you indicate that you're using “SetTexture” and “SetTransform” to apply your shadows to other objects. How, then, are you taking into account the depth of the target objects relative to the depth of the shadow-caster?

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

Oh, looking at the pastebin, i think i realize how it's intended to work. There is no depth test at all on the SM, and also there is no self shadowing possible. You only want to draw the shadow to the floor with projective texturing. Like Outcast did, which i think was the first game using SM.

Then the fix would be easy?
Draw the terrain.
Draw the projected shadow.
Only after that draw the character (and buildings). So it receives no shadows.

However, i don't think it's possible to get correct shadows from buildings on the character this way. You could only draw them to the ground as well, but no self shadowing, no shadowing to other architecture, no shadowing to the character.

@JoeJ The depth test is impossible without HLSL ?

You could probably implement a very broad-strokes, inaccurate-but-potentially-workable version by comparing object distances: if the target object is further from the light-source than the shadow-casting object, apply the shadow; if not, don't.

(This would, however, not work well with large objects, like buildings--unless they were split into smaller objects. Which itself might come with some considerations.)

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

eduard_ionut said:
The depth test is impossible without HLSL ?

It is possible since the introduction of pixel shaders. So DX9 can do it.

On your side i would ditch the current hacky solution and implement standard depth based shadow maps instead. It's some things to change, but it works. Tutorials should be easy to find, and after that less issues on the long run.
There is no more reason to use such hacky shadows on any current hardware. It's not even faster. And it never worked robustly in any game.

If feasible, I do agree that shaders would likely be the better solution.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement