• Advertisement
Sign in to follow this  

Final (hopefully) Shader Question

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

Hi guys!
Hopefully this will be my final beginning shader-related question, but I'm having a little trouble actually loading the shader.

I use the following code to render a mesh (loaded through the D3DXLoadMeshFromX function):

void renderMesh(LPDIRECT3DDEVICE9 m_pd3dDevice){

m_pd3dDevice->SetTransform(D3DTS_WORLD, &matLocal );//set model in world space




if(m_pMesh != NULL)

{

for(DWORD i=0; i<m_dwNumMaterials; i++)

{

m_pd3dDevice->SetMaterial(&m_pMeshMaterials);

m_pd3dDevice->SetTexture(0, m_pMeshTextures);



m_pMesh->DrawSubset(i);

}

}




What I can't figure out is what and where I am actually supposed to put to load a shader (either vertex or pixel), so that it is applied to the mesh. I'm assuming that since I just want the shader to be applied to the mesh that it must be a vertex shader, but at the moment I'm still rather confused as to how they are loaded and used on something other than a pre-defined quad that most tutorials seem to use as an example.

Thanks alot!!!
Matt.

Share this post


Link to post
Share on other sites
Advertisement
I don't think you can "just apply a shader" to a mesh subset - it was my understanding that it did "all by itself".
D3DXLoadMeshFromX got a [font=Consolas, Courier, monospace][size=2]ppEffectInstances [/font]parameter returning an array of D3DXEFFECTINSTANCE structures, I'd look in this direction. The shaders are bound to the subset when authored and are a unique property.

Share this post


Link to post
Share on other sites

I don't think you can "just apply a shader" to a mesh subset - it was my understanding that it did "all by itself".
D3DXLoadMeshFromX got a [font="Consolas, Courier, monospace"]ppEffectInstances [/font]parameter returning an array of D3DXEFFECTINSTANCE structures, I'd look in this direction. The shaders are bound to the subset when authored and are a unique property.


You would still need to load the effects though as the effect instance is nothing more than a filename. Also DrawSubset does nothing more then draw the vb and ib for that subset, you will have to setup the effect begin and end and all it's parameters on your own.
Like what you are already doing with the firxed function pipeline in the example you gave, except now you set them on the effect instead of the device and then begin the effect and the pass in it you want.

Make sure the FVF/VertexDeclaration the mesh is using are the inputs to the Vertex Shader, you can ask the vertexdeclaration from the mesh

Share this post


Link to post
Share on other sites
So basically, i'd have to create the vertex and index buffers for the mesh, apply the shader (does the shader have to be applied to a single vertex?) and then draw with the DrawPrimitive function?

Thanks for the replies guys,
Matt.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement