Difference between revisions of "Lesson 4 - game fix"

From Bo3b's School for Shaderhackers
Jump to: navigation, search
 
(18 intermediate revisions by one user not shown)
Line 4: Line 4:
  
 
Level of difficulty: Easy<br>
 
Level of difficulty: Easy<br>
Time required: 25 minutes
+
Time required: 45 minutes
 
<br>
 
<br>
 
<br>
 
<br>
[http://youtu.be/yznX9IBip9o <u>Video Walkthrough on YouTube</u>]<br>
+
[http://youtu.be/5Gv4thsWdjU <u>Video Walkthrough on YouTube</u>]<br>
[http://sg.bo3b.net/Lesson%202%20-%20disable%20effect.mp4 <u>Video Walkthrough direct download link</u>]
+
[http://sg.bo3b.net/Lesson%204%20-%20game%20fix.mp4 <u>Video Walkthrough direct download link</u>]
<br>
+
 
<br>
 
<br>
  
 
==== Objective ====
 
==== Objective ====
Fix the entire game, all shaders that cause 3D glitches, making it playable.
+
Fix the ''entire game'', all shaders that cause 3D glitches, making it playable.
<br>
+
Learn how HelixMod constants work.
+
 
<br>
 
<br>
 +
Give each effect a constant, so each can be disabled or enabled.
  
Discuss tradeoffs on gone vs. fix.
+
==== Quiz====
Fix full game. All shaders gone.
+
Make a second key preset to toggle bloom independently from other effects.
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.
 
<br>
 
<br>
 
  
 
----
 
----
Line 37: Line 25:
 
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.
 
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 3DThis 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.
+
There is a trade-off between fixing effects and simply disabling themNaturally, we'd want to fix things instead of just disabling 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 3DThis 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 shadersWe'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.  
+
As we go through this Lesson, we'll get a chance to see how that balance plays out with different effects.  
  
* Creating a complete list of shaders
 
*# Turn effects off with UI. Fewer to fix.
 
*# First pass in game, finding broken shaders.
 
*# Mark every shader that needs fixing.
 
  
<br>
+
For this Lesson we are going to concentrate upon getting results quickly, not necessarily the best results.  This technique also makes it easier to decide which effects to fix, and gives us a great working list of effects to be fixed when we have time.
  
----
+
Part of these Lessons is to present techniques that can lead to good working habits when fixing these games.  It's very easy to try to go too fast and get lots of files open and get confused on what file affects which effect, especially if your experiments don't work.  There are lots of different approaches to fixing effects, this will emphasize techniques that can save you time.
  
 
* Create an on/off mechanism using HelixMod constants
 
*# Remove dumpall for speed.
 
*# Show constant use in shaders.
 
*# Demo constant for on/off display use.
 
 
 
*# Navigate to The Ball's game directory with our shortcut.
 
*# Continue into ''..\Dumps\SingleShaders\PixelShader\''
 
*# Find your target Pixel Shader, usually the most recent item.
 
*# Select and Copy the shader text file.
 
*# Navigate back to the ''..\The Ball\Binaries\Win32\'' game directory.
 
*# Create a new folder there, named '''ShaderOverride'''
 
*# Open that folder, and create a new folder there named '''PixelShaders'''
 
*# Open that folder, and Paste your copied Pixel Shader.
 
*# Edit the file name, so that HelixMod can load it. Remove everything except the CRC number at the end.
 
*# Make sure the CRC is 8 hex digits long, some need a leading zero.
 
 
<br>
 
  
 
----
 
----
Now we are ready to actually make the change to the ASM text.
+
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 and to avoid getting confused.  
  
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 fixesAdding comments nearly always save you time in the long run.
+
In a later Lesson, we'll come back to these disabled shaders in order to actually fix themHaving them all in the same spot, with good comments will make it easy for us to find effects, and decide which are worth more time to actually fix.  In a very real sense, this is a working ToDo list, but without us having to write a bunch of notes.
  
  
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.
+
* Creating a complete list of shaders.
 +
*# Since we want quick results, we can turn effects off with configuration UI instead of fixing or disabling them.
 +
*# First pass in game, finding broken shaders.
 +
*# Find and mark each broken shader.
 +
*# Alt-Tab out, and comment each new file for context.
 +
*# Relaunch at different saves to shorten active search list.
  
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.[http://wiki.bo3b.net/index.php?title=Talk:Lesson_2_-_disable_effect#Optimal_way_to_disable_an_effect]
 
 
 
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.[http://msdn.microsoft.com/en-us/library/windows/desktop/bb219871(v=vs.85).aspx] 
 
 
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
 
*# Open the shader file with the fixed name in ''..\ShaderOverride\PixelShaders\''
 
*# ASM comments start with //. Put in a description comment at the first line, like '''// Annoying bloom on ball light'''
 
*# In your text editor, look for the constants, for example, ''def c1, 0.5, 1, -0.5, 0''. We'll need any zero constant.
 
*# Scroll through the shader until you get to the bottom.
 
*# Find the second to last line, right before the comment that says "// approximately ...".
 
*# The convention we use is to ''outdent'' any changes we make, so they stand out from the regular code. No spaces, no tab.
 
*# Add a comment to describe ''why'' you put in this code, like '''// Disable game-breaking bloom effect'''
 
*# On the next line, type in the instruction '''mov oC0.xyzw, c1.wwww''' [http://msdn.microsoft.com/en-us/library/windows/desktop/bb219869(v=vs.85).aspx]
 
*# That's it.  The instruction will move that zero from c1 into oC0, making every pixel invisible.
 
 
<br>
 
  
 
----
 
----
Now that we have the shader modified the way we think it should work, we need to test it out.  
+
With all the broken shaders saved in the ''..\Dumps\SingleShaders\'' folder, we can now go through and disable each of them.  We'll use our on/off mechanism so that we can decide how much of an impact disabling each effect has.
  
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.
 
  
 +
* Editing shaders to disable effects
 +
*# Fix full game. All broken shaders disabled by default.
 +
*# Toggle key code to enable them on.
 +
*# With all shaders edited, run game and make sure they're fixed.
  
Let's run the game and see if it worked.
 
 
 
* Load shader to see changes
 
*# Run The Ball.
 
*# The bloom effect should be completely gone. Amazing!
 
*# To experiment with it, alt-tab out, and edit the shader.
 
*# Scroll to the bottom, and change ''mov oC0.xyzw, c1.wwww'' to '''mov oC0.xyzw, c1.yyyy'''
 
*# Alt-tab back into the game, and press the F10 key to reload our shader.
 
*# You should see two large white rectangles, as we fill the oC0 with all ones, which is full white.
 
*# Try another combination, as '''mov oC0.xyzw, c1.ywyy'''
 
*# You should get bright purple squares, as we make red=1, green=0, blue=1, alpha=1.
 
*# Do the same thing, but put it back to fixed with '''mov oC0.xyzw, c1.wwww'''
 
*# Go ahead and quit the game.
 
 
<br>
 
  
 
----
 
----
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.
+
That's all there is to disabling effects in a game, and hopefully you see how quickly and easily you can fix an entire game.  It can be improved, but isn't it already far better than when we started?
  
Ready for the Quiz, for you to demonstrate that you successfully disabled this effect?
+
Time for the Quiz.  Can you add a second key preset, so that we can toggle that heinous bloom effect independent from the more mild fog effects?
  
  
* Save and upload before and after 3D snapshots
+
* Save and show your DX9Settings.ini file.
*# Edit the shader, and comment out our line of code that fixes the shader:  '''//mov oC0.xyzw, c1.wwww'''
+
*# Edit the DX9Settings.ini file, and add second key preset using any key you prefer.
*# Relaunch the game, and note that the effect is back, and even more annoying than ever.
+
*# Change the constants to allow the bloom or other terrible effects to be toggled without affecting others.
*# Snapshot that broken example with Alt-F1.
+
*# Once you are satisfied with your changes, edit your personal page and add your DX9Settings.ini code to your page, in a <nowiki><nowiki></nowiki></nowiki> block.
*# Alt-tab out, and edit the shader.
+
*# Remove the comment characters of // and save the file.
+
*# Alt-tab back in, and hit F10 to reload our fixed shader.
+
*# Snapshot that disabled and fixed effect with Alt-F1.
+
*# Upload your two snapshots, using the [[Special:Upload]] link.
+
*# Open the all files page in a 2nd tab, so we can get the filenames easily, at: [[Special:ListFiles]]
+
*# Navigate to your personal wiki page from the upper right.
+
*# Edit your personal page, and add '''== Lesson 2 ==''' and any comments you'd like.
+
*# Copy the text for your Before image filename from the ListFiles page.
+
*# Add '''Before:''' and your before filename reference as: '''[[File:'''<nowiki></nowiki>''before filename''<nowiki></nowiki>'''|700px]]'''
+
*# Copy the text for your After image filename from the ListFiles page.
+
*# Add '''After:''' and your after filename reference as: '''[[File:'''<nowiki></nowiki>''after filename''<nowiki></nowiki>'''|700px]]'''
+
 
*# Check your page with Preview to be sure you like it.
 
*# Check your page with Preview to be sure you like it.
 
*# When you are satisfied, click Save Page.
 
*# When you are satisfied, click Save Page.
  
<br>
 
  
 
----
 
----
Did you successfully disable that annoying effect?  Bravo!  You can now justifiably call yourself a Shaderhacker!
+
Did you successfully disable ''every'' annoying effect?  Did you just fix a complete game? Incredible!
 
+
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 [[Talk:Lesson_2_-_disable_effect|Discussion]] tab, and start a new topic.
+
If you have any questions or suggestions, please use the [[Talk:Lesson_3_-_game_fix|Discussion]] tab, and start a new topic.
 
<br>
 
<br>
 
<br>
 
<br>

Latest revision as of 07:31, 7 September 2014

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: 45 minutes

Video Walkthrough on YouTube
Video Walkthrough direct download link

Objective

Fix the entire game, all shaders that cause 3D glitches, making it playable.
Give each effect a constant, so each can be disabled or enabled.

Quiz

Make a second key preset to toggle bloom independently from other effects.



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 disabling 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 we go through this Lesson, we'll get a chance to see how that balance plays out with different effects.


For this Lesson we are going to concentrate upon getting results quickly, not necessarily the best results. This technique also makes it easier to decide which effects to fix, and gives us a great working list of effects to be fixed when we have time.

Part of these Lessons is to present techniques that can lead to good working habits when fixing these games. It's very easy to try to go too fast and get lots of files open and get confused on what file affects which effect, especially if your experiments don't work. There are lots of different approaches to fixing effects, this will emphasize techniques that can save you time.



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 and to avoid getting confused.

In a later Lesson, we'll come back to these disabled shaders in order to actually fix them. Having them all in the same spot, with good comments will make it easy for us to find effects, and decide which are worth more time to actually fix. In a very real sense, this is a working ToDo list, but without us having to write a bunch of notes.


  • Creating a complete list of shaders.
    1. Since we want quick results, we can turn effects off with configuration UI instead of fixing or disabling them.
    2. First pass in game, finding broken shaders.
    3. Find and mark each broken shader.
    4. Alt-Tab out, and comment each new file for context.
    5. Relaunch at different saves to shorten active search list.



With all the broken shaders saved in the ..\Dumps\SingleShaders\ folder, we can now go through and disable each of them. We'll use our on/off mechanism so that we can decide how much of an impact disabling each effect has.


  • Editing shaders to disable effects
    1. Fix full game. All broken shaders disabled by default.
    2. Toggle key code to enable them on.
    3. With all shaders edited, run game and make sure they're fixed.



That's all there is to disabling effects in a game, and hopefully you see how quickly and easily you can fix an entire game. It can be improved, but isn't it already far better than when we started?

Time for the Quiz. Can you add a second key preset, so that we can toggle that heinous bloom effect independent from the more mild fog effects?


  • Save and show your DX9Settings.ini file.
    1. Edit the DX9Settings.ini file, and add second key preset using any key you prefer.
    2. Change the constants to allow the bloom or other terrible effects to be toggled without affecting others.
    3. Once you are satisfied with your changes, edit your personal page and add your DX9Settings.ini code to your page, in a <nowiki></nowiki> block.
    4. Check your page with Preview to be sure you like it.
    5. When you are satisfied, click Save Page.



Did you successfully disable every annoying effect? Did you just fix a complete game? Incredible!


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