User:Westbrook348

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

Lesson 0

TheBall01 50.jpg

TheBall02 50.jpg

Lesson 1

TheBall03 50.jpg

//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
// Parameters:
//
//   float4 AmbientColorAndSkyFactor;
//   float4 MinZ_MaxZRatio;
//   sampler2D Texture2D_0;
//   sampler2D Texture2D_1;
//   sampler2D Texture2D_2;
//   sampler2D Texture2D_3;
//   sampler2D Texture2D_4;
//   sampler2D Texture2D_5;
//   sampler2D Texture2D_6;
//   sampler2D Texture2D_7;
//   sampler2D Texture2D_8;
//   float UniformPixelScalar_23;
//   float UniformPixelScalar_24;
//   float UniformPixelScalar_5;
//   float UniformPixelScalar_6;
//   float4 UniformPixelVector_0;
//   float4 UniformPixelVector_1;
//   float4 UniformPixelVector_10;
//   float4 UniformPixelVector_11;
//   float4 UniformPixelVector_12;
//   float4 UniformPixelVector_13;
//   float4 UniformPixelVector_14;
//   float4 UniformPixelVector_15;
//   float4 UniformPixelVector_16;
//   float4 UniformPixelVector_17;
//   float4 UniformPixelVector_18;
//   float4 UniformPixelVector_2;
//   float4 UniformPixelVector_3;
//   float4 UniformPixelVector_4;
//   float4 UniformPixelVector_5;
//   float4 UniformPixelVector_6;
//   float4 UniformPixelVector_7;
//   float4 UniformPixelVector_8;
//   float4 UniformPixelVector_9;
//
//
// Registers:
//
//   Name                     Reg   Size
//   ------------------------ ----- ----
//   UniformPixelVector_0     c0       1
//   MinZ_MaxZRatio           c2       1
//   UniformPixelVector_1     c4       1
//   UniformPixelVector_2     c5       1
//   UniformPixelVector_3     c6       1
//   UniformPixelVector_4     c7       1
//   UniformPixelVector_5     c8       1
//   UniformPixelVector_6     c9       1
//   UniformPixelVector_7     c10      1
//   UniformPixelVector_8     c11      1
//   UniformPixelVector_9     c12      1
//   UniformPixelVector_10    c13      1
//   UniformPixelVector_11    c14      1
//   UniformPixelVector_12    c15      1
//   UniformPixelVector_13    c16      1
//   UniformPixelVector_14    c17      1
//   UniformPixelVector_15    c18      1
//   UniformPixelVector_16    c19      1
//   UniformPixelVector_17    c20      1
//   UniformPixelVector_18    c21      1
//   UniformPixelScalar_5     c22      1
//   UniformPixelScalar_6     c23      1
//   UniformPixelScalar_23    c24      1
//   UniformPixelScalar_24    c25      1
//   AmbientColorAndSkyFactor c26      1
//   Texture2D_0              s0       1
//   Texture2D_1              s1       1
//   Texture2D_2              s2       1
//   Texture2D_3              s3       1
//   Texture2D_4              s4       1
//   Texture2D_5              s5       1
//   Texture2D_6              s6       1
//   Texture2D_7              s7       1
//   Texture2D_8              s8       1
//

    ps_3_0
    def c1, 0.75, -9.99999997e-007, 6, -0.333299994
    def c3, 0.666700006, 1.5, 0.0250000004, 4
    def c27, 5, 0.5, 6.28318548, -3.14159274
    def c28, 0.200000003, 0.100000001, 10, 0.800000012
    def c29, 0.300000012, 0.589999974, 0.109999999, 0.600000024
    def c30, 1.5, 0.649999976, 0, 0
    def c31, 0.5, -0.5, 8, 17
    def c32, 2, -1, -0.5, 0
    def c33, 1.25, 1, 0, 0
    def c34, 9, 0.5, 0.200000003, 0.100000001
    def c35, 0.450000018, 100, 90, 0.100000001
    def c36, 0.816496611, 0.577350259, 0, 0
    def c37, -0.707106769, -0.408248305, 0.577350259, 0.707106769
    dcl_texcoord2_pp v0.xyz
    dcl_texcoord3_pp v1.xyz
    dcl_texcoord5 v2.w
    dcl_texcoord6 v3.xyz
    dcl_color v4.xyz
    dcl_color1 v5
    dcl_texcoord v6
    dcl_2d s0
    dcl_2d s1
    dcl_2d s2
    dcl_2d s3
    dcl_2d s4
    dcl_2d s5
    dcl_2d s6
    dcl_2d s7
    dcl_2d s8
    mul r0.xy, c1.x, v6
    texld r0, r0, s8
    add r0.y, r0_abs.x, c1.y
    pow r1.x, r0_abs.x, c25.x
    cmp r0.y, r0.y, r1.x, c32.w
    lrp r1.x, c24.x, r0.y, r0.x
    mul r0.x, r1.x, c24.x
    mul_sat r0.x, r0.x, c1.z
    add r0.x, r0.x, c1.w
    mov r1, c32
    add r0.y, r1.y, c24.x
    cmp r0, r0.y, c3.x, r0.x
    texkill r0
    mov r0.y, c3.y
    mad r0.xy, v6, r0.y, c11
    texld r0, r0, s2
    mad r0.xz, v6.xyyw, r1.x, c12.xyyw
    texld r2, r0.xzzw, s2
    mul r0.x, r2.y, c3.z
    mad r0.x, r0.y, r2.y, r0.x
    add r0.yz, c9.xxyw, v6.xxyw
    texld r2, r0.yzzw, s2
    mad r0.yz, v6.xxyw, -r1.z, c10.xxyw
    texld r3, r0.yzzw, s2
    mul r0.y, r2.x, r3.x
    mad r0.x, r0.y, c3.w, r0.x
    mul r0.xyz, r0.x, c8
    mov r1.x, c23.x
    mul r0.w, r1.x, c13.x
    mad r0.w, r0.w, c27.x, c27.y
    frc r0.w, r0.w
    mad r0.w, r0.w, c27.z, c27.w
    sincos r2.y, r0.w
    mul r2.xyz, r0, r2.y
    mad r0.xyz, r2, c32.z, r0
    nrm_pp r2.xyz, v4
    nrm_pp r3.xyz, v5
    mul_pp r4.xyz, r2.yzxw, r3.zxyw
    mad_pp r4.xyz, r3.yzxw, r2.zxyw, -r4
    mul r4.xyz, r4, v5.w
    mov r5.y, r4.z
    dp3 r4.y, r4, c19
    mov_pp r5.x, r2.z
    dp3 r4.x, r2, c19
    mov_pp r5.z, r3.z
    dp3 r0.w, r5, r5
    rsq r0.w, r0.w
    mul r0.w, r0.w, r5.z
    dp3 r4.z, r3, c19
    mad r0.w, r0.w, c29.w, c29.w
    mul r1.x, r0_abs.w, r0_abs.w
    add r0.w, r0_abs.w, c1.y
    mul r1.x, r1.x, r1.x
    mul r1.x, r1.x, r1.x
    mul r1.x, r1.x, c3.w
    cmp r0.w, r0.w, r1.x, c32.w
    min r1.x, r0.w, c28.w
    dp3 r0.w, r4, r4
    rsq r0.w, r0.w
    mul r0.w, r0.w, r4.z
    mad r0.w, r0.w, c31.y, c31.x
    add r2.x, r0_abs.w, c1.y
    mul r0.w, r0_abs.w, r0_abs.w
    mul r0.w, r0.w, r0.w
    mul r0.w, r0.w, r0.w
    mul r0.w, r0.w, c3.w
    cmp r0.w, r2.x, r0.w, c32.w
    min r2.x, r0.w, c28.w
    add r0.w, -r2.x, -c32.y
    mad r0.w, c20.x, r0.w, r2.x
    mad r2.xy, v6.wzzw, c31.x, c31.y
    dp2add r3.x, c17, r2, r1.w
    dp2add r3.y, c18, r2, r1.w
    add r2.xy, r3, -c32.z
    texld r2, r2, s6
    add r2.xyz, r2, c30
    mov r3.yzw, c32_abs.xyxw
    texld r4, v6, s3
    dp3 r2.w, r4, c29
    mul r3.x, r2.w, c28.z
    mul r2.xyz, r2, r3.xyxw
    mul r2.xyz, r2, r3.zxww
    mul r2.xyz, r0.w, r2
    add r3.xy, v6, v6
    nrm r5.xyz, v3
    mad r3.xy, r5, c35.x, r3
    texld r3, r3, s4
    mul r3.xyz, r3.y, c35.yzzw
    max r6.xyz, r4_abs, -c1.y
    log r7.x, r6.x
    log r7.y, r6.y
    log r7.z, r6.z
    mul r6.xyz, r7, c3.y
    exp r7.x, r6.x
    exp r7.y, r6.y
    exp r7.z, r6.z
    mad r3.xyz, r3, r7, r4
    texld r6, v6, s5
    mul r3.xyz, r3, r6.x
    mul r7.xyz, r4, c28.xyyw
    mad r3.xyz, r3, c35.w, r7
    mad r3.xyz, r6.z, c15, r3
    mad r2.xyz, c16.x, r2, r3
    mul r3.xyz, r4, c32_abs
    mad r2.xyz, r1.x, r3, r2
    mul r0.w, r4.w, c21.x
    mad r2.xyz, r0.w, c32_abs.xzww, r2
    mad r0.xyz, c14.x, r0, r2
    add_pp r0.xyz, r0, c0
    mad r0.w, r5.z, -c33.x, c33.y
    cmp r0.w, r5.z, r0.w, -c32.y
    mul r1.x, r0_abs.w, r0_abs.w
    mul r1.x, r1.x, r1.x
    mul r1.x, r0_abs.w, r1.x
    add r0.w, r0_abs.w, c1.y
    mad r2.xyz, r4, c34.x, c34.yzww
    mul r2.xyz, r1.x, r2
    cmp r2.xyz, r0.w, r2, c32.w
    add r2.xyz, r2, r4
    add r3.xyz, -r1.y, -c0
    mul_pp r2.xyz, r2, r3
    mul_pp r3.xyz, r2, v0
    mad r1.xy, c22.x, v6, r1.z
    dp2add r4.x, c5, r1, r1.w
    dp2add r4.y, c6, r1, r1.w
    add r1.xy, r4, -c32.z
    texld r1, r1, s1
    mad r1.xyz, r1, c32.x, c32.y
    mul r1.xyz, r1, c7
    texld r4, v6, s0
    mad r4.xyz, r4, c32.x, c32.y
    mad_pp r1.xyz, r4, c4, r1
    nrm_pp r4.xyz, r1
    dp3 r0.w, r4, r5
    mul r1.xyz, r0.w, r4
    mad r1.xyz, r1, c32.x, -r5
    dp2add_sat_pp r5.x, r1.yzzw, c36, c36.z
    dp3_sat_pp r5.y, r1, c37
    dp3_sat_pp r5.z, r1.yzxw, c37.yzww
    max r1.xyz, r5, -c1.y
    log r5.x, r1.x
    log r5.y, r1.y
    log r5.z, r1.z
    mad_pp r0.w, r6.x, c31.z, c31.w
    mul r1.xyz, r6.y, c32_abs.xzww
    mul r5.xyz, r5, r0.w
    exp_pp r6.x, r5.x
    exp_pp r6.y, r5.y
    exp_pp r6.z, r5.z
    dp3_pp r0.w, v1, r6
    texld r5, v6, s7
    mad_pp r1.xyz, r5, c3.w, r1
    mul_pp r1.xyz, r1, v0
    mul_pp r1.xyz, r0.w, r1
    dp2add_sat_pp r5.x, r4.yzzw, c36, c36.z
    dp3_sat_pp r5.y, r4, c37
    dp3_sat_pp r5.z, r4.yzxw, c37.yzww
    mul_pp r4.xyz, r5, r5
    max_pp r5.xyz, r4, -c1.y
    dp3_pp r0.w, v1, r5
    mad_pp r1.xyz, r3, r0.w, r1
    add_pp r0.xyz, r0, r1
    mad_pp oC0.xyz, r2, c26, r0
    rcp r0.x, v2.w
    mad_pp oC0.w, c2.x, r0.x, c2.y

// approximately 188 instruction slots used (12 texture, 176 arithmetic)
 

Lesson 2

Before:

TheBall04 50.jpg

After:

TheBall05 50.jpg

Lesson 3

Shader A977E84A.txt

// Annoying bloom on ball light
// ...
    ps_3_0
	
//def c220, Const1, Const2, Const3, Const4
def c200, 0, 1, 0.0625, 0	// x=0 for comparison to Const1

    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		// Light changes color pink <==> yellow
    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

// Toggle bloom effect
// if Const1 = 0 disable effect, else leave it on
mov r30.x, c220.x
if_eq r30.x, c200.x
   mov oC0.xyzw, c200.xxxx
endif

DX9Settings.ini

[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=false

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

// The PresetKeysList specifies which KEYs will be used.
// Multiple keys lists are supported.
PresetsKeysList = 1;

// For this single key example, we only need one keylist, KEY1. This specifies
// that the Numpad 0 keyboard key (Key=96) should act as a toggle. And toggle
// between the two Presets of PRES1, PRES2.  Which will change the Const1 being 
// passed to the shader code from 1.0 to 0.0 as floating point numbers.
// Type=1 is toggle, Type=2 is momentary.
[KEY1]
Key = 8		// Backspace
Presets = 1;2;
Type = 2

// Constants that will be sent to every shader through constant register c220.
// The Const1 tells us that we'll need to use c220.x to compare against these
// values.  Const2 would be seen as c220.y.
// 0x3f800000 is 1.0 in floating point hex, 0x00000000 is 0.0 in hex
// UseByDef specifies which constant is the default starting value.
[PRES1]
Const1 = 0x3f800000
[PRES2]
UseByDef=True
Const1 = 0x00000000

TheBall06 50.jpg

Lesson 4

[General]

UseRenderedShaders=true
DumpAll=false

DefVSConst1 = 220  		
DefPSConst1 = 220

PresetsKeysList = 1;2;

[KEY1]
Key = 96
Presets = 1;2;
Type = 1

[KEY2]
Key = 8	   // Backspace
Presets = 3;4;
Type = 1

[PRES1]
Const1 = 0x3f800000

[PRES2]
UseByDef=True
Const1 = 0x00000000

[PRES3]
Const2 = 0x3f800000

[PRES4]
UseByDef=True
Const2 = 0x00000000

Lesson 5

PS 47B32BDA

// Light reflections on surface of green goo disappear - FIXED
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
// Parameters:
//
//   float4 MinZ_MaxZRatio;
//   float NvStereoEnabled;
//   sampler2D NvStereoFixTexture;
//   sampler2D SceneColorTexture;
//   float4 ScreenPositionScaleBias;
//   sampler2D Texture2D_0;
//   sampler2D Texture2D_1;
//   sampler2D Texture2D_2;
//   float4 UniformPixelVector_0;
//   float4 UniformPixelVector_1;
//   float4 UniformPixelVector_2;
//   float4 UniformPixelVector_3;
//   float4 UniformPixelVector_4;
//   float4 UniformPixelVector_5;
//   float4 UniformPixelVector_6;
//
//
// Registers:
//
//   Name                    Reg   Size
//   ----------------------- ----- ----
//   UniformPixelVector_0    c0       1
//   ScreenPositionScaleBias c1       1
//   MinZ_MaxZRatio          c2       1
//   NvStereoEnabled         c3       1
//   UniformPixelVector_1    c4       1
//   UniformPixelVector_2    c5       1
//   UniformPixelVector_3    c6       1
//   UniformPixelVector_4    c7       1
//   UniformPixelVector_5    c8       1
//   UniformPixelVector_6    c9       1
//   SceneColorTexture       s0       1
//   NvStereoFixTexture      s1       1
//   Texture2D_0             s2       1
//   Texture2D_1             s3       1
//   Texture2D_2             s4       1
//

    ps_3_0
    def c10, 6, 2, -1, 4
    def c11, 0.200000003, -0.0500000007, 0.25, 0.800000012
    def c12, 0.300000012, 0.589999974, 0.109999999, 0.174999997
    def c13, 25, 40, 4, 65503
    def c14, 0.00800000038, -0.150000006, 0.0625, 0
    def c15, 2, 4, 0, 3
    def c16, 2, 3, 0.5, 0.0078125
    def c17, 8, -9.99999997e-007, 2.5, 0
    dcl_texcoord4 v0
    dcl_texcoord5 v1.xyw
    dcl_texcoord6 v2.xyz
    dcl_texcoord v3.xy
    dcl_2d s0
    dcl_2d s1
    dcl_2d s2
    dcl_2d s3
    dcl_2d s4
    dp3 r0.x, v2, v2
    rsq r0.x, r0.x
    mul r0.xy, r0.x, v2
    add r0.zw, v3.xyxy, v3.xyxy
    mov r1.xw, c10
    mad r1.xy, v3, r1.x, c4
    texld r2, r1, s2
    mad r1.x, r2.x, c10.y, c10.z
    mad r1.yz, v3.xxyw, r1.w, c5.xxyw
    texld r2, r1.yzzw, s2
    mad r1.y, r2.y, c10.y, c10.z
    mul r1.x, r1.y, r1.x
    mov r2.x, c17.x
    mad r1.yz, v3.xxyw, r2.x, c6.xxyw
    texld r3, r1.yzzw, s3
    mad r1.x, r1.x, c10.w, r3.x
    add r1.y, -r1.x, c10.z
    mad r0.zw, r1.y, r0.xyxy, r0
    texld r4, r0.zwzw, s3
    add r0.z, r4_abs.y, c17.y
    pow r0.w, r4_abs.y, c17.z
    mul r2.yzw, r0.w, c15.xxyz
    cmp r2.yzw, r0.z, r2, c17.w
    mad r0.zw, v3.xyxy, r1.w, c7.xyxy
    texld r4, r0.zwzw, s4
    mul r1.yzw, r4.xxyz, c15.w
    mad r0.zw, v3.xyxy, r2.x, c8.xyxy
    mad r1.x, r1.x, c11.x, c11.y
    mad r0.xy, r1.x, r0, r0.zwzw
    texld r0, r0, s4
    mul r3.xyw, r0.xyzz, r1.yzzw
    dp3 r0.w, r3.xyww, c12
    mad r0.xyz, r1.yzww, -r0, r0.w
    mad r0.xyz, r0, c11.z, r3.xyww
    max r1.xyz, r0_abs, -c17.y
    log r0.x, r1.x
    log r0.y, r1.y
    log r0.z, r1.z
    mul r0.xyz, r0, c11.w
    exp r1.x, r0.x
    exp r1.y, r0.y
    exp r1.z, r0.z
    mov r0.w, c15.w
    mad r0.xy, v3, r0.w, c9
    texld r0, r0, s3
    mul r0.x, r0.z, r3.z
    mul r0.xyz, r0.x, c13
    mad r0.xyz, r1, c16, r0
    add r0.xyz, r0, r2.yzww
    dp3 r0.w, r0, c12
    lrp r1.xyz, c11.z, r0.w, r0
    add_pp r0.xyz, r1, c0
    mad_sat r0.w, v1.w, c14.x, c14.y
    mul r0.w, r0.w, c12.w
    abs r1.x, c3.x
    if_ne c3.x, -c3.x
      texld r2, c14.zwzw, s1
      add r1.y, -r2.y, v1.w
      mad r2.x, r2.x, r1.y, v1.x
      mov r2.yz, v1.xyww
    else
      mov r2.xyz, c17.w
    endif

// fix green goo edges part A  (replace v1)  
mov r30.x, c220.x
if_eq r30.x, c200.x
	mov r30.xyzw, c200.wwww
	cmp r1.xyz, -r1.x, r30.xyww, r2
else
	cmp r1.xyz, -r1.x, v1.xyww, r2
endif
   
    rcp r1.z, r1.z
    mul r1.xy, r1.z, r1
    mad r1.xy, r1, c1, c1.wzzw
    texld_pp r1, r1, s0
    min_pp r2.x, r1.w, c13.w
    mad r1.x, r2.x, c2.z, -c2.w
    rcp_pp r1.x, r1.x

// fix green goo edges part B (replace v1)
mov r30.x, c220.x
if_eq r30.x, c200.x
    mov r30.xyzw, c200.wwww
	add r1.x, r1.x, r30.w
else
	add r1.x, r1.x, -v1.w
endif
   
    mul_sat r1.x, r1.x, c16.w
    mul_pp oC0.w, r0.w, r1.x
    mad_pp oC0.xyz, r0, v0.w, v0

// approximately 79 instruction slots used (9 texture, 70 arithmetic)

Before:

TheBall07 50.jpg

After:

TheBall08 50.jpg

Lesson 6

Apply Prime directive to VS 4A65B800 to fix oil effect

...
def c200, 1.0, 600, 0.0625, 0
dcl_2d s0
...
//mov o3, r4
...
mov r0, r4
...
// Prime Directive
...
mov o3, r0

Before:

TheBall09 50.jpg

After:

TheBall10 50.jpg