等距瓷砖有锯齿状的线条
Isometric tile has jagged lines
所以我正在尝试渲染一个小的等距图块地图,并且刚开始使用单个图块来感受一下。但是我 运行 遇到了一个问题,如果瓷砖得到 "too small" (实际上是 64x64,与纹理的大小完全相同),它会出现锯齿状的线条,即使它在纹理本身上看起来还不错。奇怪的是,如果我在 Visual Studio 中使用图形调试器,它似乎也是正确的。这是一张图片,可以更好地形象化我的意思:
左图是正常 window 内渲染帧的一部分。右边部分是图形调试工具捕获的帧。如您所见,捕获帧的显示看起来完全正常。如果我按某种因素放大此图块,window 内的正常渲染也开始看起来不错。任何想法为什么会发生这种情况?如果对您有帮助,这里是原始纹理。
进一步说明:我通过在搅拌机中渲染一个对象来创建 "texture",同时像这样设置相机:http://flarerpg.org/tutorials/isometric_tiles/(据我所知,这应该是在其中渲染它的一种好方法DirectX)
编辑: 这是我的采样器描述。我正在使用 DirectXTK (https://github.com/Microsoft/DirectXTK) 提供的 CreateDDSTextureFromFile
方法创建纹理。
CreateDDSTextureFromFile(gfx->GetGraphicsDevice()->GetDevice(), L"resources/house_tile.DDS", nullptr, shaderResource.GetAddressOf())
g_defaultSamplerDesc.Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
g_defaultSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
g_defaultSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
g_defaultSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
g_defaultSamplerDesc.MipLODBias = 0.0f;
g_defaultSamplerDesc.MaxAnisotropy = 1;
g_defaultSamplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
g_defaultSamplerDesc.BorderColor[0] = 0;
g_defaultSamplerDesc.BorderColor[1] = 0;
g_defaultSamplerDesc.BorderColor[2] = 0;
g_defaultSamplerDesc.BorderColor[3] = 0;
g_defaultSamplerDesc.MinLOD = 0;
g_defaultSamplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
编辑 2: 我检查了 .dds 文件,发现只有 1 个 Mip-Level。这也是 DirectXTK 方法使用的纹理描述。我觉得还不错:
Width 64 unsigned int
Height 64 unsigned int
MipLevels 1 unsigned int
ArraySize 1 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (87) DXGI_FORMAT
+ SampleDesc {Count=1 Quality=0 } DXGI_SAMPLE_DESC
Usage D3D11_USAGE_DEFAULT (0) D3D11_USAGE
BindFlags 8 unsigned int
CPUAccessFlags 0 unsigned int
MiscFlags 0 unsigned int
这里值得一提的还有我的 Vertex-Setup:
Vertex v[] =
{
Vertex(-32.f, -32.f, 1.0f, 0.0f, 1.0f),
Vertex(-32.f, 32.f, 1.0f, 0.0f, 0.0f),
Vertex(32.0f, -32.f, 1.0f, 1.0f, 1.0f),
Vertex(32.0f, 32.f, 1.0f, 1.0f, 0.0f)
};
应该创建大小为 64x64 的四边形。
编辑 3: 我尝试生成 Mip-Maps 以查看是否有效,但没有成功。以下是可用的 7 个 Mip 级别中的两个:
还有新的纹理描述:
Width 64 unsigned int
Height 64 unsigned int
MipLevels 7 unsigned int
ArraySize 1 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (87) DXGI_FORMAT
+ SampleDesc {Count=1 Quality=0 } DXGI_SAMPLE_DESC
Usage D3D11_USAGE_DEFAULT (0) D3D11_USAGE
BindFlags 8 unsigned int
CPUAccessFlags 0 unsigned int
MiscFlags 0 unsigned int
我觉得不错,但结果还是一样:/.
@Gnietschow:谢谢你的努力。解决方案非常简单,它被 gamedev.net 版块中的一些人找到:
引用:
I had a similiar issue once, and it turned out I was doing windowed
mode wrong in terms of calculating the window size to fit the
backbuffer size etc., resulting in a vaguely stretched display that
was hard to notice for a long while
I was going to say the same thing. You want to make sure that the
client area of your window is the same size as your D3D backbuffer,
otherwise you'll get really crappy scaling when the backbuffer is blit
onto the window. You can use something like this:
RECT windowRect;
SetRect(&windowRect, 0, 0, backBufferWidth, backBufferHeight);
BOOL isMenu = (GetMenu(hwnd) != nullptr);
if(AdjustWindowRectEx(&windowRect, style, isMenu, exStyle) == 0)
DoErrorHandling();
if(SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOMOVE) == 0)
DoErrorHandling();
来源:http://www.gamedev.net/topic/677243-iso-dimetric-tile-texture-has-jagged-edges/
所以我正在尝试渲染一个小的等距图块地图,并且刚开始使用单个图块来感受一下。但是我 运行 遇到了一个问题,如果瓷砖得到 "too small" (实际上是 64x64,与纹理的大小完全相同),它会出现锯齿状的线条,即使它在纹理本身上看起来还不错。奇怪的是,如果我在 Visual Studio 中使用图形调试器,它似乎也是正确的。这是一张图片,可以更好地形象化我的意思:
左图是正常 window 内渲染帧的一部分。右边部分是图形调试工具捕获的帧。如您所见,捕获帧的显示看起来完全正常。如果我按某种因素放大此图块,window 内的正常渲染也开始看起来不错。任何想法为什么会发生这种情况?如果对您有帮助,这里是原始纹理。
进一步说明:我通过在搅拌机中渲染一个对象来创建 "texture",同时像这样设置相机:http://flarerpg.org/tutorials/isometric_tiles/(据我所知,这应该是在其中渲染它的一种好方法DirectX)
编辑: 这是我的采样器描述。我正在使用 DirectXTK (https://github.com/Microsoft/DirectXTK) 提供的 CreateDDSTextureFromFile
方法创建纹理。
CreateDDSTextureFromFile(gfx->GetGraphicsDevice()->GetDevice(), L"resources/house_tile.DDS", nullptr, shaderResource.GetAddressOf())
g_defaultSamplerDesc.Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
g_defaultSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
g_defaultSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
g_defaultSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
g_defaultSamplerDesc.MipLODBias = 0.0f;
g_defaultSamplerDesc.MaxAnisotropy = 1;
g_defaultSamplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
g_defaultSamplerDesc.BorderColor[0] = 0;
g_defaultSamplerDesc.BorderColor[1] = 0;
g_defaultSamplerDesc.BorderColor[2] = 0;
g_defaultSamplerDesc.BorderColor[3] = 0;
g_defaultSamplerDesc.MinLOD = 0;
g_defaultSamplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
编辑 2: 我检查了 .dds 文件,发现只有 1 个 Mip-Level。这也是 DirectXTK 方法使用的纹理描述。我觉得还不错:
Width 64 unsigned int
Height 64 unsigned int
MipLevels 1 unsigned int
ArraySize 1 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (87) DXGI_FORMAT
+ SampleDesc {Count=1 Quality=0 } DXGI_SAMPLE_DESC
Usage D3D11_USAGE_DEFAULT (0) D3D11_USAGE
BindFlags 8 unsigned int
CPUAccessFlags 0 unsigned int
MiscFlags 0 unsigned int
这里值得一提的还有我的 Vertex-Setup:
Vertex v[] =
{
Vertex(-32.f, -32.f, 1.0f, 0.0f, 1.0f),
Vertex(-32.f, 32.f, 1.0f, 0.0f, 0.0f),
Vertex(32.0f, -32.f, 1.0f, 1.0f, 1.0f),
Vertex(32.0f, 32.f, 1.0f, 1.0f, 0.0f)
};
应该创建大小为 64x64 的四边形。
编辑 3: 我尝试生成 Mip-Maps 以查看是否有效,但没有成功。以下是可用的 7 个 Mip 级别中的两个:
还有新的纹理描述:
Width 64 unsigned int
Height 64 unsigned int
MipLevels 7 unsigned int
ArraySize 1 unsigned int
Format DXGI_FORMAT_B8G8R8A8_UNORM (87) DXGI_FORMAT
+ SampleDesc {Count=1 Quality=0 } DXGI_SAMPLE_DESC
Usage D3D11_USAGE_DEFAULT (0) D3D11_USAGE
BindFlags 8 unsigned int
CPUAccessFlags 0 unsigned int
MiscFlags 0 unsigned int
我觉得不错,但结果还是一样:/.
@Gnietschow:谢谢你的努力。解决方案非常简单,它被 gamedev.net 版块中的一些人找到:
引用:
I had a similiar issue once, and it turned out I was doing windowed mode wrong in terms of calculating the window size to fit the backbuffer size etc., resulting in a vaguely stretched display that was hard to notice for a long while
I was going to say the same thing. You want to make sure that the client area of your window is the same size as your D3D backbuffer, otherwise you'll get really crappy scaling when the backbuffer is blit onto the window. You can use something like this:
RECT windowRect; SetRect(&windowRect, 0, 0, backBufferWidth, backBufferHeight); BOOL isMenu = (GetMenu(hwnd) != nullptr); if(AdjustWindowRectEx(&windowRect, style, isMenu, exStyle) == 0) DoErrorHandling(); if(SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOMOVE) == 0) DoErrorHandling();
来源:http://www.gamedev.net/topic/677243-iso-dimetric-tile-texture-has-jagged-edges/