Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

  1. ; STATIC: "NORMALMAPALPHAENVMAPMASK" "0..1"
  2. ps.1.4
  3. ;------------------------------------------------------------------------------
  4. ; Phase 1
  5. ;------------------------------------------------------------------------------
  6. ; Get the 3-vector from the normal map
  7. texld r0, t0
  8. ; Get environment matrix
  9. texcrd r1.rgb, t1
  10. texcrd r2.rgb, t2
  11. texcrd r3.rgb, t3
  12. ; Normalize eye-ray vector through normalizer cube map
  13. texld r4, t4 ; <---- CUBE MAP here!!!
  14. ;mov r0.rgba, r4
  15. ; Transform normal
  16. dp3 r5.r, r1, r0_bx2
  17. dp3 r5.g, r2, r0_bx2
  18. dp3 r5.b, r3, r0_bx2
  19. ; Reflection calculatiom
  20. dp3_x2 r3.rgb, r5, r4_bx2 ; 2(N.Eye)
  21. mul r3.rgb, r5, r3 ; 2N(N.Eye)
  22. dp3 r2.rgb, r5, r5 ; N.N
  23. mad r2.rgb, -r4_bx2, r2, r3 ; 2N(N.Eye) - Eye(N.N)
  24. #if NORMALMAPALPHAENVMAPMASK
  25. ; Alpha gets lost after phase marker, so store it here
  26. mov r5, r0.a
  27. #endif
  28. ;------------------------------------------------------------------------------
  29. ; Phase 2
  30. ;------------------------------------------------------------------------------
  31. ; What's left over from the last phase:
  32. ; r0 - normal
  33. ; r1 - free
  34. ; r2 - vector to sample in envmap
  35. ; r3 - free
  36. ; r4 - normal
  37. ; r5 - normal map alpha (rgba)
  38. phase
  39. ; Sample environment map
  40. texld r3, r2
  41. ; dot eye-vector with per-pixel normal from r0
  42. dp3_sat r1, v0_bx2, r0_bx2
  43. ; Result goes in output color (multiply by constant color c0)
  44. mul r0.rgb, r3, c0
  45. ; run Fresnel approx. on it: R0 + (1-R0) (1-cos(q))^5 in alpha channel
  46. mul r1.rgb, r0, r0
  47. +mul r0.a, 1-r1.a, 1-r1.a ; squared
  48. lrp r0.rgb, c1, r1, r0 ; blend between color and color * color
  49. +mul r0.a, r0.a, r0.a ; quartic
  50. dp3 r1.rgb, r0, c3
  51. +mul r0.a, r0.a, 1-r1.a ; quintic
  52. lrp r0.rgb, c2, r0, r1 ; blend between color and greyscale
  53. mad r0.a, r0.a, c6.a, c4.a ; Take Fresnel R(0) into consideration
  54. mul r0.rgb, r0, r0.a ; multiply output color by result of fresnel calc
  55. #if NORMALMAPALPHAENVMAPMASK
  56. +mul r0.a, c0.a, r5.r ; Fade amount * alpha from the texture
  57. #else
  58. +mov r0.a, c0.a ; Just use the fade amount
  59. #endif