Advertisement
yerWizard

pica shader

May 13th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. ; Example PICA200 vertex shader
  2.  
  3. ; Uniforms
  4. .fvec projection[4], model[4], view[4]
  5. .fvec lightVec, lightHalfVec, lightClr, material[4]
  6. .alias mat_amb material[0]
  7. .alias mat_dif material[1]
  8. .alias mat_spe material[2]
  9. .alias mat_emi material[3]
  10.  
  11. ; Constants
  12. .constf myconst(0.0, 1.0, -1.0, -0.5)
  13. .alias zeros myconst.xxxx ; Vector full of zeros
  14. .alias ones myconst.yyyy ; Vector full of ones
  15.  
  16. ; Outputs
  17. .out outpos position
  18. .out outtc0 texcoord0
  19. .out outclr color
  20.  
  21. ; Inputs (defined as aliases for convenience)
  22. .alias inpos v0
  23. .alias intex v1
  24. .alias innrm v2
  25.  
  26. .proc main
  27. ; Force the w component of inpos to be 1.0
  28. mov r0.xyz, inpos ; mov --> move value inpos to r0.xyz
  29. mov r0.w, ones
  30.  
  31. ; Calculating the MVP (Model View Projection) matrix
  32.  
  33. ; r1 = model * inpos
  34. dp4 r1.x, model[0], r0
  35. dp4 r1.y, model[1], r0
  36. dp4 r1.z, model[2], r0
  37. dp4 r1.w, model[3], r0
  38.  
  39. ;
  40. dp4 r2.x, view[0], r1
  41. dp4 r2.y, view[1], r1
  42. dp4 r2.z, view[2], r1
  43. dp4 r2.w, view[3], r1
  44.  
  45. ; outpos = projection * r2
  46. dp4 outpos.x, projection[0], r2
  47. dp4 outpos.y, projection[1], r2
  48. dp4 outpos.z, projection[2], r2
  49. dp4 outpos.w, projection[3], r2
  50.  
  51. ; outtex = intex
  52. mov outtc0, intex
  53.  
  54. ; Transform the normal vector with the modelView matrix
  55. ; r1 = normalize(modelView * innrm)
  56. mov r0.xyz, innrm
  57. mov r0.w, zeros
  58. dp4 r1.x, model[0], r0
  59. dp4 r1.y, model[1], r0
  60. dp4 r1.z, model[2], r0
  61. mov r1.w, zeros
  62. dp3 r2, r1, r1 ; r2 = x^2+y^2+z^2 for each component
  63. rsq r2, r2 ; r2 = 1/sqrt(r2) ''
  64. mul r1, r2, r1 ; r1 = r1*r2
  65.  
  66. ; Calculate the diffuse level (r0.x) and the shininess level (r0.y)
  67. ; r0.x = max(0, -(lightVec * r1))
  68. ; r0.y = max(0, (-lightHalfVec[i]) * r1) ^ 2
  69. dp3 r0.x, lightVec, r1
  70. add r0.x, zeros, -r0
  71. dp3 r0.y, -lightHalfVec, r1
  72. max r0, zeros, r0
  73. mul r0.y, r0, r0
  74.  
  75. ; Accumulate the vertex color in r1, initializing it to the emission color
  76. mov r1, mat_emi
  77.  
  78. ; r1 += specularColor * lightClr * shininessLevel
  79. mul r2, lightClr, r0.yyyy
  80. mad r1, r2, mat_spe, r1
  81.  
  82. ; r1 += diffuseColor * lightClr * diffuseLevel
  83. mul r2, lightClr, r0.xxxx
  84. mad r1, r2, mat_dif, r1
  85.  
  86. ; r1 += ambientColor * lightClr
  87. mov r2, lightClr
  88. mad r1, r2, mat_amb, r1
  89.  
  90. ; outclr = clamp r1 to [0,1]
  91. min outclr, ones, r1
  92.  
  93. ; We're finished
  94. end
  95. .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement