Archived

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

Texture Projection

This topic is 5149 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

I'm trying to project a texture into a surface... but it wont seem to work. I've tried a lot but the picture simply doesnt get projected right. can any1 help me with this please and tell where i'm probably making a mistake: here is a snap shot of what i get this is where i calculate the projection matrix and render the surface:
HRESULT CParsWater::Render(LPDIRECT3DDEVICE8 pDevice)
{

	HRESULT r=0;
    
	// Get the current view matrix

    D3DXMATRIX matView, matInvView;
    pDevice->GetTransform( D3DTS_VIEW, &matView );
    D3DXMatrixInverse( &matInvView,  NULL, &matView );

	// Compute view matrix

    const D3DXVECTOR3 vUp( 0.0f, 0.0f, 1.0f );
	const D3DXVECTOR3 vLookAt( 0.0f, -1.0f, 0.0f );
	const D3DXVECTOR3 vPosition( -800,-1000,1300 );
    D3DXMATRIX matTexView;
    D3DXMatrixLookAtLH( &matTexView, &vPosition, &vLookAt, &vUp );

	// Compute projection matrix

    D3DXMATRIX matTexProj;
    D3DXMatrixPerspectiveFovLH( &matTexProj, D3DX_PI/6, 1.0f, 1.0f, 200.0f );

    D3DXMATRIX matScale;
    D3DXMatrixIdentity( &matScale );
    matScale._11 = 0.5f;
    matScale._22 = 0.5f;

    D3DXMATRIX matBias;
    D3DXMatrixIdentity( &matBias );
    matBias._31 = 0.5f;
    matBias._32 = 0.5f;

    D3DXMATRIX matTexGen;

	D3DXMatrixIdentity( &matTexGen );
	D3DXMatrixMultiply( &matTexGen, &matTexGen, &matInvView ); // Transform cameraspaceposition to worldspace

    D3DXMatrixMultiply( &matTexGen, &matTexGen, &matTexView ); // Transform to worldspace

    D3DXMatrixMultiply( &matTexGen, &matTexGen, &matTexProj ); // Situate verts relative to projector's view

    D3DXMatrixMultiply( &matTexGen, &matTexGen, &matScale );   // Scale and bias to map the near clipping plane to texcoords

    D3DXMatrixMultiply( &matTexGen, &matTexGen, &matBias );    // Scale and bias to map the near clipping plane to texcoords

	
    pDevice->SetTransform( D3DTS_TEXTURE1, &matTexGen );
    pDevice->SetTextureStageState( 1, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3|D3DTTFF_PROJECTED );
    pDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX,  D3DTSS_TCI_CAMERASPACEPOSITION);

	pDevice->SetTexture( 1, m_pDecalMap );
    pDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
    pDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    //pDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );

    //pDevice->SetTextureStageState( 1, D3DTSS_ADDRESSU,  D3DTADDRESS_CLAMP );

    //pDevice->SetTextureStageState( 1, D3DTSS_ADDRESSV,  D3DTADDRESS_CLAMP );

    //pDevice->SetTextureStageState( 1, D3DTSS_MINFILTER, D3DTEXF_LINEAR );

    //pDevice->SetTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );


	
	pDevice->SetVertexShader( PARSVERTEX_TYPE );
	r = pDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, (m_iWidth-1)*(m_iLength-1)*2, m_pVertexList, sizeof(CParsVertex) );


	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
	
	pDevice->SetTexture( 0, NULL );
    pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    pDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
    pDevice->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );

	
	return r;


}
the surface center is located at (-800,-2000,1300) so i project from const D3DXVECTOR3 vPosition( -800,-1000,1300 ); thanx in advance [edited by - Persian_Gamer on November 6, 2003 4:55:22 AM]

Share this post


Link to post
Share on other sites
Im not exactly sure why its not working but I have 2 ideas.
1) are you using a pure device. gettransform doesnt work with that function.

2) why do you need the view matrix? isnt a projected texture independent of where you are?

Share this post


Link to post
Share on other sites