SleepKiller's SWBFII Shader Patch - WIP

Started by SleepKiller, December 27, 2017, 04:38:41 AM

Previous topic - Next topic
December 27, 2017, 04:38:41 AM Last Edit: December 29, 2017, 03:41:14 PM by SleepKiller
So I've been making thing for SWBFII. This time it is using the shader toolkit I previously and a bit of cheeky DLL hijacking (like ENB or ENB esque mods) to hook into the Direct3D 9 run time. By injecting some metadata into the compiled shaders using a modified version of the compiler I made for the toolkit I can identify and make sense of the game's rendering pipeline in code. All without ever touching the game's executable or any of the ones it shipped with. (Which means as best I can tell this is not in violation of the EULA.)

So what does it do? Well currently it does some basic things that may seem dull but still provide notable improvements to visual fidelity without (hopefully) affecting the game's or any mods art style/direction. 

Borderless Fullscreen Windowed Operation   
Per-Pixel Lighting for Most Things
Per-Pixel Fog for Most Things
Derpy Proof-of-Concept Soft Shadows

Let's go through what some of those do and look like. Ideally I would just have side by side before and after pictures but there is only so much time in a day.

If you go here you can see the soft shadows. The idea here is quite simple, soft shadows usually look nicer than hard edged stencil shadows. (Hard edged stencil shadows could of course be used to great artistic effect in a game's art style and that is a very interesting topic for another time.) In this case I am simply blurring the shadow map before it's sampled this is in no way physically correct and does cause artifacting in certain places. But more importantly than those in most cases in looks nice. Eventually I would like to see about using different techniques like depth aware blurring to boost the quality and remove some of the artifacting. (And maybe even though in some form of Ambient Occlusion as well.)

Next here we have a poor example of the per-pixel lighting. You can see how the lighting more accurately and smoothly interacts with the storm troopers armour by fading at more correct angles. A better example would be on meshes that have low-tessellation (triangle count) over a large area. In those circumstances you can clearly see individual point lights interact correctly with the surface by fading out correctly and smoothly. Shoot a bunch of lasers down a hallway or a sniper bolt at a flat wall to see this effect.

Finally for now here you can see the per-pixel fog. Now I'll level with you, this was implemented primarily out of need. I had to ditch Shader Model 2 in order to get per-pixel lighting globally enabled. This killed the fixed function fog the game used which meant I had to re-implement it in shaders myself.

While doing this I made a couple improvements because A. Why not? and B. It is was easier to. The fog is now range based which means that objects will fade based of their world position not their perspective position, which creates less visual anomalies and is also closer to how fog works. The second is that fog is calculated per-pixel which is more expensive but gives a much nicer result as individual pixels have their fog coverage determined individually based of their distance. You can see this in action in the screenshot.

Some features I would like to look at adding are...

Soft Particles (maybe hard to integrate well into the game, but it would be really nice if they could be)
Improved Water and (maybe) Ocean Effects
Improved Refraction and Blur Quality
Improved HDR Rendering (currently normal maps can have their detail washed out before they're blended with their diffuse maps, some form of improved HDR rendering could fix this)
Order Independent Transparency (fixes things like command posts appearing behind glass)
(maybe) Depth-of-Field
(maybe) Other things I'm forgetting right now...

Be sure to give me your thoughts and say if you're interested in this! Or even better test it out, you'll obviously need an adequately capable GPU to run it. (If you have a DirectX 10/11 Feature Level GPU you are probably fine to give this a go.)

To install the current (early, likely unstable, don't be surprised if it crashes on you) version of it download and extract the contents of the folder below to your GameData folder. You should see dinput8.dll in the same directory as battlefrontII.exe.

Current Version (Backup your core.lvl before installing!)

The source code is of course coming soon. (That is as soon as I clean up the projects structure and write a readme.)

As a heads up, I can imagine some anti-viruses flagging this because of how it works (DLL Hijacking). It isn't, or at least it shouldn't be (if someone hijacked the web page they could trick you into downloading a version that was a virus, although that probably won't happen (but it could (although it probably won't, but still, it could))). Anyway the point is it is (probably) no more likely to be a virus than anything else you download from this site. But since it is a DLL if you're not comfortable installing that beside your game then that is highly understandable and I don't blame you for potentially giving it a pass.

Maybe just maybe someone...in the future...relef shder for models or atleast terrain texture? :D

Quote from: Ginev on December 27, 2017, 01:00:01 PM
Maybe just maybe someone...in the future...relef shder for models or atleast terrain texture? :D
Relief mapping requires a depth map as well as a normal map to work. And since any change I make to the normal mapping shader will affect everything in the game it would lead to everything that didn't also have a depth map attached looking not quite as good as regular normal mapping.

However that said there are some ways to potentially hack in custom material types so I will keep adding relief mapping in mind!

Cool!   :moo:
I made some testing and figired out that your specular light is not readimg how much power must be used om my models.For example while i was using the original shaders i figured out that if i use render type 27 with specular checked,specular color to 177 and specular decay on 60 my models look very good ingame.Its like a better bumpmap.However when i use your shaders everything is super shiny which mean that your shaders cannot read how powerfull is the specular effect.If you want i can give yoi an early prealpha versiom of my First Assault Tatooine map so that you can test your shaders there.

@Ginev: Just to confirm that the shininess isn't the result of the new shaders, are you using proper specular map textures? (i.e. grayscale textures that go in the alpha layer of both your diffuse and bump/normal map .tga files similar to what most stock weapons have)

No i do not use.Some of my BumpMaps (which are basically normalmaps) have alpha channel texture but not the diffuse one.So if i put grayscales on my diffuse and normalmaps this shinny problem will be fixed?

Yep, definitely. And remember, the lighter parts of the alpha layer will appear shinier than darker parts in-game. Having no alpha is the same thing as having a completely white alpha layer meaning everything would appear equally shiny, which is what you were experiencing.