简体   繁体   中英

Why are my textures not rendered in greater detail in my DirectX11 game?

I am trying to write a small 3D game in C++, using DirectX 11. This is absolutely the first time I have attempted to write a game using only a graphics API. I have been following the tutorials on the website Rastertek.com up to Tutorial 9 for ambient lighting.

After implementing movement and collisions for the player, I increased the size of my play area. This is when I noticed my issue: the textures I am using for the walls and floor of my play area are not being rendered the way I expected them to.

Wall from close up

Wall from far away

Maybe you can tell how the lines on the wall appear strangely broken up - I was expecting them to be rendered properly at larger distances (like they are close up).

The thing that seems most weird to me, though, is that the lines can be rendered from far away, but only while moving the camera around the scene and only on certain parts of the wall. Standing still breaks the texture again. I tried capturing this effect on video, but I had no success getting it to show up in the video I took with the GeForce Experience.

I tried playing around with a bunch of the settings that DirectX offers, like the rasterizer or the depth buffer descriptions, I tried to enable and disable VSync, Antialiasing and Multisampling, I tried using Anisotropic filtering instead of linear filtering... But none of it had any effect.

I do not know where to look and what to try next. Am I just going to have to accept that my textures will look terrible at any sort of distance?

You need to generate mip maps for the texture you load. Check the DDSTextureLoader.h/cpp and WICTextureLoader.h/cpp here .

For example, to load the.dds image with mip maps, you would use:

HRESULT DirectX::CreateDDSTextureFromFileEx( ID3D11Device* d3dDevice,
                                         ID3D11DeviceContext* d3dContext,
                                         const wchar_t* fileName,
                                         size_t maxsize,
                                         D3D11_USAGE usage,
                                         unsigned int bindFlags,
                                         unsigned int cpuAccessFlags,
                                         unsigned int miscFlags,
                                         bool forceSRGB,
                                         ID3D11Resource** texture,
                                         ID3D11ShaderResourceView** textureView,
                                         DDS_ALPHA_MODE* alphaMode )

Example of usage:

HRESULT hr = DirectX::CreateDDSTextureFromFileEx(device, context, path.c_str(), 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET, 0, D3D11_RESOURCE_MISC_GENERATE_MIPS, 0, reinterpret_cast<ID3D11Resource**>(&pTexture), &pSRV);
THROW_IF_FAILED(hr);

Note the flags D3D11_BIND_RENDER_TARGET and D3D11_RESOURCE_MISC_GENERATE_MIPS used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM