Lesson 4 - game fix

From Bo3b's School for Shaderhackers
Revision as of 00:25, 30 August 2014 by Bo3b admin (Talk | contribs)

Jump to: navigation, search

Summary

This lesson will show one way to go about fixing the entire game, getting it playable as quickly as possible.


Level of difficulty: Easy
Time required: 25 minutes

Video Walkthrough on YouTube
Video Walkthrough direct download link

Objective

Fix the entire game, all shaders that cause 3D glitches, making it playable.
Learn how HelixMod constants work.

Discuss tradeoffs on gone vs. fix. Fix full game. All shaders gone. Fix lava by killing one layer instead, show experiments.

maybe: relaunch for fewer 'live' shaders. maybe: profile switch for fixes. maybe: nvidia cfg param for stereo.


Quiz

Save and upload two screen shots. This time, using the on/off key mechanism to show any scene with glitches, then all of them fixed.


Even with the tiny information that we have so far, we can still fix entire games!

Let's go through The Ball and fix every broken effect that we find. After we finish disabling all the broken effects, we will have a fully playable game in 3D.

There is a trade-off between fixing effects and simply disabling them. Naturally, we'd want to fix things instead of just disable them, but fixing things is quite a lot harder and more time-consuming than simply disabling them.

There is an artistic balance to be struck between how much an effect is worth, compared to how bad it looks in 3D. This is simply a judgment call, and everyone will have a different opinion. In general, we try to lean toward fixing everything, but if you only have a little bit of time, it's far better to have a game that runs with effects disabled, than no game at all.


As a first pass, let's find and mark all the broken shaders. We'll still look for them one at a time, so we can easily keep track of what we need to do.

We can't reload the shaders live, so it's reasonable to mark them all first.

  • Creating a complete list of shaders
    1. Turn effects off with UI. Fewer to fix.
    2. First pass in game, finding broken shaders.
    3. Mark every shader that needs fixing.




  • Create an on/off mechanism using HelixMod constants
    1. Remove dumpall for speed.
    2. Show constant use in shaders.
    3. Demo constant for on/off display use.


    1. Navigate to The Ball's game directory with our shortcut.
    2. Continue into ..\Dumps\SingleShaders\PixelShader\
    3. Find your target Pixel Shader, usually the most recent item.
    4. Select and Copy the shader text file.
    5. Navigate back to the ..\The Ball\Binaries\Win32\ game directory.
    6. Create a new folder there, named ShaderOverride
    7. Open that folder, and create a new folder there named PixelShaders
    8. Open that folder, and Paste your copied Pixel Shader.
    9. Edit the file name, so that HelixMod can load it. Remove everything except the CRC number at the end.
    10. Make sure the CRC is 8 hex digits long, some need a leading zero.



Now we are ready to actually make the change to the ASM text.

We'll also add some comments to the code as reminders for when we come back to the code, or help other people who might use our fixes. Adding comments nearly always save you time in the long run.


There are multiple ways to disable an effect, and you might notice that the technique described below does not match the Guide on HelixMod. The reason to change this is to show the simplest possible way to disable an effect.

In a later Lesson, we'll come back to disabling an effect, and we'll present a more complicated, but better way to do this.[1]


A pixel shader is responsible for deciding what color a particular output screen pixel is supposed to be. So the idea behind this fix, is that we want to make the output color via oC0.xyzw register all zeroes.[2]

This is the most common approach, but keep in mind that in some scenarios this won't work and other techniques are required.


With that in mind, let's edit the source file.


  • Editing shader to disable effect
    1. Open the shader file with the fixed name in ..\ShaderOverride\PixelShaders\
    2. ASM comments start with //. Put in a description comment at the first line, like // Annoying bloom on ball light
    3. In your text editor, look for the constants, for example, def c1, 0.5, 1, -0.5, 0. We'll need any zero constant.
    4. Scroll through the shader until you get to the bottom.
    5. Find the second to last line, right before the comment that says "// approximately ...".
    6. The convention we use is to outdent any changes we make, so they stand out from the regular code. No spaces, no tab.
    7. Add a comment to describe why you put in this code, like // Disable game-breaking bloom effect
    8. On the next line, type in the instruction mov oC0.xyzw, c1.wwww [3]
    9. That's it. The instruction will move that zero from c1 into oC0, making every pixel invisible.



Now that we have the shader modified the way we think it should work, we need to test it out.

While we are here, we will also look at another feature of HelixMod, which allows you to modify the ASM source code, then reload it without having to relaunch. This is extremely useful for experimenting on the code.


Let's run the game and see if it worked.


  • Load shader to see changes
    1. Run The Ball.
    2. The bloom effect should be completely gone. Amazing!
    3. To experiment with it, alt-tab out, and edit the shader.
    4. Scroll to the bottom, and change mov oC0.xyzw, c1.wwww to mov oC0.xyzw, c1.yyyy
    5. Alt-tab back into the game, and press the F10 key to reload our shader.
    6. You should see two large white rectangles, as we fill the oC0 with all ones, which is full white.
    7. Try another combination, as mov oC0.xyzw, c1.ywyy
    8. You should get bright purple squares, as we make red=1, green=0, blue=1, alpha=1.
    9. Do the same thing, but put it back to fixed with mov oC0.xyzw, c1.wwww
    10. Go ahead and quit the game.



That's it! That's all there is to disabling an effect in a game, and even in this simple example, you can see how much difference it makes to disable some effect that is heinous in 3D.

Ready for the Quiz, for you to demonstrate that you successfully disabled this effect?


  • Save and upload before and after 3D snapshots
    1. Edit the shader, and comment out our line of code that fixes the shader: //mov oC0.xyzw, c1.wwww
    2. Relaunch the game, and note that the effect is back, and even more annoying than ever.
    3. Snapshot that broken example with Alt-F1.
    4. Alt-tab out, and edit the shader.
    5. Remove the comment characters of // and save the file.
    6. Alt-tab back in, and hit F10 to reload our fixed shader.
    7. Snapshot that disabled and fixed effect with Alt-F1.
    8. Upload your two snapshots, using the Special:Upload link.
    9. Open the all files page in a 2nd tab, so we can get the filenames easily, at: Special:ListFiles
    10. Navigate to your personal wiki page from the upper right.
    11. Edit your personal page, and add == Lesson 2 == and any comments you'd like.
    12. Copy the text for your Before image filename from the ListFiles page.
    13. Add Before: and your before filename reference as: [[File:before filename|700px]]
    14. Copy the text for your After image filename from the ListFiles page.
    15. Add After: and your after filename reference as: [[File:after filename|700px]]
    16. Check your page with Preview to be sure you like it.
    17. When you are satisfied, click Save Page.



Did you successfully disable that annoying effect? Bravo! You can now justifiably call yourself a Shaderhacker!

Disabling effects can salvage a game from being completely unplayable, so don't discount the power of this simple technique.


If you have any questions or suggestions, please use the Discussion tab, and start a new topic.