Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Feb 2004
Offline Last Active Jul 17 2013 03:29 AM

Topics I've Started

Strange textures when loading md5 model in AssImp

29 April 2013 - 11:31 PM

I've finally gotten AssImp to work in DirectX11, but the textures are all wrong. I seem to remember seeing something similar before, but I can't remember what caused it.


Any ideas? I've included a screenshot (Print screen didn't seem to work, so I just took a picture for now).

Textures are grainy and pixels move when moving the camera

03 November 2012 - 08:14 AM

I've recently moved to the Windows SDK, so I've stopped using the D3DX libraries. I now use D3DCompiler for shaders and DirectXTex for loading textures (CreateDDSTextureFromFile).

I've noticed that my textures are grainy, and when I move the camera the grain(pixels) move around as well. I'm basically using the rastertek directx 11 tutorials, but converted them to use DirectXMath and the libraries I explained below.

I've uploaded a video on youtube that explains this better. Remember to turn on 720p and full screen viewing.

I've tried to compare flags and such when loading the textures/compilers, but I haven't found anything. Does anyone know what could cause this? I can provide code if necessary.

Mesh loaded with Assimp not showing up

05 October 2012 - 05:55 PM

I've been trying to load an md5 file with Assimp for a while with no luck. I've used some example code that loads a simple .obj file without assimp to make sure my directx 11 code for creating vertex/index buffers, shaders and textures works. It seems like the problem is in the LoadModel method somewhere. I've removed the DirectX 11 specific code, since I got this to work with the example I found.

I'm not that experienced with 3d programming yet, so maybe there's a simple solution to my problem. Maybe it's rendered far away somewhere outside my frustum even. The model I'm trying to render is simple, and has one aiMesh and 24 vertices.

My shaders take pos, texCoord, normal and tangents. I also have a light that illuminates the whole texture. The shader is rendered with DrawIndexed(indexCount, 0, 0). I can provide some more code if necessary.

Any ideas?

This is the code is use for loading the model with Assimp:
[source lang="cpp"]struct VertexType{ XMFLOAT3 position; XMFLOAT2 texture; XMFLOAT3 normal;};struct Mesh{ ID3D11Buffer* vertexBuffer; ID3D11Buffer* indexBuffer; Texture* texture; int indexCount;};bool Model::LoadModel(ID3D11Device* device, std::string filename){ HRESULT result;Assimp::Importer importer;const aiScene* scene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_MakeLeftHanded | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_JoinIdenticalVertices | aiProcess_GenSmoothNormals | aiProcess_LimitBoneWeights | aiProcess_RemoveRedundantMaterials | aiProcess_OptimizeMeshes | aiProcess_GenUVCoords | aiProcess_TransformUVCoords);if(!scene){ MessageBoxA(nullptr, importer.GetErrorString(), "Error", MB_OK); return false;}meshes.reserve(scene->mNumMeshes);for( unsigned int m=0; m<scene->mNumMeshes; ++m ){ aiMesh* aiMesh = scene->mMeshes[m]; if(!aiMesh->HasNormals() || !aiMesh->HasTextureCoords(0)) { MessageBox(NULL, L"Model is missing normals or texture coordinates.", L"Error", MB_OK); return false; } Mesh mesh; D3D11_SUBRESOURCE_DATA vertexData, indexData; int vertexCount = aiMesh->mNumVertices; vector<VertexType> vertices(vertexCount); for(unsigned int i=0;i < (unsigned)vertexCount;++i) { vertices[i].position = XMFLOAT3(aiMesh->mVertices->x, aiMesh->mVertices->y, aiMesh->mVertices->z); vertices[i].normal = XMFLOAT3(aiMesh->mNormals->x, aiMesh->mNormals->y, aiMesh->mNormals->z); vertices[i].texture = XMFLOAT2(aiMesh->mTextureCoords[0][i].x, aiMesh->mTextureCoords[0][i].y); } mesh.indexCount = aiMesh->mNumFaces*3; vector<unsigned int> indices(aiMesh->mNumFaces); for (unsigned int i = 0; i < aiMesh->mNumFaces;++i) { const aiFace& Face = aiMesh->mFaces[i]; assert(Face.mNumIndices == 3); indices.push_back(Face.mIndices[0]); indices.push_back(Face.mIndices[1]); indices.push_back(Face.mIndices[2]); } int materialid = aiMesh->mMaterialIndex; aiMaterial* mat = scene->mMaterials[materialid]; aiString szPath; char diffuseName[150]; //diffuse texture if(AI_SUCCESS == aiGetMaterialString(mat, AI_MATKEY_TEXTURE_DIFFUSE(0), &szPath)) { strcpy(diffuseName, "../../Media/md5/"); strcat(diffuseName, szPath.data); } else { strcpy(diffuseName, "DEFAULTTEX"); } if(!(mesh.texture = LoadTexture(device, diffuseName))) { MessageBox(NULL, L"Could not load texture", L"Error", MB_OK); return false; }// Directx 11 code for creating vertex and index buffers etc[/source]
Edit: Removed tangents and some other code that was just there for testing.

Entity system: Avoiding casts when returning shared_ptr

29 November 2011 - 03:27 AM

I'm making an entity system for a game in C++, and I want a function getComponent that returns a component of a specified type.

I found an example that does this when fetching a component: entitySystem->getComponent<VisualComponent>(entity)
(This isn't the intended usage, I just don't want to drag too much code from the example)
template<typename T> T *getComponent(Entity *e) {

	return (T*)e->mComponents[T::familyId];

All my components are shared_ptrs, so I have to do this differently. How do I do the same thing with a shared_ptr? I want to avoid adding casts everywhere.

DirectX 9 w/DXUT & C++ Sprite/Device problem

29 December 2009 - 12:27 AM

I've been making a game engine based on the architecture in the book Game Coding Complete by Mike McShaffry. When I began trying to draw sprites I'm not able to create a valid texture with the D3DXCreateTextureFromFile or ..Ex function. The texture name just ends up scrambled with chinese letters, the resolution is also incorrect. After some debugging I found out that the d3ddevice parameters are all mixed up, the resolution is where the refresh rate should be, for example. The actual resolution seems to be correct though. I'm using the core game engine in a static library (.lib) and running a game implementation on top of that. I haven't used much of the code in the book, since I've rewritten most of it from scratch. Any ideas what the problem could be? I'm at work now, but I could include some screens later if that would help. I thought I'd ask before making an svn branch and making some drastic changes to find out.