Difference between revisions of "Lesson 3 - Const"

From Bo3b's School for Shaderhackers
Jump to: navigation, search
(Created page with "==== Summary ==== This lesson will show how to create and use constants, from DX9Settings.ini all the way into the shader code itself. Level of difficulty: Easy<br> Time req...")
 
 
(4 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: 30 minutes
<br>
+
<br>
+
[http://youtu.be/O2pafLpepsk <u>Video Walkthrough on YouTube</u>]<br>
+
 
<br>
 
<br>
 
<br>
 
<br>
 +
[http://youtu.be/fMNp9JbGFjw <u>Video Walkthrough on YouTube</u>]<br>
  
 
==== Objective ====
 
==== Objective ====
Line 15: Line 13:
 
<br>
 
<br>
 
Learn how HelixMod constants work to make an on/off mechanism from the keyboard.
 
Learn how HelixMod constants work to make an on/off mechanism from the keyboard.
<br>
 
 
 
  
 
==== Quiz====
 
==== Quiz====
...
+
Make a version that uses a different key, changes the color when on, and is only active when held down.
 
<br>
 
<br>
 
<br>
 
<br>
  
 
----
 
----
Before we get started disabling effects, let's take a quick look at another HelixMod feature that we are going to use extensively in the future.  Our use here will be a simple version, but a good introduction.
+
For this Lesson, let's take a quick look at another HelixMod feature that we are going to use extensively in the future.  Our use here will be a simple version, but a good introduction.
  
 
In the HelixMod DX9Settings.ini file, we can add ''Constants'', and we can then use those constants in any Pixel or Vertex Shader.  They are provided by the tool as a convenience, and for any purpose that we wish.  The constants can be used to make it easy to change the HUD depth for example, or specify how transparent to make it.  
 
In the HelixMod DX9Settings.ini file, we can add ''Constants'', and we can then use those constants in any Pixel or Vertex Shader.  They are provided by the tool as a convenience, and for any purpose that we wish.  The constants can be used to make it easy to change the HUD depth for example, or specify how transparent to make it.  
  
 
These constants can also be chosen based on a given key or mouse press, so that we can change effects in the shader, like changing viewpoints on key press, or changing convergence to zero when the right mouse is down.
 
These constants can also be chosen based on a given key or mouse press, so that we can change effects in the shader, like changing viewpoints on key press, or changing convergence to zero when the right mouse is down.
 +
 +
Note that this version of constants is for the latest HelixMod DLL, and that the syntax changed from the older versions. The original documentation is thus misleading for the newer DLLs.
  
  
Line 42: Line 39:
 
*# Copy and paste that default .ini into our Ball DX9Settings.ini.
 
*# Copy and paste that default .ini into our Ball DX9Settings.ini.
 
*# Open the A977E84A.txt shader where we'll see how to use the constants we just made.
 
*# Open the A977E84A.txt shader where we'll see how to use the constants we just made.
*# In the ''def'' section, add new constant as:  
+
*# In the ''def'' section, add a new constant as:[http://msdn.microsoft.com/en-us/library/windows/desktop/bb205595(v=vs.85).aspx]
 
*#: '''//def c220, Const1, Const2, Const3, Const4'''
 
*#: '''//def c220, Const1, Const2, Const3, Const4'''
 
*#: '''def c200, 0, 1, 0.0625, 0 // x=0 for comparison to Const1'''
 
*#: '''def c200, 0, 1, 0.0625, 0 // x=0 for comparison to Const1'''
*# At the bottom, change our mov oC0 code to be the if statement:
+
*# At the bottom, change our mov oC0 code to be the if statement:[http://msdn.microsoft.com/en-us/library/windows/desktop/bb174582(v=vs.85).aspx]
*#: '''// if  Const1 = 0 turn effect off, else leave it on'''
+
*#: '''// if  Const1 = 0 disable effect, else leave it on'''
 
*#: '''mov r30.x, c220.x'''
 
*#: '''mov r30.x, c220.x'''
 
*#: '''if_eq r30.x, c200.x'''
 
*#: '''if_eq r30.x, c200.x'''
Line 52: Line 49:
 
*#: '''endif'''
 
*#: '''endif'''
 
*# Run The Ball and see if it works.
 
*# Run The Ball and see if it works.
 +
 +
 +
----
 +
With an understanding of how the constants work, it's time to demonstrate that you can alter this technique to suit your needs.
 +
 +
This quiz will be harder than the previous ones, as not every step will be detailed, and you will be expected to apply what you've learned.
 +
 +
 +
For this Quiz, you'll need to change 3 characteristics of the toggle mechanism, then upload your example code and a screen snapshot.
 +
 +
 +
* Modify the toggle code, then upload your changes.
 +
*# Change the key used to toggle the effect from Numpad 0 to any key of your choice.
 +
*# Change the mechanism to not toggle the effect, but only be active when held down.
 +
*# When the effect is being displayed, change its color.
 +
*# With those all working, go to [[Special:Upload]] and upload a screen shot.
 +
*# Go to your personal page and add a new section for '''== Lesson 3 =='''
 +
*# Add your code changes into a text section bracketed with '''<nowiki><nowiki></nowiki></nowiki>'''
 +
*# Add a link to your screenshot showing an alternate color with '''[[File:'''<nowiki></nowiki>''filename''<nowiki></nowiki>'''|700px]]'''
 +
 +
 +
----
 +
Were you able to navigate the DX9Settings.ini and shader code to change the behavior?  Excellent!  We nearly always use constants of some form in game fixes.
 +
 +
<br>
 +
<br>

Latest revision as of 22:36, 11 September 2014

Summary

This lesson will show how to create and use constants, from DX9Settings.ini all the way into the shader code itself.


Level of difficulty: Easy
Time required: 30 minutes

Video Walkthrough on YouTube

Objective

Learn how constants are defined and used, including possible problems and workarounds.
Learn how HelixMod constants work to make an on/off mechanism from the keyboard.

Quiz

Make a version that uses a different key, changes the color when on, and is only active when held down.


For this Lesson, let's take a quick look at another HelixMod feature that we are going to use extensively in the future. Our use here will be a simple version, but a good introduction.

In the HelixMod DX9Settings.ini file, we can add Constants, and we can then use those constants in any Pixel or Vertex Shader. They are provided by the tool as a convenience, and for any purpose that we wish. The constants can be used to make it easy to change the HUD depth for example, or specify how transparent to make it.

These constants can also be chosen based on a given key or mouse press, so that we can change effects in the shader, like changing viewpoints on key press, or changing convergence to zero when the right mouse is down.

Note that this version of constants is for the latest HelixMod DLL, and that the syntax changed from the older versions. The original documentation is thus misleading for the newer DLLs.


For our example here, we'll make a simple on/off mechanism, where we can decide in each shader whether to show the original shader, or our disabled version. Then by a keypress, Numpad 0 by default, we can toggle it from broken to disabled.

There is no particular advantage to do this, other than it's interesting and makes a great demo, but it can make it easier to decide whether something needs to be fixed or if disabled is good enough.


  • Create an on/off mechanism using HelixMod constants
    1. Edit the DX9Settings.ini file and set DumpAll=false for speed.
    2. Look at the DX9Settings.ini that we'll now use, at Default_DX9Settings.ini
    3. Copy and paste that default .ini into our Ball DX9Settings.ini.
    4. Open the A977E84A.txt shader where we'll see how to use the constants we just made.
    5. In the def section, add a new constant as:[1]
      //def c220, Const1, Const2, Const3, Const4
      def c200, 0, 1, 0.0625, 0 // x=0 for comparison to Const1
    6. At the bottom, change our mov oC0 code to be the if statement:[2]
      // if Const1 = 0 disable effect, else leave it on
      mov r30.x, c220.x
      if_eq r30.x, c200.x
      mov oC0.xyzw, c200.wwww
      endif
    7. Run The Ball and see if it works.



With an understanding of how the constants work, it's time to demonstrate that you can alter this technique to suit your needs.

This quiz will be harder than the previous ones, as not every step will be detailed, and you will be expected to apply what you've learned.


For this Quiz, you'll need to change 3 characteristics of the toggle mechanism, then upload your example code and a screen snapshot.


  • Modify the toggle code, then upload your changes.
    1. Change the key used to toggle the effect from Numpad 0 to any key of your choice.
    2. Change the mechanism to not toggle the effect, but only be active when held down.
    3. When the effect is being displayed, change its color.
    4. With those all working, go to Special:Upload and upload a screen shot.
    5. Go to your personal page and add a new section for == Lesson 3 ==
    6. Add your code changes into a text section bracketed with <nowiki></nowiki>
    7. Add a link to your screenshot showing an alternate color with [[File:filename|700px]]



Were you able to navigate the DX9Settings.ini and shader code to change the behavior? Excellent! We nearly always use constants of some form in game fixes.