Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

118 Neutral

About Dyronix

  • Rank
  1. Dyronix

    Diffuse Light

    Hello,   Recently I've continued working on my own framework and tried implementing some diffuse lighting shader. First I've create a shader that only takes a POSITION semantic after that I created a shader that takes a POSITION & TEXCOORD semantic But now when I'm using POSITION TEXCOORD NORMAL my cube turns into something like this. I looked at the VertexStruct and the Inputlayout and there does not seem to be anything wrong with it.   //VERTEX STRUCT //------------------------------------------------------------------------------------- struct VertexPosTexNorm : public VertexPos { public: VertexPosTexNorm() :VertexPos() , TexCoord(0,0) , Normal(-1,-1,-1) { } VertexPosTexNorm(const XMFLOAT3& p, const XMFLOAT3& n, const XMFLOAT2& uv) : VertexPos(p) , TexCoord(uv) , Normal(n) { } VertexPosTexNorm(float px, float py, float pz, float u, float v, float nx, float ny, float nz) : VertexPos(px, py, pz) , TexCoord(u,v) , Normal(nx,ny,nz) { } VertexPosTexNorm(const VertexPosTexNorm& v) : VertexPos(v.Position.x, v.Position.y, v.Position.z) , TexCoord(v.TexCoord.x, v.TexCoord.y) , Normal(v.Normal.x,v.Normal.y,v.Normal.z) { }   VertexPosTexNorm(const VertexPos& v) :VertexPos(v.Position.x,v.Position.y,v.Position.z) , TexCoord(-1,-1) , Normal(-1, -1, -1) {} VertexPosTexNorm(const VertexPosTex& v) :VertexPos(v) , TexCoord(v.TexCoord) , Normal(-1,-1,-1) {}   bool operator==(const VertexPosTexNorm& rhs) const { return XMFloat3Compare(this->Position, rhs.Position) && XMFloat3Compare(this->Normal,rhs.Normal) && XMFloat2Compare(this->TexCoord,rhs.TexCoord); }   XMFLOAT2 TexCoord; XMFLOAT3 Normal; };   //VERTEX BUFFERS //-------------------------------------------------------------------------------------   HRESULT hr = S_OK;   D3D11_BUFFER_DESC bdVertex; ZeroMemory(&bdVertex, sizeof(bdVertex));   // Create vertex buffer bdVertex.Usage = D3D11_USAGE_DEFAULT; bdVertex.ByteWidth = sizeof(VertexPosTexNorm)* (int)_vertexVec.size(); bdVertex.BindFlags = D3D11_BIND_VERTEX_BUFFER; bdVertex.CPUAccessFlags = 0; bdVertex.MiscFlags = 0; bdVertex.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA initDataVertex; ZeroMemory(&initDataVertex, sizeof(initDataVertex)); initDataVertex.pSysMem = _vertexVec.data();   hr = GRAPHICSDEVICEMANAGER->GetGraphicsDevice3D()->GetDevice()->CreateBuffer(&bdVertex, &initDataVertex, &package.vertexBuffer); if (FAILED(hr)) return hr;   D3D11_BUFFER_DESC bdIndex; ZeroMemory(&bdIndex, sizeof(bdIndex));   bdIndex.Usage = D3D11_USAGE_DEFAULT; bdIndex.ByteWidth = sizeof(DWORD)* (int)_indexVec.size(); bdIndex.BindFlags = D3D11_BIND_INDEX_BUFFER; bdIndex.CPUAccessFlags = 0; bdIndex.MiscFlags = 0; bdIndex.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA initDataIndex; ZeroMemory(&initDataIndex, sizeof(initDataIndex)); initDataIndex.pSysMem = _indexVec.data();   hr = GRAPHICSDEVICEMANAGER->GetGraphicsDevice3D()->GetDevice()->CreateBuffer(&bdIndex, &initDataIndex, &package.indexBuffer); if (FAILED(hr)) return hr;   return hr;   //INPUT LAYOUT //------------------------------------------------------------------------------------- D3D11_INPUT_ELEMENT_DESC polygonLayout[3]; unsigned int numElements;   // Create the vertex input layout description. // This setup needs to match the VertexType stucture in the ModelClass and in the shader. polygonLayout[0].SemanticName = "POSITION"; polygonLayout[0].SemanticIndex = 0; polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[0].InputSlot = 0; polygonLayout[0].AlignedByteOffset = 0; polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[0].InstanceDataStepRate = 0;   polygonLayout[1].SemanticName = "TEXCOORD"; polygonLayout[1].SemanticIndex = 0; polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT; polygonLayout[1].InputSlot = 0; polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[1].InstanceDataStepRate = 0;   polygonLayout[2].SemanticName = "NORMAL"; polygonLayout[2].SemanticIndex = 0; polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[2].InputSlot = 0; polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[2].InstanceDataStepRate = 0;   // Get a count of the elements in the layout. numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);   // Create the input layout hr = GRAPHICSDEVICEMANAGER->GetGraphicsDevice3D()->GetDevice()->CreateInputLayout(polygonLayout, numElements, this->m_MaterialData->pVSBlob->GetBufferPointer(), this->m_MaterialData->pVSBlob->GetBufferSize(), &this->m_MaterialData->pInputLayout); if (FAILED(hr)) return hr;   I kinda hardcode everything now, to find where the error could be. But I don't seem to find it. Does anybody have any idea what could be going on?
  2. Dyronix

    Importing a mesh, using FBX SDK

    I already narrowed it down to the position where the error occurs, but when I'm helping somebody I'd like to have as much code as possible to seek out a problem. In my post I metioned that it had to do something with the indices of my mesh but did not know exactly what was going wrong. I also know how to debug my code, I went over it 20000 times and everything seems valid to me that the issue that I don't understand. I checked everything step by step, used a more simple mesh like a cube because the first mesh was much more complex. All my values are correctly but I cannot get the right result, and I don't know why. That's why I posted my question over here. But if you want "12 lines of code". here they are.   //For each vertex in a polygon for (int k = 0; k < iNumVertices; ++k) { FbxVector4 vertexNormal = FbxVector4(0, 0, 0); FbxVector2 vertexUV = FbxVector2(0, 0); bool unmappedUV; int iControlPointIndex = pMesh->GetPolygonVertex(j, k); pMesh->GetPolygonVertexNormal(j, k, vertexNormal); pMesh->GetPolygonVertexUV(j, k, UVNames[0], vertexUV, unmappedUV); int polygonindex = pMesh->GetPolygonVertexIndex(j); if (polygonindex == -1) return false; int* VerticesIndices = pMesh->GetPolygonVertices(); ...
  3. Hi,   I got a question about importing meshes using C++. Currently I'm working on my own game-engine and I'd like to import meshes using the FBX SDK of autodesk. I'v got a whole environment setup but something is not quite right. These are some screenshots:   https://www.dropbox.com/s/3i57g8zyredn63r/00.png?dl=0 https://www.dropbox.com/s/4cn8a6v7i463ovu/01.png?dl=0 https://www.dropbox.com/s/8pej50sz7np3f6h/02.png?dl=0   it's supposed to be a cube but as you can see what the engine outputs is not exactly a cube. I know it has probably something to do with the vertex ordering or indices of my mesh but I checked everything over and over again and I cannot find what I'm doing wrong. Here a link to my code: http://pastebin.com/MRK4Fwru   Kind Regards, Dave
  4. Dyronix

    3DS Max to DirectX Matrix

    Thanks "Lightxbulb" & "Buckeye" for the reply I already the solution. I just needed to muliply my vertex with the following matrix:   (1, 0, 0, 0); (0, 0, -1, 0);//need to multiply by -1 because directx has a left handed coordinate system. (0, 1, 0, 0);  (0, 0, 0, 1);   It was so obvious that just did not think about it. Then again "Buckeye" you have a valid point, maybe I should write an application that imports meshes from several moddeling applications and then export it to a fileformat my engine can read, this way I can avoid dirty coding and just import my own format. I'll take that into account.
  5. Hello, I'm building my own engine in directx and I came to the point where I'm trying to import meshes. I installed the FBX SDK and imported a mesh inside my framework. But, there is one small issue ... In 3DS max the Z-axis is the up axis and in my framework the Y-axis is the up axis. Is there some sort of algorithm to solve this issue. I thought that I could multiply my final transform matrix with another matrix according to what 3d software package the mesh came from. I don't like to swap the y and z axis inside my engine it's a bit dirty coding and it will not work when a mesh is exported form another 3d software package. I already looked it up on google and found some kind of solution: http://forum.devmaster.net/t/transform-matrix-from-3ds-max-to-right-handed/10295/2 But I don't really understand what he means, do I need to multiply every vertex, or just my final transformation matrix? Also the reply on the solution tells me that he had to use a different matrix. But in my entire programming carreer the x-axis is right, y-axis is up and z-axis is forward so what do I need to use and why?   Kind Regards, Dyronix
  6. Dyronix

    Streaming .COM objects

    Thanks for the reply Nypyren, I'll take a look at it.
  7. Hi there,   I'm busy with handeling content ( textures, meshes, etc). I'd like to stream data to a binary file and then when I need them I just read everything from the binary file. The problem is: I can stream everything from custom made classes to basic variables like integers etc, but when I try t read a COM object it just won't work.   this is what my writer looks like: ContentTypeWriter& ContentTypeWriter::operator<<(ID3D11ShaderResourceView** resource) { Write(&resource, sizeof(ID3D11ShaderResourceView)); return *this; } void ContentTypeWriter::Write(const void* buffer, size_t length) { m_Stream->write((char*)buffer, length); if (!*m_Stream) Logger::Log(_T("File::write Error"), LOGTYPE_ERROR, false); } this is what my reader looks like: ContentTypeReader& ContentTypeReader::operator>>(ID3D11ShaderResourceView** resource) { Read(&resource, sizeof(ID3D11ShaderResourceView)); return *this; } void ContentTypeReader::Read(void* buffer, size_t length) { m_Stream->read((char*)buffer, length); if (!*m_Stream) Logger::Log(_T("File::write Error"), LOGTYPE_ERROR, false); } Everytime I load my ShaderResourceView it comes out as a 0x000000, but all my other variables are parsed the same way and they come out just like I saved them.   Does anybody have any idea what I'm doing wrong?
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!