| 1 | // Pixel Shader for doing bump mapping with parallax plus diffuse and specular lighting by nfz  | 
|---|
| 2 |  | 
|---|
| 3 | // uv               TEXCOORD0  | 
|---|
| 4 | // lightDir            TEXCOORD1  | 
|---|
| 5 | // eyeDir            TEXCOORD2  | 
|---|
| 6 | // half               TEXCOORD3  | 
|---|
| 7 |  | 
|---|
| 8 | // lightDiffuse         c0  | 
|---|
| 9 | // lightSpecular      c1  | 
|---|
| 10 | // Parallax scale and bias c2  | 
|---|
| 11 | // normal/height map   texunit 0 - height map in alpha channel  | 
|---|
| 12 | // diffuse texture      texunit 1  | 
|---|
| 13 |  | 
|---|
| 14 | ps.1.4  | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | texld r0, t0               // get height  | 
|---|
| 18 | texcrd r2.xyz, t0            // get uv coordinates  | 
|---|
| 19 | texcrd r3.xyz, t2            // get eyedir vector  | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 | mad r0.xyz, r0.a, c2.x, c2.y   // displacement = height * scale + bias  | 
|---|
| 23 | mad r2.xyz, r3, r0, r2         // newtexcoord = eyedir * displacement + uv  | 
|---|
| 24 |  | 
|---|
| 25 | phase  | 
|---|
| 26 |  | 
|---|
| 27 | texld r0, r2.xyz            // get normal N using newtexcoord  | 
|---|
| 28 | texld r1, r2.xyz            // get diffuse texture using newtexcoord  | 
|---|
| 29 | texcrd r4.xyz, t1            // get lightdir vector  | 
|---|
| 30 | texcrd r5.xyz, t3            // get half angle vector  | 
|---|
| 31 |  | 
|---|
| 32 | dp3_sat r5.rgb, r0_bx2, r5         // N dot H - spec calc  | 
|---|
| 33 | dp3_sat r4.rgb, r0_bx2, r4         // N dot L - diffuse calc  | 
|---|
| 34 | + mul r5.a, r5.r, r5.r  | 
|---|
| 35 | mul r0.rgb, r4, r1            // colour = diffusetex * N dot L  | 
|---|
| 36 | + mul r5.a, r5.a, r5.a  | 
|---|
| 37 |  | 
|---|
| 38 | mul r5.rgb, r5.a, r5.a           | 
|---|
| 39 | mul r5.rgb, r5, r5           | 
|---|
| 40 | mul r5.rgb, r5, r5           | 
|---|
| 41 | mul r5.rgb, r5, c1            // specular = (N dot H)^32 * specularlight  | 
|---|
| 42 |  | 
|---|
| 43 | mad r0.rgb, r0, c0, r5         // colour = diffusetex * (N dot L)* diffuselight + specular  | 
|---|
| 44 | + mov r0.a, c2.b  | 
|---|