Sign in to follow this  
MattCa

Final (hopefully) Shader Question

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):

[code]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[i]);

m_pd3dDevice->SetTexture(0, m_pMeshTextures[i]);



m_pMesh->DrawSubset(i);

}

}

[/code]


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
I don't think you can "just apply a shader" to a mesh subset - it was my understanding that it did "all by itself".
[url="http://msdn.microsoft.com/en-us/library/bb172890(VS.85).aspx"]D3DXLoadMeshFromX[/url] got a [font=Consolas, Courier, monospace][size=2]ppEffectInstances [/size][/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
[quote name='Krohm' timestamp='1306400378' post='4815957']
I don't think you can "just apply a shader" to a mesh subset - it was my understanding that it did "all by itself".
[url="http://msdn.microsoft.com/en-us/library/bb172890(VS.85).aspx"]D3DXLoadMeshFromX[/url] got a [font="Consolas, Courier, monospace"][size="2"]ppEffectInstances [/size][/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.
[/quote]

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

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