PrismaticFlower / shaderpatch

Improved shaders (and fun stuff for modders) for Star Wars Battlefront II (2005) - Incompatible with Classic Collection
MIT License
39 stars 2 forks source link

Add high DPI awareness support #100

Closed PrismaticFlower closed 3 years ago

PrismaticFlower commented 4 years ago

Currently if you start the game with SP enabled Windows provide DPI virtualization for the window size. This is done to SP using GetMonitorInfoW and MonitorFromWindow to position the game's window. Without marking the thread as DPI aware it gives back virtual sizes and then Windows scales the game's window itself to match the real size later on.

This gives a blurry result because SP draws the game at the virtual resolution Windows gave it. Fixing parts of this is fairly simple, I've already done some rough tests in a local branch.

We could easily just mark the game's thread as DPI aware, this would solve the blurriness but would create big problems for actual high DPI displays.

A better solution would be to actually implement DPI scaling for the game. The first part of doing this is easily done, pass back a virtual resolution to the game ourselves and then actually draw the game at a higher resolutions. This would require some touch ups in some places like the fixed function shaders and StretchRect but overall would be manageable.

The problems start once we get to UI rendering. The game's bitmap fonts and UI elements are not intended to be drawn at high DPIs. We can kind of get away with cubic sampling for the UI elements but text just looks downright bad. Meaning if we want to look good at high DPIs we need to replace the game's fonts with one's we've rendered based on the current DPI. Mods would continue to be screwed sadly.

The best thing I can think of might be to introduce a custom material specifically for font rendering then we replace the game's fonts with that whenever it loads core.lvl like we do for shaders already.

Solving this properly is probably going to take a fair amount of work but I think it is worth looking into.

PrismaticFlower commented 3 years ago

Implemented by 32e0fe5cd1dad938d37f3e41e5ab78b56786f9e7