Jump to content
  • Advertisement
Sign in to follow this  
Anddos

Vertex shader with a mesh

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

I cant seem to get my Box mesh to show up , here is the code

 
void
 
 
initBox()
{
 
 
 
//Create the shader
 
 
const char* strAsmVertexShader = "vs_1_1\n" //version instruction
 
 
"dcl_position v0\n" //define position data in register v0
 
 
"dcl_color v1\n" //define color
 
 
"m4x4 oPos, v0, c0\n" //view/projection
 
 
"mov oD0, v1\n" //apply diffuse to vertices
 
 
"";
 
 
LPD3DXBUFFER pShader = NULL;
HRESULT hr;
hr = D3DXAssembleShader(strAsmVertexShader,
(UINT)strlen(strAsmVertexShader),
NULL,
NULL,
D3DXSHADER_DEBUG,
&pShader,
NULL);
 
 
if(FAILED(hr))
{
 
 
//SAFE_RELEASE(pShader);
}
hr = d3ddev->CreateVertexShader((DWORD*)pShader->GetBufferPointer(),&m_pAsm_VS);
 
 
if(FAILED(hr))
{
}
?
?
 
 
//Mesh code
D3DVERTEXELEMENT9 decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, 
 
//POSITION
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, 
 
//COLOR
D3DDECL_END()
};
 
HRESULT hr = d3ddev->CreateVertexDeclaration(decl,&m_pVertexDeclarationBox);
D3DXCreateBox(d3ddev,1.0f,1.0f,1.0f,&D3DCube,NULL);
?
 
 
//Clone the mesh so it gets position and color data for the vertex shader
D3DCube->CloneMesh(D3DXMESH_32BIT | D3DXMESH_MANAGED,
decl,
d3ddev,
&D3DClonedCube);
 
}
 

?

 

Rendering

 

 
 
if(m_pAsm_VS)
{
D3DXMATRIX compMat;
D3DXMatrixMultiply(&compMat,&matRotateY,&matView);
D3DXMatrixMultiply(&compMat,&compMat,&matProjection);
 
D3DXMatrixTranspose(&compMat,&compMat); 
 
//rearranges to column major order so its 4 dot products
 
d3ddev->SetVertexShaderConstantF(0,(
 
float*)&compMat,4);
d3ddev->SetVertexDeclaration(m_pVertexDeclarationBox);
d3ddev->SetVertexShader(m_pAsm_VS);
 
 
//d3ddev->SetStreamSource(0,m_pVB,0,sizeof(CUSTOMVERTEX_ASM));//CreateVertexBuffer code, now were working with LPD3DXMESH...
//d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
 
 
d3ddev->SetVertexShader(NULL);
D3DClonedCube->DrawSubset(0);
}
 

?

Edited by Anddos

Share this post


Link to post
Share on other sites
Advertisement

A lot of things not shown in the code can be wrong, starting with your transform matrices.

Enable the Direct3D Debug Runtimes and check for any errors and warnings in the output log. Use PIX to debug the application and see better what's going on.

 

Btw, what color do you use to clear your backbuffer? If it's black or white then definitely change it to something else. Especially black is perfect in "hiding" rendered geometry if you have some error in lighting.

Also I would pay attention to the fact that you create the box with D3DXCreateBox and then add color to its vertex declaration via CloneMesh, but you never really set some colors to the verticles. I don't know how exactly this behaves, but I would suppose the color is zero? Either completely zero, which means also completely transparent, or maybe 0xFF000000 which means black. Or it simply is a "random" number? No idea. You definitely should lock the vertex buffer and set your own colors.

 

And last remark - is it possible to have your own vertex shader and let the fixed-function pipeline do the rest? You don't set any pixel shader. I've never done this, but maybe it is possible.

And just now I noticed that you don't set even the vertex shader. You have this line d3ddev->SetVertexShader(NULL) before the DrawSubset. So you have no vertex shader!

Edited by Tom KQT

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!