Perspective based shadow mapping

Started by
0 comments, last by MikeyO 18 years, 8 months ago
I've been trying (for the last several days) to implement different kinds of perspective based shadow maps by following the Nvidia SDK's examples.. and I've had little luck so far. Could someone maybe outline the steps for creating a trapezoidal shadow map or perspective shadow map and then use them? By my error, it kind of looks like I'm not transforming the texture coordinates correctly during the useshadowmap pass.. at the same time I must not be creating the LightViewProjection matrix correctly for the first pass either, based on this image: Standard shadow mapping does work with basically the same shaders, just calculating a different LightViewProjection. It would be nice to have a step-by-step or otherwise if anyone has suggestions or links that might help? I could definitely use some more DirectX source code, since all I've been able to find on google relating to TSMs or PSMs is OpenGL. Here is some troublesome code I wasn't sure if I was converting correctly (to C# from C++):

//Nvidia's C++ version:
#define FLT_AS_DW(F) (*(DWORD*)&(F))
#define ALMOST_ZERO(F) ((FLT_AS_DW(F) & 0x7f800000L)==0)
if ( !(ALMOST_ZERO(boxWidth) || ALMOST_ZERO(boxHeight)) )

//C# version:
if( !(((uint)boxWidth & 0x7f800000L) == 0) || (((uint)boxHeight & 0x7f800000L) == 0))

////////////////////////////////////
//Nvidia's C++ version:
const D3DXPLANE& p0 = (i&1)?camPlanes[4] : camPlanes[5];
const D3DXPLANE& p1 = (i&2)?camPlanes[3] : camPlanes[2];
const D3DXPLANE& p2 = (i&4)?camPlanes[0] : camPlanes[1];

//C# Version:
Plane p0 = ((i&1U) != 0U) ? camPlanes[4] : camPlanes[5];
Plane p1 = ((i&2U) != 0U) ? camPlanes[3] : camPlanes[2];
Plane p2 = ((i&4U) != 0U) ? camPlanes[0] : camPlanes[1];

////////////////////////////////////
//Nvidia's C++ version:
#define ALMOST_ZERO(F) ((FLT_AS_DW(F) & 0x7f800000L)==0)
#define IS_SPECIAL(F)  ((FLT_AS_DW(F) & 0x7f800000L)==0x7f800000L)
if ( ALMOST_ZERO(cosTheta) || IS_SPECIAL(cosTheta) )
    return FALSE;

//C# Version
if((((uint)cosTheta & 0x7f800000L) == 0) || (((uint)cosTheta & 0x7f800000L) == 0x7f800000L))
Advertisement
This image also shows the problem(s) in a bit more detail

It looks like the faces that are being drawn into the shadowmap are being projected backwards (opposite to the direction of the light) or something.

This topic is closed to new replies.

Advertisement