# SOLVED - Basics of HLSL - Why DrawSubset fails with ID3DXEffect ?

## Recommended Posts

StratBoy61    232
Hello again, Well, in my quest to understand HLSL, I just copied two projects that dealt with simple Effect files. I downloaded and ran the DirectX 9.0 sample called BasicHLSL, and the Simple Vertex & Pixel Shader (HLSL/Fx Effect File) from CodeSampler.com. Both samples work fine (obviously), until I add my own tests in them. I created a very simple project in which I first create a teapot with the D3DXCreateTeapot() function, teapot that I render with a call to DrawSubset. I mainly pasted the whole code from the BasicHLSL sample that dealt with the ID3DEffect, so that I get the following render function :
if(SUCCEEDED(g_pD3DDevice->BeginScene()))
{
m_pEffect->SetTechnique("RenderScene");

D3DXMATRIXA16  matWorld, matProj, matView;
D3DXMatrixIdentity(&matWorld);
D3DXMatrixIdentity(&matProj);
D3DXMatrixIdentity(&matView);

D3DXMATRIXA16 compMat = matWorld * matView * matProj;
D3DXMatrixTranspose(&compMat, &compMat);

m_pEffect->SetMatrix("g_mWorldViewProjection", &compMat);
m_pEffect->SetMatrix("g_mWorld", &matWorld);
m_pEffect->SetFloat("g_fTime", m_fTime);
m_pEffect->SetTexture("g_MeshTexture", g_pTexture);

HRESULT hr;
UINT numPasses, iPass;
hr = m_pEffect->Begin( &numPasses, 0 );
for( iPass = 0; iPass < numPasses; iPass ++ ) // all passes
{
hr = m_pEffect->Pass(iPass);
if( FAILED(hr) )
{
MessageBox(NULL, "Pass() failed! Aborting", "Error", MB_OK|MB_ICONEXCLAMATION);
exit(-1);
}
hr = pMesh->DrawSubset(0);
if( FAILED(hr) )
{
MessageBox(NULL, "DrawSubset() failed! Aborting", "Error", MB_OK|MB_ICONEXCLAMATION);
exit(-1);
}
}
hr = m_pEffect->End();
}
g_pD3DDevice->EndScene();


Well, the DrawSubset() function fails in the code above. If I comment out the call to m_pEffect->Pass(iPass), I get the display of my teapot. What am I missing there ? Thank you in advance. Cheers StratBoy61 [Edited by - StratBoy61 on November 24, 2006 10:49:19 AM]

##### Share on other sites
BornToCode    1185
After you multiply the world*view*projection, there is no need for you to transpose the matrix as long in your shader code, you are doing vector*matrix instead of matrix*vector

##### Share on other sites
StratBoy61    232
Thank you BornToCode for the hint, I will take it into consideration, now that I can see my teapot on the screen...

My problem was caused by something else, and it was not in the code I pasted above :(

I cloned my ID3DXMesh, so that the vertex structure would be :
D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX0
float4 vPos : POSITION, float3 vNormal : NORMAL, float2 vTexCoord0 : TEXCOORD0

Well, it did not work because I used D3DFVF_TEX0. It had to be D3DFVF_TEX1 instead.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EDIT

As a matter of fact, I am not sure it makes sense, the change from D3DFVF_TEX0 to D3DFVF_TEX1. For some reason, it solves my problem in my code, but it does not change anything if I replace it in the DirectX sample... it still works, even with D3DFVF_TEX0.
StratBoy61

[Edited by - StratBoy61 on November 24, 2006 12:53:29 PM]