SADX Mod Loader - Widescreen Fix
Posted by SonicFreak94 on 2015/07/31 05:47:57
As you may or may not have noticed, SADX PC allows you to select just about any resolution your display supports, and the mod loader allows you to set arbitrary resolutions. However, when it comes to widescreen, the field of view would become extremely low, leaving you with a super zoomed in game. This is why the mod manager has a "Force 4:3 Aspect Ratio" option, and probably the reason the Steam version doesn't even allow anything other than 4:3 resolutions. With the latest SADX Mod Loader, this is no longer a problem; the field of view now properly adjusts to widescreen resolutions.
An explanation as to why that happens, how it was fixed, as well as some comparison screenshots after the jump!
In this album you can see some comparison screenshots between 4:3, vanilla 16:9 and hacked 16:9. As you can see, the vanilla code visibly crops the image instead of expanding the field of view horizontally.
Why does that happen?
The reason for that is simple (once I figured it out, anyway): SADX operates on a vertical field of view. Somebody working on the game decided it would be a great idea to calculate that based on the horizontal resolution and field of view instead of using a static vertical field of view. As a result, as the screen gets wider, the vertical field of view gets narrower. I'm sure that was mostly obvious though. On the bright side, this method works great for portrait displays!
All the information I needed was here on this Wikipedia article. In the "Field of view calculations" section, the third formula is what the game does by default. Also noted in the "Field of view scaling methods" section is the specific name for this method: Vert-. What I did was make it use Hor+. Hor+ is much more common; even Sonic Riders and the modern ports of Sonic Adventure 2 use Hor+ instead of Vert-. Whether SA2 used that in the original code base or if that was added just for the ports remains to be discovered, though. Sonic Heroes is the odd one out--it doesn't adjust the FOV at all for widescreen resolutions at least. It just stretches! Maybe I should take that on next... Anyway:
How was it fixed?
The game passes the vertical field of view as a parameter to D3DXMatrixPerspectiveFovLH*. It's also calculated every frame to account for field of view changes during gameplay. An example of this would be Speed Highway. It changes the field of view as you gain speed, and I believe it's the only stage in the game to do that. Cutscenes also unsurprisingly change the field of view quite often.
* Fun fact: Sonic Riders uses D3DXMatrixPerspectiveFovRH, meaning it uses a right-handed perspective, whereas SADX uses a left-handed perspective.
So I noted the result of that calculation and stored the value statically (which is about 55.4 degrees, for those interested). I hooked several functions that change the field of view and used them to store a field of view multiplier. I then use that multiplier on the static value in some code injected just before the call to D3DXMatrixPerspectiveFovLH, and pass in the result as the desired vertical field of view.
As a result, the field of view expands horizontally as the resolution gets wider. I also decided to only enable this on aspect ratios that are determined to be widescreen. Otherwise--to use this example again--if you were to play the game in a portrait resolution, we would have the same cropping effect the game has normally for widescreen resolutions. That means there are no code changes if you play at 4:3, 5:4, or portrait aspect ratios.
Widescreen is better now. Enjoy.
Multialanfull54 wrote at 2017/02/05 22:26:09:
Multialanfull wrote at 2017/02/05 22:25:47:
Kell wrote at 2016/08/21 18:43:06:
Good job here! Thank you!
santi wrote at 2016/08/11 22:08:12:
santi wrote at 2016/08/11 22:07:01:
Mike Dexter wrote at 2015/11/26 02:46:24:
So, why are character models a different story for the SADX Mod Loader and Not the SA2 Mod Loader? When/Will we ever see a Dreamcast Models Mod for SADX, like how we have a DC Models mod for SA2?
Araraura wrote at 2015/08/24 19:56:37:
how do i install this?
MainMemory (registered) wrote at 2015/08/02 15:37:50:
It is compatible with hacked EXEs, as long as they're hacked from the US version. Character models are a different story, though.
Go! wrote at 2015/08/02 07:11:20:
Now make it work with hacked SADX.exes that have models edits. Then it will be perfect. (or just allow hacked exes to be compatible with the new modloader in general.) haha good stuff ^-^