2

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)

Frank
  • 31
  • 5
  • Do you want 3D lines with a fixed screen width? (such as with glLineWidth command) – elmattic Aug 26 '10 at 15:18
  • I want to draw 2D. DX9 works fine, 1px thin lines: http://img828.imageshack.us/img828/8417/lolwf.png DX10 is my problem, not one px thin lines: http://img828.imageshack.us/img828/346/screenshotvg.png – Frank Aug 26 '10 at 15:27
  • I've tested the code in my DX10 test environment. The lines appear fine in there. So i am quite sure its some renderState or something else forcing that bug when running in the games context. I've tried to reset the devices state with ->ClearnState() but that didnt work out. – Frank Aug 27 '10 at 07:50

2 Answers2

0

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.

elmattic
  • 12,046
  • 5
  • 43
  • 79
  • That could be possible. In my code i am setting the GeometryShader to NULL so how can the games preset GS affect my code? Thats how i init my Inputlayout and stuff: http://privatepaste.com/f6ea42a721/oijoiggggg As you see in my draw function at the top of this thread i am always applying my own EffectPass. And that doesnt include any GS – Frank Aug 27 '10 at 09:22
  • I don't know how this can happen! Did you try to debug the states with PIX? I would do that first. Just to make sure I'm heading in the right direction. – elmattic Aug 27 '10 at 10:02
  • Check this out: http://msdn.microsoft.com/en-us/library/ee418737(VS.85).aspx Select single frame capture (hit F12 for capturing a frame where you see your wrong lines), then analyse the capture :) – elmattic Aug 27 '10 at 10:24
  • Gonna try that out after work. Just got a stupid mac book pro in here^^ Should i post the results in here or do you have some instant messanger i could catch you at. Thanks for your help! – Frank Aug 27 '10 at 10:28
0

I found the same problem. In my case the problem was anti-aliasing (multisamle count = 8 & multisampleQuality = 32) & flag in rasterization:

D3D11_RASTERIZER_DESC rasterDesc;
rasterDesc.AntialiasedLineEnable = true;

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.

HappySDE
  • 36
  • 2