Original Post
DrawIndexedPrimitive return :Vertex shader function usage (D3DDECLUSAGE_TEXCOORD,1) does not have corresponding usage in the current vertex declaration! Why? ///////////////////////// ///////////////////////// ps_1.vsh //////////////////////// //////////////////////// vs_1.psh /////////////////////////// .h file [Edited by - iGoo on July 13, 2004 11:09:08 AM]
//-----------------------------------------------------------------------------
// File: ps_1.cpp
//
// Desc: DirectX window application created by the DirectX AppWizard
//-----------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <basetsd.h>
#include <math.h>
#include <stdio.h>
#include <d3dx9.h>
#include <dxerr9.h>
#include <tchar.h>
#include "DXUtil.h"
#include "D3DEnumeration.h"
#include "D3DSettings.h"
#include "D3DApp.h"
#include "D3DFile.h"
#include "D3DUtil.h"
#include "resource.h"
#include "ps_1.h"
//-----------------------------------------------------------------------------
// Global access to the app (needed for the global WndProc())
//-----------------------------------------------------------------------------
CMyD3DApplication* g_pApp = NULL;
HINSTANCE g_hInst = NULL;
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Idle time is used to render the scene.
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
CMyD3DApplication d3dApp;
g_pApp = &d3dApp
g_hInst = hInst;
InitCommonControls();
if( FAILED( d3dApp.Create( hInst ) ) )
return 0;
return d3dApp.Run();
}
//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Application constructor. Paired with ~CMyD3DApplication()
// Member variables should be initialized to a known state here.
// The application window has not yet been created and no Direct3D device
// has been created, so any initialization that depends on a window or
// Direct3D should be deferred to a later stage.
//-----------------------------------------------------------------------------
CMyD3DApplication::CMyD3DApplication()
{
m_dwCreationWidth = 500;
m_dwCreationHeight = 375;
m_strWindowTitle = TEXT( "ps_1" );
m_d3dEnumeration.AppUsesDepthBuffer = TRUE;
m_bStartFullscreen = false;
m_bShowCursorWhenFullscreen = false;
m_pFont = NULL;
m_bLoadingApp = TRUE;
ZeroMemory( &m_UserInput, sizeof(m_UserInput) );
m_fWorldRotX = 0.0f;
m_fWorldRotY = 0.0f;
m_pIB = NULL;
m_pVB = NULL;
m_pDecl = NULL;
m_pVShader = NULL;
m_pPShader = NULL;
m_dwNumVertices = 0;
m_dwNumFaces = 0;
// Read settings from registry
ReadSettings();
}
//-----------------------------------------------------------------------------
// Name: ~CMyD3DApplication()
// Desc: Application destructor. Paired with CMyD3DApplication()
//-----------------------------------------------------------------------------
CMyD3DApplication::~CMyD3DApplication()
{
}
//-----------------------------------------------------------------------------
// Name: OneTimeSceneInit()
// Desc: Paired with FinalCleanup().
// The window has been created and the IDirect3D9 interface has been
// created, but the device has not been created yet. Here you can
// perform application-related initialization and cleanup that does
// not depend on a device.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::OneTimeSceneInit()
{
// TODO: perform one time initialization
// Drawing loading status message until app finishes loading
SendMessage( m_hWnd, WM_PAINT, 0, 0 );
m_bLoadingApp = FALSE;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: ReadSettings()
// Desc: Read the app settings from the registry
//-----------------------------------------------------------------------------
VOID CMyD3DApplication::ReadSettings()
{
HKEY hkey;
if( ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER, DXAPP_KEY,
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ) )
{
// TODO: change as needed
// Read the stored window width/height. This is just an example,
// of how to use DXUtil_Read*() functions.
DXUtil_ReadIntRegKey( hkey, TEXT("Width"), &m_dwCreationWidth, m_dwCreationWidth );
DXUtil_ReadIntRegKey( hkey, TEXT("Height"), &m_dwCreationHeight, m_dwCreationHeight );
RegCloseKey( hkey );
}
}
//-----------------------------------------------------------------------------
// Name: WriteSettings()
// Desc: Write the app settings to the registry
//-----------------------------------------------------------------------------
VOID CMyD3DApplication::WriteSettings()
{
HKEY hkey;
if( ERROR_SUCCESS == RegCreateKeyEx( HKEY_CURRENT_USER, DXAPP_KEY,
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ) )
{
// TODO: change as needed
// Write the window width/height. This is just an example,
// of how to use DXUtil_Write*() functions.
DXUtil_WriteIntRegKey( hkey, TEXT("Width"), m_rcWindowClient.right );
DXUtil_WriteIntRegKey( hkey, TEXT("Height"), m_rcWindowClient.bottom );
RegCloseKey( hkey );
}
}
//-----------------------------------------------------------------------------
// Name: ConfirmDevice()
// Desc: Called during device initialization, this code checks the display device
// for some minimum set of capabilities
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS9* pCaps, DWORD dwBehavior,
D3DFORMAT Format )
{
UNREFERENCED_PARAMETER( Format );
UNREFERENCED_PARAMETER( dwBehavior );
UNREFERENCED_PARAMETER( pCaps );
BOOL bCapsAcceptable;
// TODO: Perform checks to see if these display caps are acceptable.
bCapsAcceptable = TRUE;
if( bCapsAcceptable )
return S_OK;
else
return E_FAIL;
}
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Paired with DeleteDeviceObjects()
// The device has been created. Resources that are not lost on
// Reset() can be created here -- resources in D3DPOOL_MANAGED,
// D3DPOOL_SCRATCH, or D3DPOOL_SYSTEMMEM. Image surfaces created via
// CreateOffScreenPlainSurface are never lost and can be created here. Vertex
// shaders and pixel shaders can also be created here as they are not
// lost on Reset().
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
// TODO: create device objects
HRESULT hr;
// Initialize the font
HDC hDC = GetDC( NULL );
int nHeight = -MulDiv( 12, GetDeviceCaps(hDC, LOGPIXELSY), 72 );
ReleaseDC( NULL, hDC );
if( FAILED( hr = D3DXCreateFont( m_pd3dDevice, nHeight, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
TEXT("Arial"), &m_pFont ) ) )
return DXTRACE_ERR( "D3DXCreateFont", hr );
//-------------------------------------------------------------
// Init
//-------------------------------------------------------------
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, // v0
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, // v3
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, // v7
{ 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 }, // v8
D3DDECL_END()
};
if(FAILED(hr = m_pd3dDevice->CreateVertexDeclaration(decl, &m_pDecl)))
return DXTRACE_ERR("decl vs", hr);
LPDIRECT3DTEXTURE9 pHeightMap = 0;
if( FAILED( hr = D3DXCreateTextureFromFile( m_pd3dDevice, "earth.bmp", &m_pColorTex ) ) )
DXTRACE_ERR("Load color tex err", hr);
if( FAILED( hr = D3DXCreateTextureFromFile( m_pd3dDevice, "earthbump.bmp", &pHeightMap ) ) )
DXTRACE_ERR("Load bump tex err", hr);
D3DSURFACE_DESC desc;
pHeightMap->GetLevelDesc(0, &desc);
if( FAILED( hr = D3DXCreateTexture( m_pd3dDevice, desc.Width, desc.Height, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pNormalMap ) ) )
return DXTRACE_ERR("Create Normail map err", hr);
D3DXComputeNormalMap(m_pNormalMap, pHeightMap, NULL, 0, D3DX_CHANNEL_RED, 10);
SAFE_RELEASE(pHeightMap);
// Create && Assem Shaders
LPD3DXBUFFER pCode = NULL;
if(FAILED(hr = D3DXAssembleShaderFromFile("vs_1.vsh", NULL, NULL, D3DXSHADER_DEBUG, &pCode, NULL)))
return DXTRACE_ERR("Assem vs", hr);
if(FAILED(hr = m_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(), &m_pVShader)))
return DXTRACE_ERR("Create vs", hr);
SAFE_RELEASE(pCode);
if(FAILED(hr = D3DXAssembleShaderFromFile("ps_1.psh", NULL, NULL, D3DXSHADER_DEBUG, &pCode, NULL)))
return DXTRACE_ERR("Assem ps", hr);
if(FAILED(hr = m_pd3dDevice->CreatePixelShader((DWORD*)pCode->GetBufferPointer(), &m_pPShader)))
return DXTRACE_ERR("Create ps", hr);
SAFE_RELEASE(pCode);
// End: Create && Assem Shaders
//-------------------------------------------------------------
// End Init
//-------------------------------------------------------------
//------------------------------------------------------------
// Load Mesh
//------------------------------------------------------------
LPD3DXMESH pMeshSysMem = 0, pMeshSysMem2 = 0;
char cPath[256];
if( FAILED( hr = DXUtil_FindMediaFileCb( cPath, sizeof(cPath), "sphere.x" )))
return DXTRACE_ERR( "find Mesh", hr);
if( FAILED( hr = D3DXLoadMeshFromX( cPath, D3DXMESH_SYSTEMMEM, m_pd3dDevice, 0, 0, 0, 0, &pMeshSysMem ) ) )
return DXTRACE_ERR( "Load mesh", hr );
if( FAILED( hr = pMeshSysMem->CloneMesh( D3DXMESH_MANAGED, decl, m_pd3dDevice, &pMeshSysMem2 ) ) )
return DXTRACE_ERR( "clone mesh err", hr );
if( FAILED( hr = D3DXComputeNormals( pMeshSysMem, NULL ) ) )
return DXTRACE_ERR( "computer normal", hr );
if( FAILED( hr = D3DXComputeTangent( pMeshSysMem2, 0, 0, 0, TRUE, 0 ) ) )
return DXTRACE_ERR( "compute tangent", hr );
SAFE_RELEASE( pMeshSysMem );
pMeshSysMem2->GetVertexBuffer( &m_pVB );
pMeshSysMem2->GetIndexBuffer( &m_pIB );
m_dwNumVertices = pMeshSysMem2->GetNumVertices();
m_dwNumFaces = pMeshSysMem2->GetNumFaces();
SAFE_RELEASE( pMeshSysMem2 );
//------------------------------------------------------------
// End Load Mesh
//------------------------------------------------------------
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Paired with InvalidateDeviceObjects()
// The device exists, but may have just been Reset(). Resources in
// D3DPOOL_DEFAULT and any other device state that persists during
// rendering should be set here. Render states, matrices, textures,
// etc., that don't change during rendering can be set once here to
// avoid redundant state setting during Render() or FrameMove().
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RestoreDeviceObjects()
{
// TODO: setup render states
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pd3dDevice->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
D3DXMatrixIdentity( &m_matW );
// Set up our view matrix. A view matrix can be defined given an eye point,
// a point to lookat, and a direction for which way is up. Here, we set the
// eye five units back along the z-axis and up three units, look at the
// origin, and define "up" to be in the y-direction.
D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -25.0f );
D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &m_matV, &vFromPt, &vLookatPt, &vUpVec );
// Set the projection matrix
FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height;
D3DXMatrixPerspectiveFovLH( &m_matP, D3DX_PI/4, fAspect, 1.0f, 100.0f );
if( m_pFont )
m_pFont->OnResetDevice();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FrameMove()
// Desc: Called once per frame, the call is the entry point for animating
// the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FrameMove()
{
// TODO: update world
// Update user input state
UpdateInput( &m_UserInput );
// Update the world state according to user input
D3DXMATRIX matRotY;
D3DXMATRIX matRotX;
if( m_UserInput.bRotateLeft && !m_UserInput.bRotateRight )
m_fWorldRotY += m_fElapsedTime;
else if( m_UserInput.bRotateRight && !m_UserInput.bRotateLeft )
m_fWorldRotY -= m_fElapsedTime;
if( m_UserInput.bRotateUp && !m_UserInput.bRotateDown )
m_fWorldRotX += m_fElapsedTime;
else if( m_UserInput.bRotateDown && !m_UserInput.bRotateUp )
m_fWorldRotX -= m_fElapsedTime;
D3DXMatrixRotationX( &matRotX, m_fWorldRotX );
D3DXMatrixRotationY( &matRotY, m_fWorldRotY );
D3DXMatrixMultiply( &m_matW, &matRotX, &matRotY );
D3DXVECTOR4 half(0.5f, 0.5f, 0.5f, 0.5f);
m_pd3dDevice->SetVertexShaderConstantF(33, (float*)½, 1);
float fTime = (float)GetTickCount() / 1000.0f;
m_LightDir = D3DXVECTOR4(fabsf(sinf(fTime)), 0.0f, fabsf(cosf(fTime)), 0.0f);
D3DXVec4Normalize(&m_LightDir, &m_LightDir);
m_pd3dDevice->SetVertexShaderConstantF(12, (float*)&m_LightDir, 1);
D3DXMATRIX matShader;
matShader = m_matW * m_matV * m_matP;
D3DXMatrixTranspose(&matShader, &matShader);
m_pd3dDevice->SetVertexShaderConstantF(8, (float*)&matShader, 4);
D3DXMATRIX matTemp;
D3DXMatrixTranspose(&matTemp, &m_matW);
m_pd3dDevice->SetVertexShaderConstantF(0, (float*)&matTemp, 4);
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateInput()
// Desc: Update the user input. Called once per frame
//-----------------------------------------------------------------------------
void CMyD3DApplication::UpdateInput( UserInput* pUserInput )
{
pUserInput->bRotateUp = ( m_bActive && (GetAsyncKeyState( VK_UP ) & 0x8000) == 0x8000 );
pUserInput->bRotateDown = ( m_bActive && (GetAsyncKeyState( VK_DOWN ) & 0x8000) == 0x8000 );
pUserInput->bRotateLeft = ( m_bActive && (GetAsyncKeyState( VK_LEFT ) & 0x8000) == 0x8000 );
pUserInput->bRotateRight = ( m_bActive && (GetAsyncKeyState( VK_RIGHT ) & 0x8000) == 0x8000 );
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Called once per frame, the call is the entry point for 3d
// rendering. This function sets up render states, clears the
// viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Render()
{
// Clear the viewport
m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x000000ff, 1.0f, 0L );
// Begin the scene
if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
// TODO: render world
m_pd3dDevice->SetTexture(1, m_pColorTex);
m_pd3dDevice->SetTexture(0, m_pNormalMap);
m_pd3dDevice->SetIndices(m_pIB);
m_pd3dDevice->SetStreamSource(0, m_pVB, 0, sizeof(ShaderVertex));
m_pd3dDevice->SetVertexShader(m_pVShader);
m_pd3dDevice->SetVertexDeclaration(m_pDecl);
m_pd3dDevice->SetPixelShader(m_pPShader);
m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_dwNumVertices, 0, m_dwNumFaces);
// Render stats and help text
RenderText();
// End the scene.
m_pd3dDevice->EndScene();
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RenderText()
// Desc: Renders stats and help text to the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::RenderText()
{
D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,255,0);
TCHAR szMsg[MAX_PATH] = TEXT("");
RECT rct;
ZeroMemory( &rct, sizeof(rct) );
rct.left = 2;
rct.right = m_d3dsdBackBuffer.Width - 20;
// Output display stats
INT nNextLine = 40;
lstrcpy( szMsg, m_strDeviceStats );
nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
lstrcpy( szMsg, m_strFrameStats );
nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
// Output statistics & help
nNextLine = m_d3dsdBackBuffer.Height;
wsprintf( szMsg, TEXT("Arrow keys: Up=%d Down=%d Left=%d Right=%d"),
m_UserInput.bRotateUp, m_UserInput.bRotateDown, m_UserInput.bRotateLeft, m_UserInput.bRotateRight );
nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
sprintf( szMsg, TEXT("World State: %0.3f, %0.3f"),
m_fWorldRotX, m_fWorldRotY );
nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
lstrcpy( szMsg, TEXT("Use arrow keys to update input") );
nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
lstrcpy( szMsg, TEXT("Press 'F2' to configure display") );
nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: Overrrides the main WndProc, so the sample can do custom message
// handling (e.g. processing mouse, keyboard, or menu commands).
//-----------------------------------------------------------------------------
LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam )
{
switch( msg )
{
case WM_PAINT:
{
if( m_bLoadingApp )
{
// Draw on the window tell the user that the app is loading
// TODO: change as needed
HDC hDC = GetDC( hWnd );
TCHAR strMsg[MAX_PATH];
wsprintf( strMsg, TEXT("Loading... Please wait") );
RECT rct;
GetClientRect( hWnd, &rct );
DrawText( hDC, strMsg, -1, &rct, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
ReleaseDC( hWnd, hDC );
}
break;
}
}
return CD3DApplication::MsgProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Invalidates device objects. Paired with RestoreDeviceObjects()
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InvalidateDeviceObjects()
{
// TODO: Cleanup any objects created in RestoreDeviceObjects()
if( m_pFont )
m_pFont->OnLostDevice();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DeleteDeviceObjects()
// Desc: Paired with InitDeviceObjects()
// Called when the app is exiting, or the device is being changed,
// this function deletes any device dependent objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::DeleteDeviceObjects()
{
// TODO: Cleanup any objects created in InitDeviceObjects()
SAFE_RELEASE( m_pFont );
SAFE_RELEASE( m_pFont );
SAFE_RELEASE( m_pVB );
SAFE_RELEASE( m_pIB );
SAFE_RELEASE( m_pDecl );
SAFE_RELEASE( m_pVShader );
SAFE_RELEASE( m_pPShader );
SAFE_RELEASE( m_pColorTex );
SAFE_RELEASE( m_pNormalMap );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FinalCleanup()
// Desc: Paired with OneTimeSceneInit()
// Called before the app exits, this function gives the app the chance
// to cleanup after itself.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::FinalCleanup()
{
// TODO: Perform any final cleanup needed
// Write the settings to the registry
WriteSettings();
return S_OK;
}
ps_1_4
texld r0, t0
texld r1, t1
dp3 r2, r1_bx2, v0_bx2
mul r0, r0, r2
vs_1_1
dcl_position0 v0
dcl_normal0 v3
dcl_texcoord0 v7
dcl_texcoord1 v8
dp4 oPos.x, v0, c8
dp4 oPos.y, v0, c9
dp4 oPos.z, v0, c10
dp4 oPos.w, v0, c11
; transform normal
dp3 r1.x, v3, c4
dp3 r1.y, v3, c5
dp3 r1.z, v3, c6
; renormalize it
dp3 r1.w, r1, r1
rsq r1.w, r1.w
mul r1, r1, r1.w
m3x3 r5, v8, c0
m3x3 r7, v3, c0
mul r0, r5.zxy, -r7.yzx
mad r6, r5.yzx, -r7.zxy, -r0
dp3 r8.x, r5, -c12
dp3 r8.y, r6, -c12
dp3 r8.z, r7, -c12
mad oD0.xyz, r8.xyz, c33, c33
mov oT0, v7
mov oT1, v8
//-----------------------------------------------------------------------------
// File: ps_1.h
//
// Desc: Header file ps_1 sample app
//-----------------------------------------------------------------------------
#pragma once
//-----------------------------------------------------------------------------
// Defines, and constants
//-----------------------------------------------------------------------------
// TODO: change "DirectX AppWizard Apps" to your name or the company name
#define DXAPP_KEY TEXT("Software\\DirectX AppWizard Apps\\ps_1")
// Struct to store the current input state
struct UserInput
{
// TODO: change as needed
BOOL bRotateUp;
BOOL bRotateDown;
BOOL bRotateLeft;
BOOL bRotateRight;
};
struct ShaderVertex
{
FLOAT x,y,z;
FLOAT u,v;
FLOAT nx,ny,nz;
FLOAT bx,by,bz;
};
//-----------------------------------------------------------------------------
// Name: class CMyD3DApplication
// Desc: Application class. The base class (CD3DApplication) provides the
// generic functionality needed in all Direct3D samples. CMyD3DApplication
// adds functionality specific to this sample program.
//-----------------------------------------------------------------------------
class CMyD3DApplication : public CD3DApplication
{
BOOL m_bLoadingApp; // TRUE, if the app is loading
ID3DXFont* m_pFont; // D3DX font
UserInput m_UserInput; // Struct for storing user input
FLOAT m_fWorldRotX; // World rotation state X-axis
FLOAT m_fWorldRotY; // World rotation state Y-axis
LPDIRECT3DVERTEXBUFFER9 m_pVB;
LPDIRECT3DINDEXBUFFER9 m_pIB;
LPDIRECT3DVERTEXDECLARATION9 m_pDecl;
LPDIRECT3DVERTEXSHADER9 m_pVShader;
LPDIRECT3DPIXELSHADER9 m_pPShader;
LPDIRECT3DTEXTURE9 m_pColorTex;
LPDIRECT3DTEXTURE9 m_pNormalMap;
D3DXVECTOR4 m_LightDir;
DWORD m_dwNumVertices;
DWORD m_dwNumFaces;
D3DXMATRIX m_matW, m_matV, m_matP;
protected:
virtual HRESULT OneTimeSceneInit();
virtual HRESULT InitDeviceObjects();
virtual HRESULT RestoreDeviceObjects();
virtual HRESULT InvalidateDeviceObjects();
virtual HRESULT DeleteDeviceObjects();
virtual HRESULT Render();
virtual HRESULT FrameMove();
virtual HRESULT FinalCleanup();
virtual HRESULT ConfirmDevice( D3DCAPS9*, DWORD, D3DFORMAT );
HRESULT RenderText();
void UpdateInput( UserInput* pUserInput );
VOID ReadSettings();
VOID WriteSettings();
public:
LRESULT MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
CMyD3DApplication();
virtual ~CMyD3DApplication();
};