示例#1
0
//-----------------------------------------------------------------------------
// Name: ApplyEnvironmentMap()
// Desc: Performs a calculation on each of the vertices' normals to determine
//       what the texture coordinates should be for the environment map (in this 
//       case the bump map).
//-----------------------------------------------------------------------------
VOID CMyD3DApplication::ApplyEnvironmentMap()
{
    EMBOSSVERTEX* pv;
    DWORD         dwNumVertices;
    dwNumVertices = m_pObject->GetLocalMesh()->GetNumVertices();

    LPDIRECT3DVERTEXBUFFER8 pVB;
    m_pObject->GetLocalMesh()->GetVertexBuffer( &pVB );
    pVB->Lock( 0, 0, (BYTE**)&pv, 0 );

    // Get the World matrix
    D3DXMATRIX  WV,InvWV;
    m_pd3dDevice->GetTransform( D3DTS_WORLD, &WV );
    D3DXMatrixInverse( &InvWV, NULL, &WV );
    
    // Get the current light position in object space
    D3DXVECTOR4 vTransformed;
    D3DXVec3Transform( &vTransformed, (D3DXVECTOR3*)&m_Light.Position, &InvWV );
    m_vBumpLightPos.x = vTransformed.x;
    m_vBumpLightPos.y = vTransformed.y;
    m_vBumpLightPos.z = vTransformed.z;

    // Dimensions of texture needed for shifting tex coords
    D3DSURFACE_DESC d3dsd;
    m_pEmbossTexture->GetLevelDesc( 0, &d3dsd );
    
    // Loop through the vertices, transforming each one and calculating
    // the correct texture coordinates.
    for( WORD i = 0; i < dwNumVertices; i++ )
    {
        // Find light vector in tangent space
        D3DXVECTOR3 vLightToVertex;
        D3DXVec3Normalize( &vLightToVertex, &(m_vBumpLightPos - pv[i].p) );
        
        // Create rotation matrix (rotate into tangent space)
        FLOAT r = D3DXVec3Dot( &vLightToVertex, &pv[i].n );

        if( r < 0.f ) 
        {
            // Don't shift coordinates when light below surface
            pv[i].tu2 = pv[i].tu;
            pv[i].tv2 = pv[i].tv;
        }
        else
        {
            // Shift coordinates for the emboss effect
            D3DXVECTOR2 vEmbossShift;
            vEmbossShift.x = D3DXVec3Dot( &vLightToVertex, &m_pTangents[i] );
            vEmbossShift.y = D3DXVec3Dot( &vLightToVertex, &m_pBinormals[i] );
            D3DXVec2Normalize( &vEmbossShift, &vEmbossShift );
            pv[i].tu2 = pv[i].tu + vEmbossShift.x/d3dsd.Width;
            pv[i].tv2 = pv[i].tv - vEmbossShift.y/d3dsd.Height;
        }
    }

    pVB->Unlock();
    pVB->Release();
}
示例#2
0
// Loads a font texture and sets it as current font to display
BOOL	D3D_LoadFontTextureByFile ( char *file_path )
{
	D3DSURFACE_DESC desc;

	// Free our old texture
	if (m_pFontTexture)
		m_pFontTexture->Release();

	// Try to load it
	if ( !(D3D_OK == D3DXCreateTextureFromFile ( m_pOrigDDevice, file_path, &m_pFontTexture )) )
		return FALSE;

	m_pFontTexture->GetLevelDesc( 0, &desc );
	m_uiFontWidth = desc.Width;
	m_uiFontHeight = desc.Height;

	return TRUE;
}
示例#3
0
void KRipper8::Dump_TextureDesc2Log( IDirect3DBaseTexture8* pTexture ){

    if( !pTexture )
        return;

    D3DRESOURCETYPE Type = pTexture->GetType();

    g_pLog->Write( L"-----Texture desc-----\n" );
    g_pLog->Write( L"Level count: %u\n", pTexture->GetLevelCount() );
    g_pLog->Write( L"Type: %s\n", D3DRESOURCETYPE_2Str( pTexture->GetType() ) );
    g_pLog->Write( L"----------------------\n" );
    HRESULT hr;
    if( Type == D3DRTYPE_TEXTURE )
    {
        LPDIRECT3DTEXTURE8 pTex = static_cast <LPDIRECT3DTEXTURE8>( pTexture );
        D3DSURFACE_DESC desc;
        ZeroMemory( &desc, sizeof( desc ) );
        hr = pTex->GetLevelDesc( 0, &desc );
        if( SUCCEEDED( hr ) )
        {
            g_pLog->Write( L"Format: %s\n", D3DFORMAT_2Str( desc.Format ) );
            g_pLog->Write( L"Type  : %s\n", D3DRESOURCETYPE_2Str( desc.Type ) );
            g_pLog->Write( L"Usage : %s\n", D3DUSAGE_2Str( desc.Usage ) );
            g_pLog->Write( L"Pool  : %s\n", D3DPOOL_2Str( desc.Pool ) );
            g_pLog->Write( L"Size  : %u\n", desc.Size );
            g_pLog->Write( L"MultiSampleType: %s\n", D3DMULTISAMPLE_2Str( desc.MultiSampleType ) );
            g_pLog->Write( L"Width : %d\n", desc.Width );
            g_pLog->Write( L"Height: %d\n", desc.Height );
        }
        else
        {
            g_pLog->Write( L"IDirect3DTexture8::GetLevelDesc() error: 0x%08X\n", hr );
        }
    }
    else if( Type == D3DRTYPE_VOLUMETEXTURE )
    {//VOLUME
        LPDIRECT3DVOLUMETEXTURE8 pTex = static_cast <LPDIRECT3DVOLUMETEXTURE8>( pTexture );
        D3DVOLUME_DESC desc;
        ZeroMemory( &desc, sizeof( desc ) );
        hr = pTex->GetLevelDesc( 0, &desc );
        if( SUCCEEDED( hr ) ){
            g_pLog->Write( L"Format: %s\n", D3DFORMAT_2Str( desc.Format ) );
            g_pLog->Write( L"Type  : %s\n", D3DRESOURCETYPE_2Str( desc.Type ) );
            g_pLog->Write( L"Usage : %s\n", D3DUSAGE_2Str( desc.Usage ) );
            g_pLog->Write( L"Pool  : %s\n", D3DPOOL_2Str( desc.Pool ) );
            g_pLog->Write( L"Size  : %u\n", desc.Size );
            g_pLog->Write( L"Width : %d\n", desc.Width );
            g_pLog->Write( L"Height: %d\n", desc.Height );
            g_pLog->Write( L"Depth : %d\n", desc.Depth );
        }
        else{
            g_pLog->Write( L"IDirect3DVolumeTexture8::GetLevelDesc() error: 0x%08X\n", hr );
        }
    }
    else if( Type == D3DRTYPE_CUBETEXTURE )
    {//CUBE
        LPDIRECT3DCUBETEXTURE8 pTex = static_cast <LPDIRECT3DCUBETEXTURE8>( pTexture );
        D3DSURFACE_DESC desc;
        ZeroMemory( &desc, sizeof( desc ) );
        hr = pTex->GetLevelDesc( 0, &desc );
        if( SUCCEEDED( hr ) )
        {
            g_pLog->Write( L"Format: %s\n", D3DFORMAT_2Str( desc.Format ) );
            g_pLog->Write( L"Type  : %s\n", D3DRESOURCETYPE_2Str( desc.Type ) );
            g_pLog->Write( L"Usage : %s\n", D3DUSAGE_2Str( desc.Usage ) );
            g_pLog->Write( L"Pool  : %s\n", D3DPOOL_2Str( desc.Pool ) );
            g_pLog->Write( L"Size  : %u\n", desc.Size );
            g_pLog->Write( L"MultiSampleType: %s\n", D3DMULTISAMPLE_2Str( desc.MultiSampleType ) );
            g_pLog->Write( L"Width : %d\n", desc.Width );
            g_pLog->Write( L"Height: %d\n", desc.Height );
        }
        else
        {
            g_pLog->Write( L"IDirect3DCubeTexture8::GetLevelDesc() error: 0x%08X\n", hr );
        }    
    }


    g_pLog->Write( L"----------------------\n" );
}