Difference between revisions of "Lesson 2 - disable effect"
Bo3b admin (Talk | contribs) (Created page with "==== Summary ==== This lesson demonstrates how to make our very first fix, by disabling any specific effect in a game. Level of difficulty: Easy<br> Time required: 15 minute...") |
Bo3b admin (Talk | contribs) (→Quiz) |
||
(19 intermediate revisions by one user not shown) | |||
Line 3: | Line 3: | ||
Level of difficulty: Easy<br> | Level of difficulty: Easy<br> | ||
− | Time required: | + | Time required: 25 minutes |
<br> | <br> | ||
<br> | <br> | ||
− | [http://youtu.be/ | + | [http://youtu.be/yznX9IBip9o <u>Video Walkthrough on YouTube</u>]<br> |
− | [http://sg.bo3b.net/Lesson% | + | [http://sg.bo3b.net/Lesson%202%20-%20disable%20effect.mp4 <u>Video Walkthrough direct download link</u>] |
<br> | <br> | ||
<br> | <br> | ||
+ | |||
==== Objective ==== | ==== Objective ==== | ||
Using the HelixMod debugger we'll find a specific broken shader that makes the game unplayable. <br> | Using the HelixMod debugger we'll find a specific broken shader that makes the game unplayable. <br> | ||
Line 20: | Line 21: | ||
---- | ---- | ||
+ | Since our HelixMod+TheBall environment is already set up and ready to use, let's dive in and fix our very first, game breaking, 3D bug. | ||
− | + | You probably noted when running the game before, that the bloom effect on the ball light is seriously broken, and is so annoying that it makes the game unplayable. It also changes depth when you adjust separation or convergence, so it's not really possible to find a sweet spot that is playable. | |
− | + | ||
− | + | ||
− | + | ||
− | : | + | Since bloom is a low-value and abused effect, let's disable it altogether. We won't miss it. |
+ | |||
+ | |||
+ | We are going to disable it using the Pixel Shader associated with that effect. For disabling effects, it is generally better to target Pixel Shaders, because the associated Vertex Shader can often be used for multiple Pixel Shaders, and thus can remove other effects that we want to keep. | ||
+ | |||
+ | |||
+ | Let's start by hunting down the exact shader file for that effect. | ||
+ | |||
+ | |||
+ | * Shader hunting a specific effect | ||
+ | *# Run The Ball, in 3D with HelixMod installed. | ||
+ | *# Step backwards one shader with '''Numpad 1''' and '''Numpad 4''' to see that we have the short list of shaders to search. | ||
+ | *# Step forward in the Pixel Shaders using '''Numpad 2''', and cycle all the way through at least once. | ||
+ | *# With some idea of what all happens, step through and find the specific bloom effect. Note that unlike the usual case, this one doesn't disappear altogether. | ||
+ | *# With that effect selected and disabled, use '''Numpad 3''' to save it into the ''Dumps'' folder. | ||
+ | *# Quit the game. | ||
+ | |||
+ | <br> | ||
+ | |||
+ | ---- | ||
+ | With our target shader saved, we need to move it into a new folder, the ShaderOverride folder so that HelixMod will use our fix at game launch. | ||
+ | |||
+ | Be extra careful when naming files and folders, as HelixMod is not consistent on naming. Any misnamed items leads to silent failures that can be hard to figure out. | ||
+ | |||
+ | |||
+ | * Finding the shader, then moving it into ''ShaderOverride'' | ||
+ | *# 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. | ||
+ | |||
+ | 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.[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. | ||
+ | |||
+ | 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 | ||
+ | *# 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. | ||
+ | |||
+ | Ready for the Quiz, for you to demonstrate that you successfully disabled this effect? | ||
+ | |||
+ | |||
+ | * Save and upload before and after 3D snapshots | ||
+ | *# Edit the shader, and comment out our line of code that fixes the shader: '''//mov oC0.xyzw, c1.wwww''' | ||
+ | *# Relaunch the game, and note that the effect is back, and even more annoying than ever. | ||
+ | *# Snapshot that broken example with Alt-F1. | ||
+ | *# 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. | ||
+ | *# When you are satisfied, click Save Page. | ||
+ | |||
+ | <br> | ||
+ | |||
+ | ---- | ||
+ | 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 [[Talk:Lesson_2_-_disable_effect|Discussion]] tab, and start a new topic. | ||
+ | <br> | ||
+ | <br> |
Latest revision as of 17:25, 31 August 2014
Summary
This lesson demonstrates how to make our very first fix, by disabling any specific effect in a game.
Level of difficulty: Easy
Time required: 25 minutes
Video Walkthrough on YouTube
Video Walkthrough direct download link
Objective
Using the HelixMod debugger we'll find a specific broken shader that makes the game unplayable.
We'll patch that shader using the text editor to disable the effect.
Quiz
Save and upload two screen shots. From the same view angle, show the before image, then show the fixed image.
Since our HelixMod+TheBall environment is already set up and ready to use, let's dive in and fix our very first, game breaking, 3D bug.
You probably noted when running the game before, that the bloom effect on the ball light is seriously broken, and is so annoying that it makes the game unplayable. It also changes depth when you adjust separation or convergence, so it's not really possible to find a sweet spot that is playable.
Since bloom is a low-value and abused effect, let's disable it altogether. We won't miss it.
We are going to disable it using the Pixel Shader associated with that effect. For disabling effects, it is generally better to target Pixel Shaders, because the associated Vertex Shader can often be used for multiple Pixel Shaders, and thus can remove other effects that we want to keep.
Let's start by hunting down the exact shader file for that effect.
- Shader hunting a specific effect
- Run The Ball, in 3D with HelixMod installed.
- Step backwards one shader with Numpad 1 and Numpad 4 to see that we have the short list of shaders to search.
- Step forward in the Pixel Shaders using Numpad 2, and cycle all the way through at least once.
- With some idea of what all happens, step through and find the specific bloom effect. Note that unlike the usual case, this one doesn't disappear altogether.
- With that effect selected and disabled, use Numpad 3 to save it into the Dumps folder.
- Quit the game.
With our target shader saved, we need to move it into a new folder, the ShaderOverride folder so that HelixMod will use our fix at game launch.
Be extra careful when naming files and folders, as HelixMod is not consistent on naming. Any misnamed items leads to silent failures that can be hard to figure out.
- Finding the shader, then moving it into ShaderOverride
- 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.
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
- 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 [3]
- 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
- 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.
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
- Edit the shader, and comment out our line of code that fixes the shader: //mov oC0.xyzw, c1.wwww
- Relaunch the game, and note that the effect is back, and even more annoying than ever.
- Snapshot that broken example with Alt-F1.
- 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:before filename|700px]]
- Copy the text for your After image filename from the ListFiles page.
- Add After: and your after filename reference as: [[File:after filename|700px]]
- Check your page with Preview to be sure you like it.
- 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.