Sign in to follow this  
nini

texture projection

Recommended Posts

hi for all , i'm searching for good and easy to understand explanation of texture projection (i mean projective texture) ;-)(i'm trying to implement shadow maps with DirectX but i don't know how to build a projection matrix for texture coordinate from a point and a direction )... thanx by advance for your help

Share this post


Link to post
Share on other sites
Hey bud,

This is roughly how to do it:

1. Calculate the worldViewProj matrix for the light source.

2. Transform the vertex position into the clip space of the light source.

3. In the first pass you want to render a depth texture. Do this by taking the light-clip-space position and finding the distance between it and the light position.

4. The depth texture now contains the front face of the whole scene from the lights point of view. You should output the distance in one or all of the channels of the output colour. Find this value as a floating point number between 0 and 1 by working out the distance as a portion of the lights range, clipping it to the range of 0 and 1 using the saturate() intrinsic.

5. To project the shadow you do a second pass, transforming the position into the lights clip space. Make sure that this time you are outputting the position of the vertex into camera clip space, keeping the light-clip space as a temporary.

6. Convert the light-clip-space position into screen space and sample from the depth texture.

7. Do the distance calculation on the light-clip-space position and if it is greater than the distance stored in the depth texture then you know the vertex is in shadow.

Hope that guides you somewhat. I assumed that you know about shaders and basic matrix and vector maths. If you don't then ask away...

Dave

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave
Hey bud,
This is roughly how to do it...



thanx , i already know this process to compare the depth but what i need is an explanation on the building of a projection matrix from a light point because it isn't real shadowmapping that i want but lightmap eg projecting the image rendered from the point of view of the light back to receivers of shadow...

from know i've got the code for rendering into a texture the shadow caster , but i dont know how to project onto the receiver(i need a matrix to set to in DirectX D3DTS_TEXTUREn))

thanx in advance...

Share this post


Link to post
Share on other sites
Hi, ok, well i just did this:

D3DXMatrixLookAtLH( &matLightView, &lightPos, &lightLookAt, &vUpVec );
D3DXMatrixPerspectiveFovLH( &matLightProj, D3DX_PI/8, 1, 0.0f, 500.0f );
D3DXMatrixPerspectiveFovLH( &matLightEyeProj, D3DX_PI/4, 1, 1.0f, 100.0f


matLightProj is for the cone of the spotlight projection and matLightEyeProj is so the light can see the whole scene.

Dave

Share this post


Link to post
Share on other sites
Which matrix should i pass to transform the camera space position to uv coords ?

actually before rendering my object i have :

dev->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,D3DTFF_CAMERASPACEPOSITION
|D3DTFF_PROJECTED);

dev->SetTransform(D3DTS_TEXTURE1,&MatUV);

what should i give to DirectX as MatUV ?
is this a projection matrix that project vertices to lightSpace because if i send my objectTolightSpace matrix the texture is projected but when i move the view (the camera) in the scene , the texture will move with the view....

i'm stucked here because i have no knowledge about maths behind i think

thanx for any help guys...

i made a mistake above , my code is like this (tss is just a macro for dev->SetTextureStageState)

tss(dev,1,D3DTSS_TEXCOORDINDEX,D3DTSS_TCI_CAMERASPACEPOSITION);
tss(dev,1,D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_PROJECTED | D3DTTFF_COUNT3);



[Edited by - nini on March 6, 2006 9:50:57 AM]

Share this post


Link to post
Share on other sites
OK , guys , i found where the problem is , i forgot to supply the inverse of the camera transform that's why my texture was tracking the camera movement...

in order to project correctly you must set this transform :

Inverse of the camera view transform * Light View Transform * Light Proj Transform

the projection is now ok.

thanx for your responses Dave.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this