Adjacency Generation
Hello.
I've implemented an algorhytm that, from an index buffer, discovers the
adjacency buffer and insert it (following D3D10 documentation) into the
index buffer.
But, if the vertex has not got adjacences, what have i to write??
i0 = this->MeshData.Indices[i*3];
i1 = this->MeshData.Indices[i*3+1];
i2 = this->MeshData.Indices[i*3+2];
pAdj[i*6] = i0;
pAdj[i*6+1] = 0xffffffff;
pAdj[i*6+2] = i1;
pAdj[i*6+3] = 0xffffffff;
pAdj[i*6+4] = i2;
pAdj[i*6+5] = 0xffffffff;
Using this code and 0xfffffff for non adjacent vertices, like in D3D9, the
mesh it's not rendered correctly, even if the index order it's correct.
But if in the index buffer i write a simple number, 0 or 1,3,12...it works.
What value should i insert?
Anyway, i tried to make the generation throught the D3DX Helper Functions,
in this way
void CMesh::G()
{
ID3DX10Mesh *m;
ID3D10Device *device;
D3D10_BUFFER_DESC desc;
ID3DX10MeshBuffer *MeshBuffer;
this->MeshData.ColladaBuffer.IndexBuffer->GetDevice(&device);
this->MeshData.ColladaBuffer.VertexBuffer->GetDesc(&desc);
UINT vertici = desc.ByteWidth / this->MeshData.Stride;
D3D10_INPUT_ELEMENT_DESC el[ =
{
{"POSITION",0,DXGI_FORMAT_R32G32B32A32_FLOAT,0,D3D10_APPEND_ALIGNED_ELEMENT,D3D10_INPUT_PER_VERTEX_DATA,0
},
{"NORMAL",0,DXGI_FORMAT_R32G32B32_FLOAT,0,D3D10_APPEND_ALIGNED_ELEMENT,D3D10_INPUT_PER_VERTEX_DATA,0
},
{"TEXCOORD",0,DXGI_FORMAT_R32G32B32_FLOAT,0,D3D10_APPEND_ALIGNED_ELEMENT,D3D10_INPUT_PER_VERTEX_DATA,0
},
};
D3DX10CreateMesh(device,el,3,"POSITION",vertici,this->MeshData.ColladaBuffer.Indici/3,0,&m); m->SetIndexData(this->MeshData.Indices,this->MeshData.ColladaBuffer.Indici); m->GenerateAdjacencyAndPointReps(0.0001f); m->GenerateGSAdjacency(); m->GetIndexBuffer(&MeshBuffer); unsigned int IBsize = MeshBuffer->GetSize(); void *tmp; UINT *indici = new UINT[IBsize]; MeshBuffer->Map((void**)&tmp,0); memcpy(indici,tmp,IBsize); MeshBuffer->Unmap(); MeshBuffer->Release(); m->GetAdjacencyBuffer(&MeshBuffer); unsigned int ABsize = MeshBuffer->GetSize(); UINT *adj = new UINT[ABsize]; MeshBuffer->Map((void**)&tmp,0); memcpy(adj,tmp,ABsize); MeshBuffer->Unmap(); MeshBuffer->Release(); m->Release(); this->MeshData.ColladaBuffer.IndexBuffer->Release(); desc.BindFlags = D3D10_BIND_INDEX_BUFFER; desc.CPUAccessFlags = 0; desc.Usage = D3D10_USAGE_DEFAULT; desc.MiscFlags = 0; desc.ByteWidth = IBsize; D3D10_SUBRESOURCE_DATA init; init.pSysMem = indici; device->CreateBuffer(&desc,&init,&this->MeshData.ColladaBuffer.IndexBuffer); delete[] indici; delete[] adj;}But the results were not very nicehttp://img165.imageshack.us/img165/4625/5nh64e5tmpbr9.jpgThis is the silhouette finding algorythm used also in ShadowVolume10 Sample,with a certain light direction and using the function above for adjacencygenerationhttp://img373.imageshack.us/img373/4906/mkz8c8ftmpon1.jpgThis is the same thing but with my algorith. Anyway, noone makes me happy.What do you think about?
date: Fri, 4 Jul 2008 20:34:57 +0200
author: Mim-R