User:DarkStarSword

From Bo3b's School for Shaderhackers
Jump to: navigation, search

Lesson 0

TheBall - 2014-08-31 - 230320.0.jpg

Lesson 1

This pixel shader changes the appearance of the flare on the main menu, but disabling it does not remove it o_O

//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
// Parameters:
//
//   sampler2D Texture2D_0;
//   float UniformPixelScalar_7;
//   float4 UniformPixelVector_0;
//   float4 UniformPixelVector_3;
//   float4 UniformPixelVector_4;
//   float4 UniformPixelVector_5;
//   float4 UniformPixelVector_6;
//
//
// Registers:
//
//   Name                 Reg   Size
//   -------------------- ----- ----
//   UniformPixelVector_0 c0       1
//   UniformPixelVector_3 c4       1
//   UniformPixelVector_4 c5       1
//   UniformPixelVector_5 c6       1
//   UniformPixelVector_6 c7       1
//   UniformPixelScalar_7 c8       1
//   Texture2D_0          s0       1
//

    ps_3_0
    def c1, 0.5, 1, -0.5, 0
    def c2, 3, 0, 0, 0
    dcl_texcoord v0.xy
    dcl_texcoord1 v1
    dcl_texcoord2 v2.y
    dcl_texcoord4 v3.w
    dcl_2d s0
    add r0.xy, c1.z, v0
    mov r0.w, c1.w
    dp2add r1.x, c5, r0, r0.w
    dp2add r1.y, c6, r0, r0.w
    add r0.xy, r1, c1.x
    texld r0, r0, s0
    mad_sat r0.y, v2.y, -c1.x, c1.y
    mul r0.yzw, r0.y, v1.xxyz
    mul r0.yzw, r0, v1.w
    mul_sat r0.xyz, r0.yzww, r0.x
    mul r1.xyz, r0, c4
    mad r0.xyz, c4, -r0, r0
    mad r0.xyz, c8.x, r0, r1
    mul r0.xyz, r0, c4.w
    mul r0.xyz, r0, c7
    mov r1.x, c2.x
    mad_pp r0.xyz, r0, r1.x, c0
    mul_pp oC0.xyz, r0, v3.w
    mov oC0.w, c1.w

// approximately 21 instruction slots used (1 texture, 20 arithmetic)

Lesson 2

Before:

TheBall - 2014-08-31 - 235735.0.jpg

After:

TheBall - 2014-08-31 - 235626.0.jpg

Lesson 3

DX9Settings.ini changes:

// Hold F8 to enable the bloom effect (note to self - don't use F7 as it
// rewrites this file without comments):
[KEY1]
Key = 119
Presets = 1;2;
Type = 2

Pixel shader changes:

def c200, 0.4, 0.2, 0, 0

// <---snip--->

//Disable game breaking bloom effect
mov r30.x, c220.x		// r30.x = Const1
if_eq r30.x, c1.w		// if (Const1 == 0) {
  mov oC0.xyzw, c1.wwww		//   oC0 = 0
else				// } else {
  mov oC0, c200			//   oC0 = c200 (orange)
endif				// }

TheBall - 2014-09-01 - 213938.0.jpg

Lesson 4

This is a bit more complex than the quiz calls for - I wanted a template DX9Settings.ini file that I could use to toggle all four constants and easily allow one of them (Const3 in this case) to be set to an arbitrary value between 0.0 and 1.0. The idea being that while hacking on shaders I may want to use a number of constants and won't necessarily want to restart the entire game every time.

[General]

// UseRenderedShaders=true is nearly always useful, because it trims the 
// list of shaders seen while hunting down to just those active in the 
// current scene.  Disable this only if you get crashes during hunting.
UseRenderedShaders=true

// DumpAll will generate ASM text files for every shader seen by the game.
// This is usually worth doing once, but not useful for every run.
// DumpAll=true

// Constant registers that will arrive in Vertex and Pixel Shaders, as
// c200.  The constants below will be assigned, based on the key preset.
DefVSConst1 = 200  		
DefPSConst1 = 200

// The PresetKeysList specifies which KEYs will be used.
// Multiple keys lists are supported.
// Note that the KEY sections are in hexadecimal
PresetsKeysList = 0;1;2;3;4;5;6;7;8;9;A;B;C;D;E;

// Allows textures to be cycled with Up/Down - use to hunt menu text CRC32
// bCalcTexCRCatStart = true

// Number row on keyboard sets UI depth to various values between screen depth
// and separation. `~ (left of 1 on US keyboards) sets screen depth, 1-9 sets
// septh in 10% multiples and 0 sets depth to 100% separation.
// Note that the KEY%X on these sections is in hexadecimal, hence we use KEYA
// for the tenth key entry and so on.
[KEY0]
Key = 192
Presets = 0;
Type = 1
[PRES0]
Const3 = 0x00000000
[KEY1]
Key = 49
Presets = 1;
Type = 1
[PRES1]
Const3 = 0x3dcccccd
[KEY2]
Key = 50
Presets = 2;
Type = 1
[PRES2]
Const3 = 0x3e4ccccd
[KEY3]
Key = 51
Presets = 3;
Type = 1
[PRES3]
Const3 = 0x3e99999a
[KEY4]
Key = 52
Presets = 4;
Type = 1
[PRES4]
Const3 = 0x3ecccccd
[KEY5]
Key = 53
Presets = 5;
Type = 1
[PRES5]
Const3 = 0x3f000000
[KEY6]
Key = 54
Presets = 6;
Type = 1
[PRES6]
Const3 = 0x3f19999a
[KEY7]
Key = 55
Presets = 7;
Type = 1
[PRES7]
Const3 = 0x3f333333
[KEY8]
Key = 56
Presets = 8;
Type = 1
[PRES8]
Const3 = 0x3f4ccccd
[KEY9]
Key = 57
Presets = 9;
Type = 1
[PRES9]
Const3 = 0x3f666666
[KEYA]
Key = 48
Presets = A;
Type = 1
[PRESA]
Const3 = 0x3f800000

// U toggles Const1
[KEYB]
Key = 85
Presets = B;C;
Type = 1
[PRESB]
Const1 = 0x3f800000
[PRESC]
Const1 = 0x00000000

// I toggles Const2
[KEYC]
Key = 73
Presets = D;E;
Type = 1
[PRESD]
Const2 = 0x3f800000
[PRESE]
Const2 = 0x00000000

// O toggles Const3
[KEYD]
Key = 79
Presets = F;10;
Type = 1
[PRESF]
Const3 = 0x3f800000
[PRES10]
Const3 = 0x00000000

// P toggles Const4
[KEYE]
Key = 80
Presets = 11;12;
Type = 1
[PRES11]
Const4 = 0x3f800000
[PRES12]
Const4 = 0x00000000