VOGONS


Texel alignment

Topic actions

First post, by UCyborg

User metadata
Rank Member
Rank
Member

There is another issue that dgVoodoo doesn't solve, regarding texture coordinates or something along those lines. Some games don't render text correctly as the result of the problem, usually results in blurry text. Ancient NVIDIA cards had driver setting to correct that, it was called Texel Alignment.

AMD cards still have the setting, but I don't know how to adjust it on per-application basis on today's drivers. The setting is stored in the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\0000\UMD

You're looking for PixelCenter, which defaults to 30 00 00 00. Change it to 31 00 00 00, and the text in such games will render correctly under native DX. ATI Tray Tools has the option called Alternate Pixel Centers, which could be used on older cards to activate the setting on per-application basis.

So the question is, would it be possible to implement the functionality of said function in dgVoodoo? Soulbringer is the example of the game that has the issue and its settings for texel alignment don't do anything, not under native DX, not under dgVoodoo. The text appears correctly only in software mode.

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.

Reply 1 of 9, by Dege

User metadata
Rank l33t
Rank
l33t

Yes, the need for this kind of hacking is turning into a burning question.
I have some development plans for introducing the possibility of that.

I'll try to solve it in a way that an average user doesn't even encounter it while letting an expert one produce a special config for a particular game (for distributing). So, GUI control panel won't be affected.

Reply 2 of 9, by UCyborg

User metadata
Rank Member
Rank
Member

Sounds good! I hope it works out in the end. One more interesting thing, Drakan: Order of the Flame has the option called Text Adjustment, defaults to Normal on today's cards, but on those old Voodoos it defaults to Shifted to make the text right. Anyway, I figured another use for the option, to be able to use regular MSAA anti-aliasing without corrupting the text, this has to be set to Shifted and Alternate Pixel Centers has to be enabled.

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.

Reply 3 of 9, by UCyborg

User metadata
Rank Member
Rank
Member

I've read about NFS III Modern Patch, it fixes these issues in its DX renderers. I think patching each individual game would be ideal solution, this way, you'd get correct results in every scenario, with a wrapper or not. Given that I have no clue about how these things work internally, I wonder how complex such a patch needs to be.

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.

Reply 4 of 9, by Dege

User metadata
Rank l33t
Rank
l33t

Yes, that's the other way. Needs finding the points from where the game calls some DrawPrimitive methods of the D3DDevice (feeding with vertex data) and modify the game code producing the text vertices to offset the x/y coordinates by 0.5.

Reply 5 of 9, by UCyborg

User metadata
Rank Member
Rank
Member

I've managed to patch Drakan to look good with forced MSAA, it has perfectly clear text now on any graphics card through any API. Although the results are not 100% the same as on ATI with Alternate Pixel Centers + original texel shift code. Small upper portion of the scroll bar in Options menus gets blurred.

So it's 99,99% good and I'll probably lose my sanity if I try to make it 100%. But the text is perfect. Things never looked 100% good on default settings actually, eg. in Options menus, you can see borders around certain things not having the yellow outline on the left side, the yellow part is apparently misaligned a little. I could get that part right by further shifting the X component, but decided to leave it as it is for consistency with default settings.

I did have to mess with x and y members of D3DVERTEX structure, as well as with tu and tv to get the current results and given that I had no clue what I was doing, the final outcome is quite satisfactory. The original code only altered the tu member.

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.

Reply 6 of 9, by Dege

User metadata
Rank l33t
Rank
l33t

Great!

I'm curious how it looks. 😀

Reply 7 of 9, by UCyborg

User metadata
Rank Member
Rank
Member

I have the patched game on Google Drive. You mustn't forget to enable Fix Texture Coordinates in Riot Engine Options window. It can always be opened by holding Shift when starting the game. Same option is disguised as Text Adjustment in game's Options->Graphics menu.

Drakan AiO Patch ZIP has the registry fix that allows Alt-Tab to work. Windows blocks it by default because there are some obsolete entries in its compatibility database which aren't needed these days. There is also additional installable compatibility database in there which restores Win9x behavior of registry manipulation APIs for the Level Editor to be able to store the list of recent files properly.

The editor does something funny that disables desktop composition on Windows Vista and 7. On 8 and above, where DWM is always on, there is strange issue with texture previews in Databases window, Textures tab. If you view textures that are larger than preview squares, they don't display properly. When going above 256x256, there is usually just blackness. Interestingly, the same bug occurs on Windows NT 4.0. But from Windows 98 to Windows 7, it's fine. Attempting to use dgVoodoo with the editor makes it crash as soon as it tries to draw the level. Behavior on WINE is even more curious, there is always blackness, regardless of size, but if you move the window in which previews are supposed to be a little, you see them imprinted on the surface on the window below where game level you're working on is displayed in 2D!

I've read on MSDN that calling DirectDraw Lock method on primary video buffer will cause composition to get disabled. Blitting to that buffer without a clipping window is also something that shouldn't be done. Perhaps these facts have something to do with those issues.

The editor is in the Editor subfolder BTW. I think it's quite interesting piece of software. Drakan was Surreal Software's only game that came with such tools.

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.

Reply 8 of 9, by UCyborg

User metadata
Rank Member
Rank
Member

There is another glitch, the vertical line going through part of the in-game map (Tab key). There has to be a better formula to get correct results. I use the following adjustments:

D3DVERTEX.x -= 0.5;
D3DVERTEX.y -= 0.5;
D3DVERTEX.tu -= 0.5 / some number;
D3DVERTEX.tv += 0.5 / some number;

Not really sure what some number is supposed to be, it's always power of two, perhaps texture size? With alternate pixel centers enabled and anti-aliasing applied, text is more distorted than with APC disabled and anti-aliasing applied, but in the first case, the original formula in the game's code makes everything perfect:

D3DVERTEX.tu -= 0.5 / some number;

Setting TexelShiftMode to 0 in Arokh.ini enables original formula.

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.

Reply 9 of 9, by UCyborg

User metadata
Rank Member
Rank
Member

OK, it turned out the D3DVERTEX.tv adjustment is redundant, hence the scroll bar blurring. Also, that vertical line through the map also appears with ATI's APC + plus original formula, so I'd just have to detect somehow that the map is opened and bail out in such case. Guess that's what I'll try to fix next when I have more time. I found the switch-case that gets activated when you open the map in the past, but I haven't noted it down. 😵

Arthur Schopenhauer wrote:

A man can be himself only so long as he is alone; and if he does not love solitude, he will not love freedom; for it is only when he is alone that he is really free.