Linux: Fix to the slightly blurry rendering on linux

Technical support for the Linux and Mac platforms for all Trine games.
fb_jpk2
Posts: 6
Joined: Sat Apr 16, 2011 1:21 pm

Linux: Fix to the slightly blurry rendering on linux

Postby fb_jpk2 » Sat Apr 16, 2011 2:09 pm

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.

KameZero
Posts: 15
Joined: Sat Apr 16, 2011 5:28 pm

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

Postby KameZero » Sat Apr 16, 2011 5:31 pm

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.

User avatar
fb_joel
Site Admin
Posts: 2482
Joined: Fri Feb 18, 2005 2:14 pm
Location: Finland

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

Postby fb_joel » Sat Apr 16, 2011 8:02 pm

jpk, you are my (our) hero. Thanks a lot. :)
// Joel, Frozenbyte team

Xpander
Posts: 34
Joined: Fri Apr 15, 2011 5:40 am
Location: Estonia

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

Postby Xpander » Sat Apr 16, 2011 8:35 pm

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
Linux Mint 13 alpha 64bit
* AMD Phenom II x4 955 BE (3,2 ghz)
* 8GB ddr3 1600mhz
* Asus GTX 560Ti DirectCU

kepi
Posts: 2
Joined: Sun Apr 17, 2011 12:36 pm

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

Postby kepi » Sun Apr 17, 2011 12:40 pm

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.

alt_turo
Posts: 195
Joined: Mon Dec 13, 2010 11:06 am

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

Postby alt_turo » Sun Apr 17, 2011 1:34 pm

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.
Turo Lamminen
Alternative Games

alt_turo
Posts: 195
Joined: Mon Dec 13, 2010 11:06 am

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

Postby alt_turo » Sun Apr 17, 2011 5:01 pm

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.
Turo Lamminen
Alternative Games

Xpander
Posts: 34
Joined: Fri Apr 15, 2011 5:40 am
Location: Estonia

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

Postby Xpander » Sun Apr 17, 2011 6:10 pm

thx. works fine.
any idea about anti aliasing and anisotrophic filtering?
Linux Mint 13 alpha 64bit
* AMD Phenom II x4 955 BE (3,2 ghz)
* 8GB ddr3 1600mhz
* Asus GTX 560Ti DirectCU

fredd
Posts: 4
Joined: Tue Aug 16, 2011 2:13 pm

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

Postby fredd » Wed Oct 05, 2011 1:29 pm

Splendid. Works as desired.
For anti aliasing and anisotrophic filtering this can be of help:
support.darkageofcamelot.com/kb/article.php?id=396


Return to “Trine Technical Support for Linux & Mac”

Who is online

Users browsing this forum: No registered users and 1 guest