Hola, resulta que queria aplicar un efecto a un d3dxskinned mesh, y no tengo problema con el salvo que la animacion me la chapa.
Alguien sabe como puedo animar la malla y aplicar el effect al mismo tiempo?
este es el codigo del skin:
// first check for skinning
if (pMeshContainer->pSkinInfo != NULL)
{
if (m_SkinningMethod == D3DINDEXED)
{
if(bump==true){
max_passes(2);
set_vpw_matrix("ModelViewProj",1);
set_matrix("ModelWorld",matTemp,1);
float cr,cg,cb,cx,cy,cz,lx,ly,lz,cp;
cr=light_r(1);
cg=light_g(1);
cg=light_b(1);
cp=light_pow(1);
get_cam_pos(cx,cy,cz);
lx=light_x(1);
ly=light_y(1);
lz=light_z(1);
set_float("cx",cx,1);
set_float("cy",cy,1);
set_float("cz",cz,1);
set_float("lx",lx,1);
set_float("ly",ly,1);
set_float("ly",ly,1);
set_float("cr",cr,1);
set_float("cg",cg,1);
set_float("cb",cb,1);
set_float("p",cp,1);
set_effect_texture("test1",get_nskinbump(get_skinmesh()),1);
set_technique("bump1",1);
}
if(efecto>0){
}
// remember to reset back to hw vertex processing if software was required
if (pMeshContainer->UseSoftwareVP)
{
m_pd3dDevice->SetSoftwareVertexProcessing(TRUE);
}
// set the number of vertex blend indices to be blended
if (pMeshContainer->NumInfl == 1)
get_d3d_device()->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_0WEIGHTS);
else
get_d3d_device()->SetRenderState(D3DRS_VERTEXBLEND, pMeshContainer->NumInfl - 1);
if (pMeshContainer->NumInfl)
get_d3d_device()->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, TRUE);
// for each attribute group in the mesh, calculate the set of matrices in the palette and then draw the mesh subset
pBoneComb = reinterpret_cast<LPD3DXBONECOMBINATION>(pMeshContainer->pBoneCombinationBuf->GetBufferPointer());
for (iAttrib = 0; iAttrib < pMeshContainer->NumAttributeGroups; iAttrib++)
{
// first calculate all the world matrices
for (iPaletteEntry = 0; iPaletteEntry < pMeshContainer->NumPaletteEntries; ++iPaletteEntry)
{
iMatrixIndex = pBoneComb[iAttrib].BoneId[iPaletteEntry];
if (iMatrixIndex != UINT_MAX)
{
D3DXMatrixMultiply( &matTemp, &pMeshContainer->pBoneOffsetMatrices[iMatrixIndex], pMeshContainer->ppBoneMatrixPtrs[iMatrixIndex] );
get_d3d_device()->SetTransform( D3DTS_WORLDMATRIX( iPaletteEntry ), &matTemp );
}
// setup the material of the mesh subset - REMEMBER to use the original pre-skinning attribute id to get the correct material id
get_d3d_device()->SetMaterial( &pMeshContainer->pMaterials[pBoneComb[iAttrib].AttribId].MatD3D );
get_d3d_device()->SetTexture( 0, pMeshContainer->ppTextures[pBoneComb[iAttrib].AttribId] );
// remember to reset back to hw vertex processing if software was required
for(UINT nefecto=0; nefecto<get_passes();nefecto++){
effect_begin(nefecto,efecto);
effect_pass( nefecto,efecto );
// finally draw the subset with the current world matrix palette and material state
pMeshContainer->MeshData.pMesh->DrawSubset( iAttrib );
}effect_end(efecto);
// reset blending state
get_d3d_device()->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, FALSE);
get_d3d_device()->SetRenderState(D3DRS_VERTEXBLEND, 0);
// remember to reset back to hw vertex processing if software was required
if (pMeshContainer->UseSoftwareVP)
{
m_pd3dDevice->SetSoftwareVertexProcessing(FALSE);
}
}
}
}
muchisimas gracias.
PD: Este DX me esta volviendo (uoh) (uoh)
Como ya he dicho alguna vez, nunca he utilizado los skinned meshes de Direct3D pero es probable que el problema esté en que no realizas la transformación de los vértices por parte de los bones a través del vertex shader. ¿Entonces qué ocurre?, que cuando activas un vertex shader, se inhabilita la fixed pipeline y todas las operaciones de transformación que pudieras haber realizado (con SetTransform) se van al carajo. Sólo cuentan las que se han realizado en el vertex shader.
Así que lo que habría que hacer es, a través del vertex shader, tranformar los vértices utilizando las matrices de transformación de los bones. Si no te aclaras, tienes el ejemplo de SkinnedMesh en el SDK de DX9.
De todas formas que venga alguien que haya utilizado skinned meshes y lo confirme.
Saludos.
bien, hare el skinning por vextex shaders :P
mushas grasias.
otra cosa, se deformaria la malla si le paso por matrix al shader la matrix "matTemp" del codigo que mostre?
podria aplicarle el skinning sin modificar el shader?
es que modificandolo me salta el error de las 128 instrucciones por shader.
Alguien que pueda audarme??
jo, que liado estoy.