Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MothaBrain

Softshadows of cars on uneven ground

This topic is 6136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I''d like to implent soft shadows to the cars in my game; mostly on uneven ground. Perhaps you know the demo of the new (and great) Championship Rally Xtreme, their shadows look like as I''d like to do it. Does anyone of you know an approach to the problem. Is it solved geometrically or by stencil buffer? Thanks! Robert http://www.moonbyte.de

Share this post


Link to post
Share on other sites
Advertisement
Well I know Rally Championship Xtreme since it''s being developed in the office downstairs from ours, and I know the original Rally Championship since I worked on it so I''ll give a hint based on what I know (I''m not personally involved in Xtreme this time, but do know a bit of what they''re doing):

Projected textures (shadow mapping) - recieving surfaces are multitextured with the shadow texture in a later stage, the coordinates come from automatic texture coordinate generation (TexGen). Game Programming Gems 1 has a good article on the technique.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thanks for the information!
Well, so my main problem will be to find the "involved" polygons that receive shadow and than generate the tex coords of the shadow map for them?
I thought I noticed, that the shadows changed when I rotated the car, is it possible with static shadowmaps?

BTW, (I think, you''re better informed than me )
does Warthog has an own site?

Thanks!

Robert
http://www.moonbyte.de

Share this post


Link to post
Share on other sites
Think of dynamic lightmaps - it stretches and shapes round the destination geometry.

Assuming you have a shadow map texture generated, you would draw the destination/reciever geometry texture in stage 0 and set the shadow map texture in stage 1:

  
// tex coords = position of a vertex in camera space

SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION|1 );

// want to apply the texture transform nmatrix

// then divide by the last component to project into 2d coords

SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3|D3DTTFF_PROJECTED );

// make a matrix which transforms texture coordinates from

// camera space (see above) into world space

D3DXMATRIX mView, mInvView;
GetTransform( D3DTRANSFORMSTATE_VIEW, (D3DMATRIX*)&mView );
float det = 0.0f;
D3DXMatrixInverse(&mInvView, &det, &mView);
Matrix mIV(mInvView);

// make a matrix which accounts for texture coordinates being

// in the range of 0 to 1 rather that -1 to 1 (or -0.5 to 0.5)

Matrix mTS;
mTS.Identity();
mTS.m_mat._11 = 0.5f; // scale

mTS.m_mat._22 = -0.5f;
mTS.m_mat._33 = 0.0f;
mTS.m_mat._41 = 0.5f; // offset

mTS.m_mat._42 = 0.5f;
mTS.m_mat._43 = 1.0f;
mTS.m_mat._44 = 1.0f;

// make a view matrix which represents the view from the light

// think of a camera positioned at the light point and pointing

// in the same direction. This is the same type of view matrix

// as the standard view matrix

mWorldToLight.Identity();
mWorldToLight.View( light.vPosition, centre, 0, Vector(0,1,0) );

// make a projection matrix representing the projection of the

// blocker (the object casting the shadow) onto the shadow map

// texture and on to the destination geometry.

// The settings here are almost the same as they would be for

// your standard projection matrix. znear and zfar are the clip

// planes - as usual.

float znear = 4.01f;
float zfar = 4096.1f;
float Q = zfar / ( zfar - znear );
Matrix mBlockerProjection;
mBlockerProjection.Identity();
mBlockerProjection.m_mat._11 = 1;
mBlockerProjection.m_mat._22 = 1;
mBlockerProjection.m_mat._33 = Q;
mBlockerProjection.m_mat._34 = 1.0f;
mBlockerProjection.m_mat._43 = -Q * znear;

// concatenate all the matrices to make a single matrix which

// transforms from CAMERA SPACE into the projected shadow space

Matrix mShad;
mShad = mTS * mBlockerProjection * mWorldToLight * mIV;

// set the transformation matrix for texture coordinates in D3D

SetTransform( D3DTRANSFORMSTATE_TEXTURE1, (D3DMATRIX*)&mShad );




Warthog''s website is: www.warthog.co.uk

Also of interest if you like RC-Extreme: www.platinum-interactive.co.uk


To clarify for anyone confused about my involvement/location - I work for Creative Asylum Limited who are a separate company to Warthog, but we (& Platinum who are another separate company) rent office space in a building Warthog own.

We''re pretty close and help each others companies out.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Hi!

3 game developer firms in a single building, cool thing
Nice opportunity to ask someone else if you don''t know how
to do something.

Thanks for the code!
I think I understood most of it but I''m still using software - that means my own - transforming in DX6
So I have yet another question since I don''t understand the new commands:

At the end of your code snippet you''re "transforming" the tex coords for the shadow maps with the final matrix. This function affects the values of the shadow maps tex coords but what are their original values before the transform?
Oh, new thought, maybe the first line you noticed "position of a vertex in camera space"? Think so...

Thanks for your help.

Robert
http://www.moonbyte.de

Share this post


Link to post
Share on other sites
quote:
Oh, new thought, maybe the first line you noticed "position of a vertex in camera space"? Think so...


Correct.

The line:

SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION|1 );

Tells D3D to automatically generate texture coordinates for texture stage 1. The coordinates correspond to the position of the 3d vertex (x,y,z) after it has been transformed into camera space (ie. after D3D/the graphics card has multiplied it by the world and view matrices).

The final |1 tells D3D to use texture coordinate set 1 with stage 1.

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!