Page 1 of 1

Linux: Fix to the slightly blurry rendering on linux

Posted: Sat Apr 16, 2011 2:09 pm
by fb_jpk2
There have been some posts about the native Trine linux port graphics not being quite the same as on the windows version - specifically the textures/screen looking blurry. So I decided to have a little peek myself too, and started the Ubuntu 9.04 install on my home computer... Yeah, its a bit old, I know, I haven't really been using linux lately. ;)

Nevertheless, the game seemed to work nicely on my Ubuntu 9.04 (with an Nvidia graphics card), but, indeed there was some apparent blurriness to the graphics.

Because the edges at the HUD (game console for example) were pixel perfect, this clearly could not be an issue with the drivers. It rather seemed to be some kind of texel offset issue (from the the DirectX to OpenGL transition), where the 3D scene (the deferred rendertarget) was still being rendered assuming DirectX texel offsetting, so the pixels were off by half a pixel...

I decided to take a quick look on the shaders and test if this could be easily fixed. And I managed to make some quick and dirty fix to the blurriness at least on my configuration. I assume that this will be fixed officially during monday or so, but if you are too eager to play Trine on Linux to wait for that, here's an explanation how to apply the temporary fix for those who are daring... :) Notice, this is a very dirty hack that will function correctly for a single selected resolution only!

1. Under your "trine" installation folder, there should be a "data/shader/cg" folder. Go there and look for the file "rendertarget_pixel.cg"

2. First make a backup copy of that file somewhere on your computer! Just to be safe. :)

3. Open the file in text editor.

4. Quite close to the top of the file, you should find a section looking like the following:
...

Code: Select all

    out   float4 oColor : COLOR)
{
   float2 textureCoord = texCoord0.xy;
   float2 glowCoord = texCoord0.zw;

   #ifdef USE_DISTORTION

...

5. Add the following lines after the line that contains "float2 glowCoord = texCoord0.zw;"

Code: Select all

// 1024x768 (offset by 0.5 / 1024, 0.5 / 768)
//textureCoord.x += 0.00048828;
//textureCoord.y += 0.00065104;

// 1280x720 (offset by 0.5 / 1280, 0.5 / 720)
//textureCoord.x += 0.00039062;
//textureCoord.y += 0.00069444;

// 1280x960 (offset by 0.5 / 1280, 0.5 / 960)
//textureCoord.x += 0.00039062;
//textureCoord.y += 0.00052083;

// 1280x1024 (offset by 0.5 / 1280, 0.5 / 1024)
textureCoord.x += 0.00039062;
textureCoord.y += 0.00048828;


6. If you are not running the game at the 1280x1024 resolution, comment the last 2 lines above by adding // at the start of those lines and remove the comments from some of the other lines (the 2 lines starting with textureCoord...)
If you are using some other resolution that one mentioned above, you can calculate the correct values with the formula: 0.5 / screen width for the x, and 0.5 / screen height for the y.

7. Now the section you just modified should look something like this: (assuming you're using, for example the 1280x720, resolution)

Code: Select all

    out   float4 oColor : COLOR)
{
   float2 textureCoord = texCoord0.xy;
   float2 glowCoord = texCoord0.zw;

// 1024x768 (offset by 0.5 / 1024, 0.5 / 768)
//textureCoord.x += 0.00048828;
//textureCoord.y += 0.00065104;

// 1280x720 (offset by 0.5 / 1280, 0.5 / 720)
textureCoord.x += 0.00039062;
textureCoord.y += 0.00069444;

// 1280x960 (offset by 0.5 / 1280, 0.5 / 960)
//textureCoord.x += 0.00039062;
//textureCoord.y += 0.00052083;

// 1280x1024 (offset by 0.5 / 1280, 0.5 / 1024)
//textureCoord.x += 0.00039062;
//textureCoord.y += 0.00048828;

   #ifdef USE_DISTORTION


8. Test it out. Start the game with the trine-launcher (and ensure that the resolution you selected was the correct one), and go play. If all things went right. You should now have crisper (and at least nearly pixel perfect) rendering. Happy gaming. Now you can enjoy the artwork in Trine for real. :)

Disclaimer: Though I have worked on Trine, I haven't worked on the Linux port of Trine nor on the actual renderer code, thus, this hack is as dirty as it gets (...to be honest, I barely knew what I was doing when hacking up that solution). :P
It will probably break things once the issue is fixed for real in some future update, and you may have to restore the file from the backup first before applying any updates. Also, remember that it works for a single selected screen size only, and if you happen to change the resolution, the pixels will be badly off unless you modify that shader file again.

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sat Apr 16, 2011 5:31 pm
by KameZero
Yup, this makes the game look 1000x better.

Hopefully Frozenbyte will focus solely on OpenGL in the future so we don't run into these issues.

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sat Apr 16, 2011 8:02 pm
by fb_joel
jpk, you are my (our) hero. Thanks a lot. :)

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sat Apr 16, 2011 8:35 pm
by Xpander
thx, it make game look much better.
only problem remaining for me is that AA and AF doesnt work. not from game options not from catalyst.
while works fine with other games like amnesia the dark descent for example

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sun Apr 17, 2011 12:40 pm
by kepi
For lazy ones :) there are values for 1680x1050 resolution

Code: Select all

 
  // 1680x1050 (offset by 0.5 / 1680, 0.5 / 1050)
  textureCoord.x += 0.000297619;
  textureCoord.y += 0.00047619;


Anyway, really thanks for this fix. Looks thousand times better.

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sun Apr 17, 2011 1:34 pm
by alt_turo
This is strange because there is code which should take care of this. Apparently there's bug somewhere in there. I'll fix it for the next version.

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sun Apr 17, 2011 5:01 pm
by alt_turo
So it looks like this was corrected in the lighting code but not the postprocessing code.

The game actually calculates the proper offsets for you. Add this after the line with COLOR_CONTROLS_RGB:

Code: Select all

    uniform float4 DEFERRED_TEXTURE_OFFSET,

and change textureCoord line to this:

Code: Select all

   float2 textureCoord = texCoord0.xy + (vec2(0.5, 0.5) * DEFERRED_TEXTURE_OFFSET.xy);


The official fix will be something very close to this.

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Sun Apr 17, 2011 6:10 pm
by Xpander
thx. works fine.
any idea about anti aliasing and anisotrophic filtering?

Re: Linux: Fix to the slightly blurry rendering on linux

Posted: Wed Oct 05, 2011 1:29 pm
by fredd
Splendid. Works as desired.
For anti aliasing and anisotrophic filtering this can be of help:
support.darkageofcamelot.com/kb/article.php?id=396