cakepie

[1.7.x ~ 1.3.x] unBlur [ v0.5.0 @ 2019-06-01 ]

Recommended Posts

Posted (edited)

unBlur
v0.5.0 @ 2019-06-01

KSP 1.3.x thru 1.7.x

 

This is a utility mod that allows fixing of blurry UI elements such as buttons and icons, which occurs when KSP's graphics settings are set to anything less than full-res textures.
This is a consequence of mipmapping, in conjunction with the way that Unity handles the texture quality setting, as explained here.

unBlur provides configurable, targeted fix of this issue by taking input config files that list the problematic textures. During KSP loading screen, unBlur will remove mipmaps from the targeted textures and ensure that their full-res version is loaded to the GPU. These changes are then persisted in the GameDatabase for subsequent use.

unBlur also provides other mods with a mechanism to programmatically fix blurry textures and fetch the resulting full-res version.

~ ~ ~ ~ ~

For Players

unBlur as a dependency of other mods

unBlur provides a way for other mods to use it to fix textures from another (third-party) mod that would cause blurry UI.
For example, although Toolbar mod can ensure that its own textures are nice and sharp, it also needs to display icons that are provided to it from other mods that are putting buttons on the toolbar. If those mods did not set up their icon textures properly, they may end up being blurry when displayed. In that case, Toolbar can ask unBlur to fix the blurry icons, to make sure that all toolbar icons show up nicely.

If you've not previously noticed any issues of blurry buttons or other UI -- this could simply be due to Toolbar having implemented a workaround for the problem. However, using unBlur as a dependency provides mods like Toolbar with a more efficient solution, with reduced I/O and memory overheads. Even if you have graphics settings at full texture resolution and are not affected by any blurry UI problems, you will reap the benefits from these improvements.

If another mod asks you to install unBlur as a dependency, this is the reason why.
If you have no need or desire to fix any blurry UI for any other mods, then there is nothing else you need to do.

Explicit usage by end-users

For end-users (that means you, the player!) unBlur gives you the ability to try to fix blurry images in other mods' UI without relying on a fix from the mod author/maintainer.
(Note that if you play with graphics settings at full texture resolution, this isn't a problem you'd even need to worry about.)

Do keep in mind that while unBlur gives you the power to fix things by yourself, if you encounter any mods with blurry UI, the best thing you could do is to politely point the mod author/maintainer at the information here so they can actually fix it for all users of the mod.

It should also be pointed out that if you are comfortable with fiddling with files in GameData, there is another approach you can take to try fixing blurry UI, without having to configure unBlur to do it for you. Just identify the *.png files for the mod that are showing up blurry, and try renaming them to *.truecolor instead. This should fix the issue in most cases. (Warning: you should really only do this for small UI textures like buttons and icons. Do NOT go rename all *.png files that you find, especially the bigger ones.)

However if you want to fix the problem but are not willing to mess around with the install and rename the files yourself, then unBlur is the right tool for the job. For example, for players who install mods via CKAN it is better not to mess with the files that CKAN installed, since doing so might cause problems with CKAN later e.g. when updating/uninstalling the mod. In that case, you can use this mod and fix the problem without actually changing any files of other mods.

To use unBlur you will need to add config files to tell unBlur which files to fix. You can easily write this yourself, instructions and examples are below. If you need help with unBlur-ing any mod in particular, post in this thread and someone from the community may be able to assist.

Things unBlur cannot help with

If a mod has textures that are too small for their intended purpose, they will inevitably be blurry when upscaled to fit the required size, even after unBlur has forced them to be at full resolution.

If a mod has code that manipulates textures programmatically rather than using them straight from the GameDatabase, then unBlur may not be able to help, in which case a fix from the mod author/maintainer is required.

~ ~ ~ ~ ~

Specifying problem textures to be fixed via config

unBlur uses the same config file format as KSP.
The basic node format is:

UNBLUR_BATCH{
  // stuff goes here
}

You can have as many nodes as you want, in as many *.cfg files as you want, anywhere in GameData directory.
Each node can contain multiple targets for unBlur to fix.

You can specify individual texture files by their relative location from GameData. Omit the filename extension.

UNBLUR_BATCH{
  unBlurTexture = modA/assets/toolbar/toolbar_on
  unBlurTexture = modA/assets/toolbar/toolbar_off
  unBlurTexture = modA/assets/icons/icon1
  unBlurTexture = modA/assets/icons/icon2
  unBlurTexture = modA/assets/icons/icon3
  unBlurTexture = modB/applauncher
  // etc ...
}

You can also specify that all texture files in a single directory should be targeted for fixing. (Trailing slash is required.)

UNBLUR_BATCH{
  unBlurFolder = modA/assets/icons/
  // etc ...
}

Or recursively include all texture files in a directory or its descendants. Be careful with this, do not accidentally include larger non-UI textures.

UNBLUR_BATCH{
  unBlurFolderRecursive = modA/assets/
  // etc ...
}

You can mix and match all three types:

UNBLUR_BATCH{
  unBlurFolderRecursive = modA/assets/
  unBlurTexture = modB/applauncher
  unBlurFolder = modC/buttons/
  // etc ...
}

There is an option that you can set which will try to compress any textures within that UNBLUR_BATCH block that are not already compressed

UNBLUR_BATCH{
  compress = true
  // compression will be attempted for all targets listed inside this UNBLUR_BATCH node
}

You can use Module Manager syntax, if you have MM installed.

UNBLUR_BATCH:NEEDS[modC]{
  unBlurFolder = modC/buttons/
  // stuff
}

A working example config for an actual existing mod is provided here.

~ ~ ~ ~ ~

Sharing unBlur configs

Feel free to share unBlur configs for fixing various mods in this thread; if there is enough demand I can also host contributed configs on the GitHub repo.

~ ~ ~ ~ ~

For Modders

For fixing blurry UI in your own mod, see information here.
You can use unBlur to learn more about what KSP is doing when it loads your textures. If you install unBlur you can use it to dump the texture info from GameData as was shown in the above linked thread.
Set the config for verbose debugging as shown below and the full list of textures will be dumped both before and after unBlur performs its fixes:

UNBLUR_DEBUG{
verbose=true
}

unBlur also provides a command you can use within KSP's Alt-F12 console to access its functionality. For usage, type:

/unBlur help

If you have a mod that accepts and uses textures from other mods, and have no control over those texture files, you can include this mod as a dependency and then use it to "unBlur" those textures before using them.
You can either:

  • Call DisableMipmaps() on the textures before fetching them using GameDatabase.Instance.GetTexture().
    This method is appropriate if you have multiple GetTexture() calls for the same texture in different places; adding a single DisableMipmaps() call in init code would suffice.
  • Call GetTexture(), which combines both steps and returns the Texture2D directly. (The result is null if requested texture is not found in GameDatabase.)
    This provides computational savings by not needing to search GameDatabase again to fetch the texture, and works well when a texture is only fetched once.

unBlur can also load DDS files, identified by either a UrlFile or the file path. DXT1, DXT3 and DXT5 formats are supported.
The behavior is similar to stock KSP DDS loading, but unBlur also allows ignoring mipmaps that are present in the file, which gives a texture that is always used at full resolution.
Note: any Texture2D that you obtain in this manner must be properly disposed (i.e. Destroy(tex);) when no longer needed, e.g. in OnDestroy().

~ ~ ~ ~ ~

License

MIT

~ ~ ~ ~ ~

Download

unBlur v0.5.0 for KSP 1.7.x
Should be backward compatible to at least 1.3.x if not older.
Compatible with Module Manager for patching configs. (Any fairly recent version should work properly)

Installation:
Delete older version, if any.
Put unBlur.x.x.x.dll into your installation's GameData folder.
Write or obtain config files specifying the UI textures that are blurry and need fixing.

Source: GitHub

Changelog:

v0.5.0 ~ 2019-06-01 ~ KSP 1.7.x - 1.3.x
Added input validation
Suppress repetitive logging for GetTexture() calls

v0.4.0 ~ 2019-05-17 ~ KSP 1.7.x - 1.3.x
Fix unreadable textures still being blurry
Implement DDS file reader with DXT1, DXT3 & DXT5 support

v0.3.0 ~ 2019-05-13 ~ KSP 1.7.x - 1.3.x
Add GetTexture() for convenience
Minor optimizations and improvements

v0.2.0 ~ 2019-05-06 ~ KSP 1.7.x  - 1.3.x
Add console command
Minor improvements and bugfixes

v0.1.0 ~ 2019-05-05 ~ KSP 1.7.x  - 1.3.x
Initial version

 

Edited by cakepie
v0.5.0

Share this post


Link to post
Share on other sites

Example config:

This config will fix some of the blurry UI in CommNetConstellation (currently v1.3.2) using unBlur.
Of course you can just rename the texture files yourself if you have the tech savvy, but this is an example
(Also this will probably not be needed anymore once changes from this PR make it into the next released version)

UNBLUR_BATCH:NEEDS[COMMNETCONSTELLATION]{
  compress = true
  unBlurFolder = CommNetConstellation/Textures/
}

 

Before, at quarter resolution textures:

https://i.imgur.com/J8YEiRG.png

 

After, at quarter resolution textures:

https://i.imgur.com/X8AfaYB.png

 

 

Share this post


Link to post
Share on other sites

v0.2.0

Functions can now be accessed via a console command.

https://i.imgur.com/PE45Lyi.png

Share this post


Link to post
Share on other sites
Posted (edited)

v0.4.0 fixes a bug.

v0.3.0 came out unannounced a few days ago, it was mostly improvements for modders, and was not aimed at players.

v0.4.0 ~ 2019-05-17 ~ KSP 1.7.x - 1.3.x
Fix unreadable textures still being blurry
Implement DDS file reader with DXT1, DXT3 & DXT5 support

v0.3.0 ~ 2019-05-13 ~ KSP 1.7.x - 1.3.x
Add GetTexture() for convenience
Minor optimizations and improvements
Edited by cakepie

Share this post


Link to post
Share on other sites

I know this is a single DLL, but having it in the GameData directory is confusing. 

Is there any reason it needs to be there?

Share this post


Link to post
Share on other sites
14 minutes ago, linuxgurugamer said:

is confusing. 

how so?

There is only one file, I have no foreseeable need to include anything else, so no need for a folder.

The file is clearly named to indicate what the mod is. The filename includes version number for ease of checking/updating for users doing manual install.

What are your concerns?

Share this post


Link to post
Share on other sites

Convention, if nothing else.  I installed it for testing the PR you did as well as the updates I did to the ToolbarController.  When i was looking for it, I always look for a mod to be in a directory, along with a .version file which lets AVC check to see if there is an update available.  Putting multiple DLLs in the GameData directory can make things messy over the long run if more mods start doing that.

BTW, your changes look fine and I'm testing now.

Share this post


Link to post
Share on other sites

Since I added unBlur (and the @linuxgurugamer beta test version of Toolbar, ToolbarController and Click Through Blocker) and changed to TEXTURE_QUALITY = 1 I get this log spamming in the VAB (for Resonant Orbit Calculator):

NullReferenceException: Object reference not set to an instance of an object
  at ResonantOrbitCalculator.ResonantOrbitCalculator.OnGUI () [0x00000] in <filename unknown>:0 
 
(Filename:  Line: -1)

and the icon of Resonant Orbit Calculator is missing.

Full log:
https://www.dropbox.com/s/q18nxj5396x5cpn/output_log.txt and stuff 2019-05-16-01.zip?dl=1

Share this post


Link to post
Share on other sites
14 minutes ago, Gordon Dry said:

Since I added unBlur (and the @linuxgurugamer beta test version of Toolbar, ToolbarController and Click Through Blocker) and changed to TEXTURE_QUALITY = 1 I get this log spamming in the VAB (for Resonant Orbit Calculator):


NullReferenceException: Object reference not set to an instance of an object
  at ResonantOrbitCalculator.ResonantOrbitCalculator.OnGUI () [0x00000] in <filename unknown>:0 
 
(Filename:  Line: -1)

and the icon of Resonant Orbit Calculator is missing.

Full log:
https://www.dropbox.com/s/q18nxj5396x5cpn/output_log.txt and stuff 2019-05-16-01.zip?dl=1

Sorry, you have too many changes, hard to know what's wrong.

Please revert the changes to the ToolbarController & ClickThroughBlocker and try again

Share this post


Link to post
Share on other sites

After reverting ToolbarController & ClickThroughBlocker problem is gone.

Share this post


Link to post
Share on other sites
5 minutes ago, Gordon Dry said:

After reverting ToolbarController & ClickThroughBlocker problem is gone.

Ok, I'll look into this later

Share this post


Link to post
Share on other sites

@linuxgurugamer you got this? Let me know if you need any help tracking this one down or further changes needed on my end.

Share this post


Link to post
Share on other sites
3 minutes ago, cakepie said:

@linuxgurugamer you got this? Let me know if you need any help tracking this one down or further changes needed on my end.

Thanks, I'll let you know.  

Share this post


Link to post
Share on other sites

Now I also revert Toolbar because of this:

eN4llsL.jpg

I just clicked the little arrow button to open the UI.

Share this post


Link to post
Share on other sites
6 hours ago, Gordon Dry said:

After reverting ToolbarController & ClickThroughBlocker problem is gone.

I found the problem, working on a fix now

Share this post


Link to post
Share on other sites
18 minutes ago, Gordon Dry said:

Now I also revert Toolbar because of this:

eN4llsL.jpg

I just clicked the little arrow button to open the UI.

Ok, I've fixed the problem in the ToolbarController.

You can download it here:

https://www.dropbox.com/s/0j5igo1i50u65bk/Beta_TCandCTBandToolbar-Beta2.zip?dl=0

I can't replicate the toolbar issue above.  One thin, the Toolbar now has the ClickThroughBlocker as a dependency, if you delete it, I'm not sure what would happen;  the updated toolbar is specifically looking for the new version of the ClickThrough Blocker.

So could you please try this new file and let us know how it goes?  Also, next time please provide a log file, which would have been able to confirm my theory.

Thanks

 

34 minutes ago, cakepie said:

@linuxgurugamer you got this? Let me know if you need any help tracking this one down or further changes needed on my end.

No need, found and fixed.  and his other issue may be related to the ones he uninstalled

Share this post


Link to post
Share on other sites

So am I understanding this right:

Unblur + Toolbar + ClickThroughBlocker will be dependencies (ie required) going forward? I see the advantage and (not that you require it) approve. Just looking ahead.

Share this post


Link to post
Share on other sites
1 hour ago, zer0Kerbal said:

So am I understanding this right:

Unblur + Toolbar + ClickThroughBlocker will be dependencies (ie required) going forward? I see the advantage and (not that you require it) approve. Just looking ahead.

Yes, for mods which use the toolbar

Share this post


Link to post
Share on other sites

I updated all three and all my previous mentioned issues are gone.

Share this post


Link to post
Share on other sites

So can use Unblur stand-alone; can use click through blocker (CTB) but if one uses TBC they will need to have Unblur and CTB installed.

So how much common code is shared? What I am asking is if one were to merge the 2-3 into one mod, eliminating common code with options to turn off parts not needed, how much space/mem/ips would be saved? Would it be worth it - would you be willing to?

I have already installed Unblur in aticipation of the change. My (probably irrational) perception is that doing so has helped performance. (220 or so mods, no glam-glam visual candy (except restock etc), 8gb decade old notebook, with amd dead, only integrated video surviving - ssd).

Share this post


Link to post
Share on other sites
4 hours ago, zer0Kerbal said:

So how much common code is shared?

I can't speak to the specifics within linuxgurugamer's mods, so you'd have to ask him if you want to know about TBC / CTB specifically.

But in general for cases like this:

a)
Part of the reason why Mod A has a dependency on Mod B is so that Mod A can use features implemented by Mod B without having to implement it themselves.
So typically there is little to no commonality of function in the first place.

In this specific instance since I did make some of the upcoming changes in blizzy toolbar I can say for a fact that I was able to remove some of its code because unBlur also had code that did the same thing.
This redundancy existed in this case because the upcoming changes are replacing toolbar's existing workaround for blurry icons with an improved solution. The redundant code has been removed in the process.

b)
Another reason to have separate mods and rely on dependencies is for reason of modularity. For example, there are other mods that require click-through-blocker. If you merge CTB into TBC that means other mods that need CTB must either force their users to install the whole CTB+TBC (even if the TBC part is not used), or else include their own copy of CTB-like code themselves (and you end up with multiple mods containing redundant code). So keeping functionally different mods separate from one another is an advantage, not a disadvantage.

 

5 hours ago, zer0Kerbal said:

My (probably irrational) perception is that doing so has helped performance.

If you're using the current release versions of CTB/TBC/toolbar, then it's probably just your imagination.

If you did downloaded the beta version of CTB/TBC/toolbar that linuxgurugamer made available for testing, then yes, they have some improvements gained from using unBlur, although I'm not sure how noticeable it would be.

Share this post


Link to post
Share on other sites

unBlur v0.5.0 for KSP 1.7.x
Should be backward compatible to at least 1.3.x if not older.

v0.5.0 ~ 2019-06-01 ~ KSP 1.7.x - 1.3.x
Added input validation
Suppress repetitive logging for GetTexture() calls

Share this post


Link to post
Share on other sites

Just an FYI, I just released the Blizzy toolbar with the unBlur code and dependency

Share this post


Link to post
Share on other sites
Posted (edited)

Hello to both of you!

I am here to, unfortunately, report a "problem" with the combination of Blizzy toolbar and Unblur... As an image is worth a thousand words, I invite you to take a look at this one:

http://www.mediafire.com/file/e5pm6hfajsw6plh/Icon_Comparaison.png/file

The image is at the actual display size of the in-game toolbar icon at 24x24. On the left, you see the rendering in-game with the previous version of Blizzy Toolbar (the one without Unblur), in the middle, you see the original texture source and on the right, you see the rendering in-game with the latest version of Blizzy Toolbar + Unblur.

The three images are taken from lossless source: Direct to memory screenshots and PNG files.

Take a close look and you will see that Unblur is doing something fishy with lossless PNG image. In fact, the result is the same as if the PNG was converter to DDS with DXT5 lossy compression enabled. So I am assuming this is what Unblur actually does for PNG texture: It convert them to DDS before loading them up. Hardly an improvement, UI wise, as far as clarity is concerned.

Suppressing the Unblur DLL cause Blizzy Toolbar to fall back to "KSP style app" buttons using slightly larger resolution images, effectively disabling itself. It would be great if, for more advanced users, we could at least decide to use it or not. I am going to revert back to the previous version for now but I am just letting you know.

Thanks.

Edited by Galenmacil
Edited for clarity

Share this post


Link to post
Share on other sites
Posted (edited)

@Galenmacil To investigate further I require the following information

- I cannot identify the mod from the icon. Please specify what mod this icon is from is so that I can investigate and reproduce.
- Also specify what your texture settings are set to (alternateively you can provide a screencap of your graphics settings screen)
- Please specify the KSP version and OS used.
- It would be tremendously helpful if you could turn on verbose debugging (see "For Modders" section of OP) and provide a full KSP.log file

 

8 hours ago, Galenmacil said:

I am assuming this is what Unblur actually does for PNG texture: It convert them to DDS 

Please don't make assumptions if you don't actually understand what it does.

 

 

Edited by cakepie

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.