Sign in to follow this  

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

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

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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
as the shader expected
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]

Share this post


Link to post
Share on other sites

This topic is 4041 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this