Skip to content

[MOD] Sharpening filter, BGEE1.3-like look and more via shaders

drunktieflingdrunktiefling Member Posts: 39
edited October 2023 in BGII:EE Mods
GitHub: https://github.com/dtiefling/dshaders. Project readme there is an actual mod readme too, with detailed illustrations, which I wholeheartedly recommend.

Download: https://github.com/dtiefling/dshaders/releases.

Inspired by @argent77's Shader Pack, I have started researching what else can be done with shaders, and discovered more potential.

With this mod, I present rewritten shaders that go much further with extra features and available settings. That includes:
  • Catmull-Rom interpolation (i.e. better scaling),
  • Changes to the outlines, including disabling them via shaders, for BGEE 1.3-like look,
  • Color operations in linear RGB space,
  • Changes to color parameters: brightness, contrast, gamma, hue, saturation,
  • Sharpening (or Gaussian blur),
  • Improved text readability,
  • Multitude of setup options,
  • Support for personal fine-tuning of parameters with notepad,
  • Automatic shader optimization via GLSL optimizer,
  • and honestly, more. Many of the ideas come from the community.

It should work on any PC platform (tested on Linux and Windows).

How does it look? Well, you can trace most of the options in the mod readme, but here is an idea:

BGEE 1.3 (top) vs mod preset that is intended to imitate the feel:
8kj3r40tr2mt.png
lh0ama8wztd0.png

Game without this mod (top) vs setup I use (includes Catmull-Rom, moderate color adjustment and sharpening):
7976crcugrox.png
ie0gxstp7vep.png
Post edited by drunktiefling on
«1

Comments

  • argent77argent77 Member Posts: 3,494
    That sounds like a great idea.

    Unfortunately the shaders don't seem to work correctly on my games. EET and SoD just show a black screen. BG2EE shows garbled graphics (greenish misaligned textures).
  • drunktieflingdrunktiefling Member Posts: 39
    Thanks for the reply! I guess I should try some setup that people actually use and do more testing. Perhaps it's because I use native Linux build, or overly new GLSL dialect? I will look into this. What you describe is typical for shaders that didn't compile, which I have seen multiple times before getting this to work for me. Well, that's the thing with code that was tested in one setup only.
  • Allanon81Allanon81 Member Posts: 349
    Catmull-Rom shader possible?
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    Allanon81 wrote: »
    Catmull-Rom shader possible?

    Perhaps. It just interpolates colors in this application, not shapes, right? If so, it would need finding the centers of surrounding 4x4 (or just 4x1 and 1x4) pixels and doing some arithmetic that is barely more difficult than convolution via kernel.

    I see that the previous BGEE releases made people love this exact method? When I get the technical stuff somewhat-together, I should give it a try.
  • drunktieflingdrunktiefling Member Posts: 39
    @Allanon81 I believe it should work! I've managed to reach the pixels I want with texelFetch, at least for the shaders that provide access to uTcScale! So the chances are good.

    Still, need to grab some Windows (not easy!) and figure out what's wrong with my shaders there. Or different GPU. Which is much, much worse stuff than algorithms themselves.
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    [deleted, not relevant anymore. it included pics of broken versions, now the right showcase of what to expect is in the main post]
    Post edited by drunktiefling on
  • Allanon81Allanon81 Member Posts: 349
    edited September 2023
    @drunktiefling I’ve also seen stuff about “Centripetal” Catmull-Rom. https://en.m.wikipedia.org/wiki/Centripetal_Catmull–Rom_spline
    Don’t know if one’s better or more sophisticated than another.
    Here’s some other docs, maybe you’ve seen or not:
    http://www.mvps.org/directx/articles/catmull/
    https://stackoverflow.com/questions/19752513/how-performing-fast-catmull-rom-texture-tiltering-by-linear-interpolations#19884005
  • drunktieflingdrunktiefling Member Posts: 39
    Thanks @Allanon81! I didn't use the exact sources, but I'm well aware that in general interpolation - I am free to choose nodes to probe.

    However, the textures are 2d bitmaps in this application. I don't get to decide where the pixel centers are, it's just a property of the input data. So anything but "Uniform" Catmull-Rom would be needlessly blurry. It's better to do this properly - and if someone actually wanted blur, add it to the output (which my code can already do - negative sharpening means Gaussian Blur with radius 1).
  • Allanon81Allanon81 Member Posts: 349
    @drunktiefling
    I would prefer non-blurry. No anti-aliasing. Super sharp. I like pixels.
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    Allanon81 wrote: »
    @drunktiefling
    I would prefer non-blurry. No anti-aliasing. Super sharp. I like pixels.

    Be careful what you ask for. I can implement nearest neighbor for the sole purpose of pre-scale sharpening (the sane thing my code does now is doing it post-scale). It would be sharper than what the game normally does with nn setting.

    But I believe we are looking for "smooth despite not losing information" (so "not blurry") as opposed to "impractically sharp".
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    Note: you can also disable C-R, set nn in game settings and play with gamma and post-scale sharpening right now. Or just find out if my code works for you.
  • Allanon81Allanon81 Member Posts: 349
    @drunktiefling Well yeah not crazy sharp, I guess a balance leaning towards sharp. Whatever makes it look better than this blurred out mess now. Particularly if it can maintain sharpness when zoomed in. I play exclusively on mobile (iOS). Nice to see someone trying to tackle this.
  • drunktieflingdrunktiefling Member Posts: 39
    @Allanon81 I'm now pretty certain that I've got it right, just look at the new screenshots in the main post. Would this + configurable sharpening in the end (you can just put a crazy number there or not) be enough?
  • ParysParys Member Posts: 205


    Mod setup: Catmull-Rom interpolation + disabled outlines. Attempt to be like BGEE 1.3. Interestingly, the output is less blurry - did the original method miss the pixel centers?
    nb81onk584sv.png

    Would you like to tell what parameters i have to change to achive this look? Or would you like to send me your configuration files? Your linux configuration files from drunkshaders-0alpha2 is flawless in my hardware configuration.
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    @Parys glad to hear that it works for you! Grab the current version from the main post, it includes readme. It should be obvious with the readme and comments in the glsl files themselves.

    Which would mean that you might want to (in all files):
    • enable Catmull-Rom,
    • set sharpening to 0.0,
    • set brightness and hue offsets to 0.0,
    • set gamma, contrast and saturation multipliers to 1.0,
    • wherever it's present (fpsprite/fpselect), set outline disable flag to true.

    Please recall that the legacy games had brightness and contrast sliders, so playing with it (and gamma) wouldn't break the tradition either.

    EDIT: I also read that as a feature request to make some presets to pick from in the installer. Also I guess I should get my arse together to put it on GitHub + readme on githubpages, so it's easier to review before downloading the archive.
  • ParysParys Member Posts: 205
    If i enable Catmull-Rom, graphical artifact appear. Do you know a way to fix this.
    no7hqfc3eqnr.png

    If i disable Catmull-Rom, i have unnatural pixelated, jagged background areas.
    30mmueqvfp5i.png

    Do you know a way to fix this issue? I would like to use Catmull-Rom interpolation.
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    @Parys interesting, that's the kind of input that helps a lot!

    I didn't get this exact set of errors, but I was reworking this shader regardless. Some of the original (as in: introduced with EE by Beamdog) code was... strange, full of assumptions. I'm rewriting it to keep roughly similar logic, but make the implementation way more consistent, also slightly faster. I will try to identify what could have produced such lines, to make sure it is fixed in the next update, which will be pushed soon.

    May I assume that you are getting this with the version from the post (0alpha4)?
    Post edited by drunktiefling on
  • ParysParys Member Posts: 205
    @Parys interesting, that's the kind of input that helps a lot!
    May I assume that you are getting this with the version from the post (0alpha4)?

    That's correct
    I play with active Scaling user interface (PC-win10, intel 10850, geforce 660 gtx)
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    @Parys great. The temporary recommendation is to disable C-R in fpseam.glsl only. Maps tiles are a mess to handle. Still, I believe that sprites are even more important, and they should work fine already.

    I should push something new in 1-2 days. For now, I identified an interesting set of malicious cases (when I fix some of them, the others start glitching). The Beamdog code is messy, as it forces the least appealing linear sRGB mixing possible (no matter of the game settings) using the shader code rather than sampler. So I really dislike it and I want to rewrite it. Also, the rewrite is necessary to get C-R for maps at all.
  • Allanon81Allanon81 Member Posts: 349
    I wonder how or if this could be implemented alongside the A.I. Denoised maps mod?
  • drunktieflingdrunktiefling Member Posts: 39
    New release just dropped! There WeiDU installer got somewhat advanced, with a menu!

    @Parys , I would be interested if it fixes your issue.

    @Allanon81 preferably, also in terms of performance. Of course AI scaling would be better than just denoising and then scaling, but... We would need to have a simple-enough pretrained model (perhaps as GLSL function? or with layers implemented as such?).

    Collecting data for training a model exactly for this need would be mostly impossible, since the 3D data on the models is known to be unavailable even to Beamdog. Unless you have funds to employ a crowd of artists to create a training set by hand.
  • GraionDilachGraionDilach Member Posts: 599
    edited September 2023
    The AI denoised areas mod basically replaces the area textures with AI-tweaked variants, so they should be compatible anyway. Its a static change.
  • ParysParys Member Posts: 205
    I would like to thank you for your work on this mod. The comfort of playing this game increases significantly. Looking at the beautiful pre-rendered backgrounds through catmull interpolation is a joy for the eyes. The sprites animation works flawlessly in my configuration as well.
    I am impressed that the previously pixelated animations of torches, mephit portals in irenicus dungeons level 2, and many many others, are now smoothed out, as in version 1.3. I played with catmullrom interpolation enabled in every glsl file.
    The backgrounds are no longe jagged. There is no graphical artifacts on the backgrounds.
    I've encountered a few minor glitch on animated objects, though:
    39vbjiir1yig.png
    qs62cxu0fh6f.png


    In BG1 i have no found any such distortions or graphic artifacts yet.

    My Pc specs: Win10, Intel i9-10850k, GTX660, Dispaly 1080x1200, Scale User interface option is turned on.

    Nevertheless, this mod is a must-have addition to the game for me. These small inconveniences are faded away in the advantages your mod provides.
    Your mod is no longer drunk. It becames more sober with each successive version :)
    Kind regards.
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    @Parys thanks for the kind words! I believe this improvement to be an experience that we deserve.

    I really like the choice of glitches you identified, as they seem mutually different (perhaps a tile with an object, then just a memory-broken tile, and finally - a non-rectangle edge rendered wrong! I hope I will manage to reproduce each case). Is that Aran's place, second floor of Harpers' place, and obvious front of Talos temple, did I get this right?
  • ParysParys Member Posts: 205
    Yes, you have correctly identified the locations!
  • drunktieflingdrunktiefling Member Posts: 39
    @Parys it was helpful indeed, your cases even have something in common. All of them seem to be related to the object tiles drawn on the map area as something "extra". And they use UI shader instead of the standard map shader, so... I have to use the tiles there too. Also, using different settings for UI and map might end up impossible due to this, oh well. Also that specific tiles seem to use fptone.glsl on pause - at least now I know some use for it.

    But getting maps with C-R and no glitches should be possible. I'm working on it, and that's thanks to your report!
  • drunktieflingdrunktiefling Member Posts: 39
    edited September 2023
    @Parys and here goes the new release, that should fix this batch of glitches.

    In general, it's a regression that we can't use different color settings for UI and maps, but that's how the engine works. At least now we are aware of that.

    I really, really liked my item stack count fonts to have lower gamma. Especially since I use Infinity UI++, which doesn't use the squarish bitmaps of the original releases. So one of the options is just a a dirty fix for that exact scenario.
  • ParysParys Member Posts: 205
    Black lines on the aran jacuzzi animation no longer appear. In addition, there is no black line on this contraption in the temple district!
    I noticed that the rendering of graphics has been improved. The selection circles and movement maker have become sharper. And rendering of sprites get better! I did not think it could be improved. Hats off to you.
    Only the small colored lines on the hearth animation at the harpists' headquarters remain.
    gic6dg17wcge.png
    fukuwzuw5niv.png
    If fixing this minor bug would cause deteriorate of the sprites, selection circles and background rendering, please don't fix it :)
    Have a nice day!
  • drunktieflingdrunktiefling Member Posts: 39
    @Parys that's interesting, as no recent changes should affect contents inside the sprites - it was my reference for the other shaders, as the way sprites work is very consistent (one bitmap, nothing special near borders, one source of alpha channel, and instant visual clue when anything is broken). Soooo, if the change is for the better, I'm not going to complain. Perhaps it is a placebo effect as there are simply less glitches in general?

    And the bottom border of object tiles is tricky, as I can't reproduce the effect from your screenshots. Sometimes I can observe some thin lines (way less than would be one pixel before scaling), but interestingly, they are there with a clean install as well. I will pray to Tymora and trace how is could be logically possible. I guess that if you removed fpdraw.glsl from your override directory, you would get pixelated objects, but no broken lines?
  • ParysParys Member Posts: 205
    @drunktiefling Yes, I would get pixelated objects, and no broken lines if i remove fpdraw.glsl
Sign In or Register to comment.