Shadow mapping problems

Started by
6 comments, last by _WeirdCat_ 7 years, 4 months ago

Hi,

I'm learning directx 11 and trying to render shadows. Here is my code: http://pastebin.com/XaxvQ4Wv

Result:

screenshot.png

What am I doing wrong?

Advertisement

You need to use a orthagonal projection rather than perspective for shadow buffer a starting point.

The rest looks about right though for using the wrong projection.

edit: Ughh...didnt look at the backface of the box, must of been drunk that day. Apologies.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

You need to use a orthagonal projection rather than perspective for shadow buffer a starting point.

The rest looks about right though for using the wrong projection.

This isn't entirely correct. Should be as following:

Directional Lights

As these lights are "at infinity" (typical example is Sun) their projection is almost non-perspective (actually covering whole Earth with perspective projection from sun, you would need (using average Sun distance) just 0.002443 degrees ~ 8.8 arc seconds - which would be field of view for shadow map covering whole Earth's surface (actually just 1 side, as the second one is in shadow) from Sun's point of view). Also we are mostly considering areas much smaller than Earth - therefore approximating that small field of view using orthogonal projection is good (also we do not have infinite precision for our numbers - and 8.8 arc seconds is already small enough to cause problems).

Therefore directional light is an approximation of point light at such distance that direction from each point in our virtual world to the light is the same vector.

Spot Lights

Are point lights which are somehow blocked and cast light only in one direction (in a "cone" - where origin is the light source, and you also know the direction and the angle). Typical example is flashlight or car lights. For these you definitely want and need perspective projection.

Point Lights

Somehow most generic and most problematic. Perspective projection is one of the ways here - you can't use just one though, you need at least 6 of them - therefore you are basically simulating 1 point light using 6 spotlights. Also there is possibility of using dual-paraboloid shadow maps (just 2 are required)... or technically any other projection as F.e. http://www.cimat.mx/~alberto/Paper.pdf

The real problem with those methods are differences between projected pixel size in the center of resulting shadow map and near the "edge" of hemisphere. Same problem is visible in dual paraboloid shadow maps (but it looks somewhat better than in hemispherical projections). Cube maps have this problem too, although due to actually having 6 projections it is less visible - and a lot of people are still using them (including me), as they just look better compared to other techniques.

Area Lights

I'd say your best bet are paraboloid imperfect shadow maps (assuming you can't just ray trace these scenarios).

Many Point Lights

Generally huge problem (we can handle many lights using tile-based method ... but what is it good for when you can't have shadows from everything?), and I doubt there are any reliable solutions, but they either suffer from huge overdraw (imperfect shadows), performance (ray tracing), somewhat complex pre-processing and not-so-good results (voxel-based methods).

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

My assumption is he wanted simple shadowing, as mentioned, it looks right otherwise.

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

Did You post your shader code somewhere? It looks like you're rendering the shadow map correctly, so I suspect you've made a mistake when you sample the shadow map and do the depth comparison.

Did You post your shader code somewhere? It looks like you're rendering the shadow map correctly, so I suspect you've made a mistake when you sample the shadow map and do the depth comparison.

Yes, here: http://pastebin.com/AZGMmLb2

It looks like you're multiplying the matrices in the opposite order for the lightViewPosition and worldPosition.

didint took a deep look into the codew but you could also you something like normals for each vertex that will interpolate a produce additional mask like:


	if (dot( normalize( vectorAB(light_pos, world_vertex_pos) ), VertexNormal) >= 0.0)
		color = vec4(0.0, 0.0, 0.0, 1.0);

This topic is closed to new replies.

Advertisement