Difference between revisions of "Lesson 3 - Const"
Bo3b admin (Talk | contribs) (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...") |
Bo3b admin (Talk | contribs) m (Protected "Lesson 3 - Const" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))) |
(No difference)
|
Revision as of 22:29, 31 August 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: 25 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
...
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.
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.
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
- Edit the DX9Settings.ini file and set DumpAll=false for speed.
- Look at the DX9Settings.ini that we'll now use, at Default_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.
- In the def section, add new constant as:
- //def c220, Const1, Const2, Const3, Const4
- 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:
- // if Const1 = 0 turn effect off, else leave it on
- mov r30.x, c220.x
- if_eq r30.x, c200.x
- mov oC0.xyzw, c200.wwww
- endif
- Run The Ball and see if it works.