Author Topic: Widescreen/fov misalignment fix  (Read 11515 times)

0 Members and 1 Guest are viewing this topic.

Offline Murleen

  • Perspective Perfector
  • 21
Widescreen/fov misalignment fix
Hi all,

I've been poking around in the code looking at the 2d/3d misalignment problem, and I think I've worked up a fix. There were two basic issues - the aspect scaling code was broken - it looks like it was intended to increase the horizontal fov when the width was greater than the height, and decrease the vertical fov otherwise. Unfortunately the if condition was wrong, so the vertical fov decrease was always being applied. Since the OpenGL projection fixes the vertical fov, I've changed the aspect scaling code to match. The second problem was the View_zoom being improperly applied - the 2d code was treating it as a linear zoom factor, while the 3d code multiplied it by an 80 degree vertical fov angle. Here's the patch:

Code: [Select]
Index: code/render/3dsetup.cpp
===================================================================
RCS file: /home/fs2source/cvsroot/fs2_open/code/render/3dsetup.cpp,v
retrieving revision 2.22.2.1
diff -u -r2.22.2.1 3dsetup.cpp
--- code/render/3dsetup.cpp     1 Oct 2006 19:31:19 -0000       2.22.2.1
+++ code/render/3dsetup.cpp     14 Feb 2008 17:58:32 -0000
@@ -284,15 +284,8 @@

        s = aspect*(float)Canvas_height/(float)Canvas_width;

-       if (s <= 0) {           //scale x
-               Window_scale.xyz.x = s;
-               Window_scale.xyz.y = 1.0f;
-       }
-       else {
-               Window_scale.xyz.y = 1.0f / s;
-               Window_scale.xyz.x = 1.0f;
-       }
-
+       Window_scale.xyz.x = s;
+       Window_scale.xyz.y = 1.0f;
        Window_scale.xyz.z = 1.0f;              //always 1

        init_free_points();
@@ -371,17 +364,10 @@

        Matrix_scale = Window_scale;

-       if (View_zoom <= 1.0)           //zoom in by scaling z
-
-               Matrix_scale.xyz.z =  Matrix_scale.xyz.z*View_zoom;
+       float f = 1.0 / tan((double) Proj_fov / 2.0);

-       else {                  //zoom out by scaling x&y
-
-               float s = (float)1.0 / View_zoom;
-
-               Matrix_scale.xyz.x = Matrix_scale.xyz.x*s;
-               Matrix_scale.xyz.y = Matrix_scale.xyz.y*s;
-       }
+       Matrix_scale.xyz.x = Matrix_scale.xyz.x*f;
+       Matrix_scale.xyz.y = Matrix_scale.xyz.y*f;

        //now scale matrix elements

It's more than possible that I've missed something here, but it seems to be pretty solid for me with wacky fov and aspect settings...

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Widescreen/fov misalignment fix
I always get a warm feeling when someone's first post is a code fix. :D
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Re: Widescreen/fov misalignment fix
I always get a warm feeling when someone's first post is a code fix. :D
Yeah, that is always pretty nice. :)


I need to test this out when I get back home before I can give it my official thumbs up, but this is easily the best best idea I've seen so far to address the problem.  This patch doesn't really touch on the root of the problem, it's a bit more complicated than that, but it certainly appears to come damn close to making the proper fix a wasted effort (which is would do if the proper fix didn't offer performance improvements).  I'll test it out in a few hours, and if everything appears to work fine then I'll go ahead and commit it.  :)

And I'm sure that you could end up getting a cookie out this, or a carrot, or a beer, or a pizza, or whatever it may be that turns you on in a congratulatory-gift sort of way. :D


EDIT:  Works great for me.  Fantastic work Murleen, I'll commit this later tonight! :)
« Last Edit: February 14, 2008, 02:36:47 pm by taylor »

 

Offline Jeff Vader

  • The Back of the Hero!
  • 212
  • Bwahaha
Re: Widescreen/fov misalignment fix
And I'm sure that you could end up getting a cookie out this, or a carrot, or a beer, or a pizza, or whatever it may be that turns you on in a congratulatory-gift sort of way. :D
If this works, I recommend a proper custom title. As a laptop user, I'd also be happy if a widescreen fix was to be implemented.
23:40 < achillion > EveningTea: ass
23:40 < achillion > wait no
23:40 < achillion > evilbagel: ass
23:40 < EveningTea > ?
23:40 < achillion > 2-letter tab complete failure

14:08 < achillion > there's too much talk of butts and dongs in here
14:08 < achillion > the level of discourse has really plummeted
14:08 < achillion > Let's talk about politics instead
14:08 <@The_E > butts and dongs are part of #hard-light's brand now
14:08 <@The_E > well
14:08 <@The_E > EvilBagel's brand, at least

01:06 < T-Rog > welp
01:07 < T-Rog > I've got to take some very strong antibiotics
01:07 < achillion > penis infection?
01:08 < T-Rog > Chlamydia
01:08 < achillion > O.o
01:09 < achillion > well
01:09 < achillion > I guess that happens
01:09 < T-Rog > at least it's curable
01:09 < achillion > yeah
01:10 < T-Rog > I take it you weren't actually expecting it to be a penis infection
01:10 < achillion > I was not

14:04 < achillion > Sometimes the way to simplify is to just have a habit and not think about it too much
14:05 < achillion > until stuff explodes
14:05 < achillion > then you start thinking about it

22:16 < T-Rog > I don't know how my gf would feel about Jewish conspiracy porn

15:41 <-INFO > EveningTea [[email protected]] has joined #hard-light
15:47 < EvilBagel> butt
15:51 < Achillion> yes
15:53 <-INFO > EveningTea [[email protected]] has quit [Quit: http://www.mibbit.com ajax IRC Client]

18:53 < Achillion> Dicks are fun

21:41 < MatthTheGeek> you can't spell assassin without two asses

20:05 < sigtau> i'm mining titcoins from now on

00:31 < oldlaptop> Drunken antisocial educated freezing hicks with good Internet == Finland stereotype

11:46 <-INFO > Kobrar [[email protected]] has joined #hard-light
11:50 < achtung> Surely you've heard of DVDA
11:50 < achtung> Double Vaginal Double ANal
11:51 < Kobrar> ...
11:51 <-INFO > Kobrar [[email protected]] has left #hard-light []

 

Offline Kazan

  • PCS2 Wizard
  • 212
  • Soul lives in the Mountains
    • http://alliance.sourceforge.net
Re: Widescreen/fov misalignment fix
He's got Perspective.
PCS2 2.0.3 | POF CS2 wiki page | Important PCS2 Threads | PCS2 Mantis

"The Mountains are calling, and I must go" - John Muir

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: Widescreen/fov misalignment fix
Title'd. :D

Will this work for FRED too? :)

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Re: Widescreen/fov misalignment fix
Will this work for FRED too? :)
Not sure yet, I'll be testing that a bit later today before I commit.  There are already a couple of issue with the fix that required some minor changes so that it works better, but that wasn't a big deal.  But after the necessary changes I haven't found any test case that doesn't work so far. :)

 

Offline Woolie Wool

  • 211
  • Fire main batteries
Re: Widescreen/fov misalignment fix
Hi all,

I've been poking around in the code looking at the 2d/3d misalignment problem, and I think I've worked up a fix. There were two basic issues - the aspect scaling code was broken - it looks like it was intended to increase the horizontal fov when the width was greater than the height, and decrease the vertical fov otherwise. Unfortunately the if condition was wrong, so the vertical fov decrease was always being applied. Since the OpenGL projection fixes the vertical fov, I've changed the aspect scaling code to match. The second problem was the View_zoom being improperly applied - the 2d code was treating it as a linear zoom factor, while the 3d code multiplied it by an 80 degree vertical fov angle. Here's the patch:

Code: [Select]
Index: code/render/3dsetup.cpp
===================================================================
RCS file: /home/fs2source/cvsroot/fs2_open/code/render/3dsetup.cpp,v
retrieving revision 2.22.2.1
diff -u -r2.22.2.1 3dsetup.cpp
--- code/render/3dsetup.cpp     1 Oct 2006 19:31:19 -0000       2.22.2.1
+++ code/render/3dsetup.cpp     14 Feb 2008 17:58:32 -0000
@@ -284,15 +284,8 @@

        s = aspect*(float)Canvas_height/(float)Canvas_width;

-       if (s <= 0) {           //scale x
-               Window_scale.xyz.x = s;
-               Window_scale.xyz.y = 1.0f;
-       }
-       else {
-               Window_scale.xyz.y = 1.0f / s;
-               Window_scale.xyz.x = 1.0f;
-       }
-
+       Window_scale.xyz.x = s;
+       Window_scale.xyz.y = 1.0f;
        Window_scale.xyz.z = 1.0f;              //always 1

        init_free_points();
@@ -371,17 +364,10 @@

        Matrix_scale = Window_scale;

-       if (View_zoom <= 1.0)           //zoom in by scaling z
-
-               Matrix_scale.xyz.z =  Matrix_scale.xyz.z*View_zoom;
+       float f = 1.0 / tan((double) Proj_fov / 2.0);

-       else {                  //zoom out by scaling x&y
-
-               float s = (float)1.0 / View_zoom;
-
-               Matrix_scale.xyz.x = Matrix_scale.xyz.x*s;
-               Matrix_scale.xyz.y = Matrix_scale.xyz.y*s;
-       }
+       Matrix_scale.xyz.x = Matrix_scale.xyz.x*f;
+       Matrix_scale.xyz.y = Matrix_scale.xyz.y*f;

        //now scale matrix elements

It's more than possible that I've missed something here, but it seems to be pretty solid for me with wacky fov and aspect settings...

I think I love you. In a completely platonic way of course. :D
16:46   Quanto   ****, a mosquito somehow managed to bite the side of my palm
16:46   Quanto   it itches like hell
16:46   Woolie   !8ball does Quanto have malaria
16:46   BotenAnna   Woolie: The outlook is good.
16:47   Quanto   D:

"did they use anesthetic when they removed your sense of humor or did you have to weep and struggle like a tiny baby"
--General Battuta

 

Offline jdjtcagle

  • 211
  • Already told you people too much!
Re: Widescreen/fov misalignment fix
Great job !!!
"Brings a tear of nostalgia to my eye" -Flipside
------------------------------------------
I'm an Apostolic Christian (Acts: 2:38)
------------------------------------------
Official Interplay Freespace Stories
Predator
Hammer Of Light - Omen of Darkness
Freefall in Darkness
A Thousand Years

 

Offline FSW

  • 27
Re: Widescreen/fov misalignment fix

 
Re: Widescreen/fov misalignment fix

All this success, and we forgot the most sacred of welcomes :)
And he gets a custom title with his first post!
(in a completely freindly way) CONGRAGU-****ING-LATIONS! WE FINALLY HAVE THE DAMNED WIDESCREEN FOV FIX! :D

Now...um...how do i use it? :confused:
Fun while it lasted.

Then bitter.

 

Offline colecampbell666

  • I See Dead Pictures
  • 212
  • Evolution and ascension.
Re: Widescreen/fov misalignment fix
Wait for a build. Has anyone, besides the Hammer of 0wnage or Thunder Kalfireth Thunder, got a title on their first post or before posting?
Gettin' back to dodgin' lasers.

 

Offline achtung

  • Friendly Neighborhood Mirror Guy
  • 210
  • ****in' Ace
    • Minecraft
    • Freespacemods.net
Re: Widescreen/fov misalignment fix
Kind of like finding a hundred dollar bill on the street.
FreeSpaceMods.net | FatHax | ??????
In the wise words of Charles de Gaulle, "China is a big country, inhabited by many Chinese."

Formerly known as Swantz

 

Offline Turambar

  • Determined to inflict his entire social circle on us
  • 210
  • You can't spell Manslaughter without laughter
Re: Widescreen/fov misalignment fix
beautiful!

no more black bars or misleading lead indicators for me!
10:55:48   TurambarBlade: i've been selecting my generals based on how much i like their hats
10:55:55   HerraTohtori: me too!
10:56:01   HerraTohtori: :D

 

Offline Bob-san

  • Wishes he was cool
  • 210
  • It's 5 minutes to midnight.
Re: Widescreen/fov misalignment fix
Will this work properly for 5:4 aspect ratio as well as 16:9 and 16:10?
NGTM-1R: Currently considering spending the rest of the day in bed cuddling.
GTSVA: With who...?
Nuke: chewbacca?
Bob-san: The Rancor.

 
Re: Widescreen/fov misalignment fix
what kind of screen uses 5:4 anyway?
Fun while it lasted.

Then bitter.

 

Offline Herra Tohtori

  • The Academic
  • 211
  • Bad command or file name
Re: Widescreen/fov misalignment fix
1280x1024...

Rather common resolution, I daresay. :p
There are three things that last forever: Abort, Retry, Fail - and the greatest of these is Fail.

 
Re: Widescreen/fov misalignment fix
yeah, but do common CRT monitors support that? what would you need that ratio for anyway?
Fun while it lasted.

Then bitter.

 

Offline CP5670

  • Dr. Evil
  • Global Moderator
  • 212
Re: Widescreen/fov misalignment fix
They support it and a lot of people use it, but it's the wrong ratio for them and makes things look squished. 5:4 LCDs were made as such because this resolution was so common on CRTs.

 
Re: Widescreen/fov misalignment fix
That's a great news!
Just need to wait opengl version of softh and i ll be able to play fs2 with my 3screens   :yes:
That fix , the track ir suppport and virtual cockpit that are coming both, scp engine open his way to simulator's immersion feeling!

 :nod:
$Formula: ( every-time
   ( has-time-elapsed "0" )
   ( Do-Nothing
   )
   ( send-message
      "#Dalek"
      "High"
      "Pro-crasti-nate"
   )
   )
)
+Name: Procratination
+Repeat Count: 99999999999
+Interval: 1