我最近开始在directX10 中进行原始渲染。我需要它,因为我想将我的游戏内聊天从 directx9 转换为 10,因为游戏弱 dx9 支持迫使我存在巨大的性能滞后。这些线条在我想要的位置上渲染得很好。我的实际问题是它们看起来不像directX9(1像素宽度)那样薄。它们似乎比像素还要厚。我已经阅读了一些信息,发现一些信息可以使用某种几何着色器来解决这个问题。有谁知道这将如何工作以及它在代码方面的表现如何?我没有那么深。
附件是drawLine方法(我相信不需要初始化,如果需要,我会立即发布)
void drawLine(int x1, int y1, int x2, int y2, D3DCOLOR lineColor) {
VERTEX Vertices[] = {
/*p1*/{getScreenPercentage(x1, y1), lineColor}, //getScreenPercentage puts the given screencoords into the rasterized state
/*p2*/{getScreenPercentage(x2, y2), lineColor}
};
pDevice->IASetInputLayout(pVertexLayout);
UINT stride = sizeof(VERTEX);
UINT offset = 0;
pDevice->IASetVertexBuffers(0, 1, &p2pBuffer, &stride, &offset);
VERTEX* pVoid;
p2pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**)&pVoid);
pVoid[0] = Vertices[0];
pVoid[1] = Vertices[1];
p2pBuffer->Unmap();
pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
pPass->Apply(0);
pDevice->Draw(2, 0);
}
还有我的效果
char szEffect[] =
"struct DATA"
"{"
" float4 Pos : SV_POSITION;"
" float4 Color : COLOR;"
"};"
"DATA VS(float4 Pos : POSITION, float4 Col : COLOR)"
"{"
" DATA Data;"
" Data.Pos = Pos;"
" Data.Color = Col;"
" return Data;"
"}"
"float4 PS(DATA Data) : SV_TARGET"
"{"
" return Data.Color;"
"}"
"technique10 T0"
"{"
" pass P0"
" {"
" SetVertexShader(CompileShader(vs_4_0, VS()));"
" SetGeometryShader(NULL);"
" SetPixelShader(CompileShader(ps_4_0, PS()));"
" }"
"}";
Bad Company 2 中在窗口模式下以最高设置运行的输出示例(也已在 AA 关闭的情况下尝试最低)