http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shadow Map



Hi everyone,

My name is Pai-Hung Chen and I am new to this list.  I am using shadow map
to generate real-time shadows in my D3D game.  My ELSA Geforce card supports
direct redering to texture and I've got the technique work to some extent.
However, I still have some questions as follows:  (in the context of
Direct3D)

(1) When redering the shadow map from the light's viewpoint, I think I
should also make sure that ALL vertices of the polygons that are _to be
shadowed_ should appear on the screen as well (from the light's viewpoint),
or I'll have no way to claculate the new clamped texture coordinates for
these shadowed polygons.  Please correct me if I am wrong.  If what I just
said is ture, I think shadow map will have certain restriction on the scene
geometry and I have to take care to choose the right viewing distance when
rendering shadow map from the light's viewpoint to make sure the all the
polygons that are to receive shadows have all their vertices within the
viewing frustum of light's viewpoint.  I hope I am not saying nonsense...

(2) Somehow my shadow are a little off-position after blending with the base
texture on the screen.  I suspect the problem lies in my calculation of
texture coordinate for the shadow map:

D3DMATRIX mWorld;
D3DMATRIX mView;
D3DMATRIX mProjection;
D3DMATRIX mCombined;
D3DVECTOR vTemp;
float fX, fY, fW;

// Setup transformation matrices
D3DUtil_SetIdentityMatrix( mWorld );
D3DUtil_SetViewMatrix( mView, D3DVECTOR( 300.0f, 300.0f, -300.0f ),
                                                     D3DVECTOR( 0.0f, 0.0f,
0.0f ),
                                                     D3DVECTOR( 0.0f, 1.0f,
0.0f ) );
D3DUtil_SetProjectionMatrix( mProjection, 0.8f, 1.0f, 1.0f, 1000.0f );

D3DMath_MatrixMultiply( mCombined, mWorld, mView );
D3DMath_MatrixMultiply( mCombined, mCombined, mProjection );

// Calculate new texture coordinates for shadow map
for each Polygon that is to receive shadow
        fX = mCombined._11 * Polygon.vPosition.dvX
                 + mCombined._21 * Polygon.vPosition.dvY
                 + mCombined._31 * Polygon.vPosition.dvZ
                 + mCombined._41;
        fY = mCombined._12 * Polygon.vPosition.dvX
                 + mCombined._22 * Polygon.vPosition.dvY
                 + mCombined._32 * Polygon.vPosition.dvZ
                 + mCombined._42;
        fW = 1.0f / ( mCombined._14 * Polygon.vPosition.dvX
                             + mCombined._24 * Polygon.vPosition.dvY
                             + mCombined._34 * Polygon.vPosition.dvZ
                             + mCombined._44 );
        Polygon.fU2 = (1.0f + fX * fW) * 0.5f;  // u component of the 2nd
texture coord set
        Polygop.fV2 = (1.0f - fY * fW) * 0.5f;   // v component of the 2nd
texture coord set
end for

Is there anything wrong with the above code?

Any advises are highly appreciated!  Thank you.

Pai-Hung Chen



=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html