# texture projection

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

## 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 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 on other sites
Quote:
 Original post by DaveHey 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))

##### 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 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 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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632631
• Total Posts
3007538
• ### Who's Online (See full list)

There are no registered users currently online

×