DarkStarSword example fixes

From Bo3b's School for Shaderhackers
Jump to: navigation, search

Whether you need to apply a fix in a vertex shader or a pixel shader depends on the effect you are trying to fix (and some can be fixed in either, and some need adjustments in both).

Halos are often (but not always) possible to fix in either, but are almost always easier to fix in the vertex shader (the biggest exception where a halo fix has had to go in the pixel shader has been water, but only in a few games). Shadows almost always need a fix in the pixel shader.

When we talk about patterns we're usually talking about fixing an effect in an engine that someone has already worked out how to fix. Generally games using the same engine will have effects broken in the same way, so studying how we have fixed another game using the same engine will show you the patterns to fix that engine.

You can look at any of the fixes on the blog, or go through the history of my 3d-fixes repository to find these patterns - if you find the first time I fixed a given effect in the history I'll have included some extra notes in the commit message and usually have added the original shader in a separate commit so that the diff will show what I actually changed:

https://github.com/DarkStarSword/3d-fixes/commits/master

I also have a database of all DX9 shaders running on one of my servers - you can use the lookup_shader.py script in my 3d-fixes repository to look up any shader's CRC to see if it has been used in any fixes (DX9 games only for now) and show the difference between your local copy and any fixed versions.


Asside from halos (which are an almost universal problem with an almost equally universal solution), here's a few other examples of patterns (some easy, some difficult, some insane):


Move skybox to infinity (pattern applies to most, but not all games): https://github.com/DarkStarSword/3d-fixes/commit/7622a2940530d3a14b4bb1b556cdbbbfb0e3dec6


Shadows in Unreal Engine 3 (fairly simple): https://github.com/DarkStarSword/3d-fixes/commit/3cbebd0e4b5af11729fa9db6959acc71623ee3b7

However you will notice that any of my more recent DX9 UE3 fixes use a script (shadertool.py) that knows how to recognise the pattern and apply the fix automatically, including dealing with slight variations in registers/components selected by the compiler: https://github.com/DarkStarSword/3d-fixes/commit/82181b842fe6cf3e0d087a58d6a7309b0b5a134d


God rays in Unreal Engine 3 (simple): https://github.com/DarkStarSword/3d-fixes/commit/ad6535c0534b68638dd2411a2ad770ccec3ba9f6

God rays in CryEngine 3 (simple): https://github.com/DarkStarSword/3d-fixes/commit/76af7b96a19723172520f61cd778a79fedf970cc

God rays in Euro Truck Simulator 2 (moderate - no headers): https://github.com/DarkStarSword/3d-fixes/commit/67b31c856c08a4d563eebd0901cd91b67ff6de1a

God rays in Unity 4 (simple once headers were extracted): https://github.com/DarkStarSword/3d-fixes/commit/54831b2f00a9912daa514ac6df384376eecc1f97

God rays + underwater crepuscular rays in Stranded Deep (also Unity, but more complex than the above): https://github.com/DarkStarSword/3d-fixes/commit/83d50b1eac65ebbb938a697ae4ef2e2882c2cfcb

God rays in Witcher 3 (moderate - no headers): https://github.com/bo3b/3DMigoto/commit/dde106498b06455133af025afe21a9147efaae18

You might notice that the god ray pattern is similar for all the above engines... but things can get quite a bit more complicated:

NVIDIA "Enhanced" god rays in Far Cry 4 (relatively simple for an approximation): https://github.com/bo3b/3DMigoto/commit/c713fad554177eca9d90c3f2840e0c05f326caa1

Regular god rays in Far Cry 4 (very difficult): https://github.com/bo3b/3DMigoto/commit/007e1a26eb68f12dbc5e7c1f3ad3b887160361bb

God rays in Miasmata (insanely difficult): https://github.com/DarkStarSword/3d-fixes/commit/8c8f51d2e0b8e583b09c3fe12d64ebbf1c9fa7e5 https://github.com/DarkStarSword/3d-fixes/commit/d4a11aeae8bd69e04fa489f5acad80565e765f37



Alternate Unity 4 shadow fix for games where the usual technique in my template doesn't work: https://github.com/DarkStarSword/3d-fixes/commit/da1483c728398e9c355dfad42cb550e9434557bb

CryEngine 3 point lights/shadows: https://github.com/DarkStarSword/3d-fixes/commit/d26e85d9461af07875021cef97e6627f326f5e0b

CryEngine 3 directional lights/shadows: https://github.com/DarkStarSword/3d-fixes/commit/06805484e6b65d6c52380f9271346f36ae232a27

CryEngine 3 decales: https://github.com/DarkStarSword/3d-fixes/commit/8af18a481baffcf616bb0ea62f42135c51fd6cc4

Multipass fog in Unreal Engine 3 (needs adjustments to *four* shaders to fix accurately): https://github.com/DarkStarSword/3d-fixes/commit/d4d9f63f8fd30c1b4e7e44cda743e6d2483b0cb6

HBAO+ in Far Cry 4: https://forums.geforce.com/default/topic/897529/3d-vision/3d-hbao-normal-map-artefact-fix/

Far Cry 4 underwater caustics: https://github.com/bo3b/3DMigoto/commit/87e48ff8ff3831511c99ecbab17e8286873dda91


I could go on, but I think you get the idea.

Moving to infinity

https://forums.geforce.com/default/topic/882500/3d-vision/elite-dangerous-fix/post/4688379/#4688379