Advertisement

md5 mesh rendered wrong in directX application

Started by April 05, 2019 04:24 PM
16 comments, last by rekotc 5 years, 9 months ago

I don't know the exact reason but i can't load the model in your attachment into my viewer. 

It has a lot of materials and textures but they are messy too. For example it has references to textures like bob_body_d.tga, bob_head_d.tga that should be diffuse textures but as you see there are no such textures. I've tried to fix it but they are in total mess. I found similar model that works well in my viewer from this article - bob with lamp

The model inside GPUAnimation.zip.

 

oh the old rastertek turorials, I loved them as they provided a lot of basic suggestions and ideas for terrain rendering...

Anyway, here's you rendering issue:



	srvDesc.Texture2D.MipLevels = -1;

which means 4294967294 mips setted in the SRV. If you want create a SRV for a texture without mips, just put 0.

Quote

Index of the most detailed mipmap level to use; this number is between 0 and MipLevels(from the original Texture2D for which ID3D11Device::CreateShaderResourceView creates a view) -1.

And now more serious things you need to fix: _m128 (aka SIMD registry vectors) need to be 16-byte aligned. Since SIMD performance is not you first goal (at least I guess this), I strongly suggest you to not use _m128 derived types (like XMMATRIX and XMVECTOR are by default), but more simple and beginner-reliable float[] structures (you can turn off SIMD implementation in DirectXMath using _XM_NO_INTRINSICS_ macro, otherwise switch to XMFLOAT4, XMFLOAT4x4 etc..).

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/
Advertisement

4294967295, typo.

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/
Quote

which means 4294967294 mips setted in the SRV. If you want create a SRV for a texture without mips, just put 0.

It doesn't work (it crashes) if i put MipLevels = 0, while it works if i set MipLevels = 1;


srvDesc.Texture2D.MipLevels = 1;

I read the documentation, trying to understand why it happens, but i don't understand the problem, the documentation about MipLevels says:

Quote

The maximum number of mipmap levels for the view of the texture. See the remarks in D3D11_TEX1D_SRV.Set to -1 to indicate all the mipmap levels from MostDetailedMip on down to least detailed.

 

Thanks for pointing me in the right direction!

PS: about this:

Quote

And now more serious things you need to fix: _m128 (aka SIMD registry vectors) need to be 16-byte aligned. Since SIMD performance is not you first goal (at least I guess this), I strongly suggest you to not use _m128 derived types (like XMMATRIX and XMVECTOR are by default), but more simple and beginner-reliable float[] structures (you can turn off SIMD implementation in DirectXMath using _XM_NO_INTRINSICS_ macro, otherwise switch to XMFLOAT4, XMFLOAT4x4 etc..).

I need time to understand what it is all about :D

I love to learn new stuff about computer graphics and the DirectX APIs.

 

If using DirectXMath then _m128 type is mapped on SIMD registers if _XM_NO_INTRINSICS_ macro is not defined. On x86, SIMD registers must be 16-byte aligned, ie address%16 must be 0. I suggest you to avoid using SIMD register types declaring _XM_NO_INTRINSICS_  macro, so everything will be mapped on simple structs wrapping float[4] or so...

Note also, this is a major issue on 32-bit build, on 64-bit build, using MSVC default compiler settings, everything should be automatically aligned on 16-byte.

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/
Quote

I don't know the exact reason but i can't load the model in your attachment into my viewer. 

It has a lot of materials and textures but they are messy too. For example it has references to textures like bob_body_d.tga, bob_head_d.tga that should be diffuse textures but as you see there are no such textures. I've tried to fix it but they are in total mess. I found similar model that works well in my viewer from this article - bob with lamp

The model inside GPUAnimation.zip.

Some background:

The LoadTarga() function inside my application needs the .tga textures to be 32bits, i had to convert all the textures inside the model to 32bits to be able to run the demo.

I tried the md5mesh file inside GPUAnimation.zip (after converting its textures to 32bits) , and i still see the black face. However, thanks to @Alessio1989 i now know that i need to set the srvDesc.Texture2D.MipLevels to 1 in order to render the model successfully, this fix works on both the md5mesh files so i can say that my problem was solved. I need to study better the meaning of this 1, as i don't really get how it works. Besides, the texture loading is based on this rastertek demo, where the MipLevels is set to 1 without much explanations.

Thanks everybody for your help, i really appreciate it.

Special thanks to @Alessio1989 for the extra details about 16-byte aligned SIMD registers.

I love to learn new stuff about computer graphics and the DirectX APIs.

 

Advertisement
Quote

Still something that bugs me though, the guy's face is totally black, but it gets brighter when i move closer to it...

I believe i can now answer to my own question. I completely forgot to call GenerateMips after creating the SRV. I modified the code inside graphicsclass.cpp and added:


d3d11DevCon->GenerateMips(tempMeshSRV);

Just after creating the ShaderResourceView:


hr = d3d11Device->CreateShaderResourceView(m_texture, &srvDesc, &tempMeshSRV);

And the model now renders correctly! There is no need to touch the mipLevels, -1 is a perfectly legal value, it just didnt' make sense without creating the mipmaps first!

Thanks again :)

I love to learn new stuff about computer graphics and the DirectX APIs.

 

This topic is closed to new replies.

Advertisement