原始厚度 - DX10
我最近开始使用 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的情况下尝试了最低设置)
i recently stepped into primitive rendering in directX10. I need that because i want to convert my ingame chat from directx9 to 10 due my huge performance lag being forced by the games weak dx9 support. The lines are being rendered fine on the positions i want. My actual problem is that they doesnt appear as thin as in directX9 (1 pixel width). They seem to be more thick than a pixel. I've read some around and found some info that its possible to fix that with some kind of geometry shader. Does anybody know how that would work and how it would look code wise? I am not into it that deep.
Attached is the drawLine method (initialization isnt needed i belive, if so i'll post it immediliantly)
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);
}
And my effect
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()));"
" }"
"}";
Example of the output in Bad Company 2 running in windowed mode on highest settings (also tried lowest already with AA off)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很奇怪。我不明白为什么你在游戏上下文中看到超过 1 个像素宽度的线(如果你没有设置 GS )。
D3D10_PRIMITIVE_TOPOLOGY_LINELIST
状态始终生成 1 像素宽度的线,这就是规范。一条线可能超过一个像素宽度的唯一原因是因为您有一个 GS 着色器,可以将一条线扩展为四边形或其他形状。我很确定游戏在某处设置了几何着色器。
This is weird. I don't understand why you see more than 1 pixel-width lines in the game context (if you don't have GS set ).
D3D10_PRIMITIVE_TOPOLOGY_LINELIST
state always produces 1 pixel-width lines, that's the specification.The only reason a line could be more than one pixel width is because you have a GS shader that expands a line into a quad or whatever. I'm pretty sure that the game set a geometry shader somewhere.
我发现了同样的问题。
就我而言,问题是抗锯齿(multisamle count = 8 & multisampleQuality = 32)&光栅化中的标志:
计数 = 1 且质量 = 8 时工作正常(线条宽度为 1 像素),但对于 8/32 线条变为 2 像素宽度。
我解决了将 rasterDesc.AntialiasedLineEnable 更改为 false 的问题。
也许它对你有用。
I found the same problem.
In my case the problem was anti-aliasing (multisamle count = 8 & multisampleQuality = 32) & flag in rasterization:
With count=1 and quality=8 that worked OK (1 pixel width for line), but for 8/32 line became 2 pixel width.
I solved the problem over changing rasterDesc.AntialiasedLineEnable to false.
Maybe it will work for you.