iMackshun

skinnedmodelshader.v.pica

Jan 16th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. ; Skinned Model Shader
  2.  
  3. ; Constants
  4.  
  5. .constf zeros(0, 0, 0, 0)
  6. .constf ones(1, 1, 1, 1)
  7. .constf offset(4, 4, 4, 4)
  8.  
  9. ; Inputs
  10.  
  11. .alias inpos v0
  12. .alias innrm v1
  13. .alias inclr v2
  14. .alias inuv v3
  15. .alias inbid v4
  16. .alias inbwt v5
  17.  
  18. ; Outputs
  19.  
  20. .out outpos position
  21. .out outclr color
  22. .out outuv texcoord0
  23.  
  24. ; Uniforms
  25.  
  26. .fvec projectionMatrix[4]
  27. .fvec viewMatrix[4]
  28. .fvec modelMatrix[4]
  29. .fvec boneMatrices[64]
  30.  
  31. ; Main Function
  32. .proc main
  33. ; Multiply the inbid by 4 to generate the correct offsets.
  34. mul r0, offset, inbid
  35.  
  36. ; Calculate the first transformed position.
  37. mova a0.x, r0.x
  38. dp4 r1.x, boneMatrices[a0.x], inpos
  39. dp4 r1.y, boneMatrices[a0.x + 1], inpos
  40. dp4 r1.z, boneMatrices[a0.x + 2], inpos
  41. dp4 r1.w, boneMatrices[a0.x + 3], inpos
  42.  
  43. ; Calculate the second transformed position.
  44. mova a0.x, r0.y
  45. dp4 r2.x, boneMatrices[a0.x], inpos
  46. dp4 r2.y, boneMatrices[a0.x + 1], inpos
  47. dp4 r2.z, boneMatrices[a0.x + 2], inpos
  48. dp4 r2.w, boneMatrices[a0.x + 3], inpos
  49.  
  50. ; Calculate the third transformed position.
  51. mova a0.x, r0.z
  52. dp4 r3.x, boneMatrices[a0.x], inpos
  53. dp4 r3.y, boneMatrices[a0.x + 1], inpos
  54. dp4 r3.z, boneMatrices[a0.x + 2], inpos
  55. dp4 r3.w, boneMatrices[a0.x + 3], inpos
  56.  
  57. ; Multiply each register by the corresponding weight.
  58. mul r1, r1, inbwt.xxxx
  59. mul r2, r2, inbwt.yyyy
  60. mul r3, r3, inbwt.zzzz
  61.  
  62. ; Add the transformed positions together to get the final model-space position of the vertex.
  63. add r4, zeros, r1
  64. add r4, r4, r2
  65. add r4, r4, r3
  66.  
  67. ; modelMatrix * inpos
  68. dp4 r5.x, modelMatrix[0], r1
  69. dp4 r5.y, modelMatrix[1], r1
  70. dp4 r5.z, modelMatrix[2], r1
  71. dp4 r5.w, modelMatrix[3], r1
  72.  
  73. ; viewMatrix * modelMatrix * inpos
  74. dp4 r6.x, viewMatrix[0], r5
  75. dp4 r6.y, viewMatrix[1], r5
  76. dp4 r6.z, viewMatrix[2], r5
  77. dp4 r6.w, viewMatrix[3], r5
  78.  
  79. ; projectionMatrix * viewMatrix * modelMatrix * inpos
  80. dp4 outpos.x, projectionMatrix[0], r6
  81. dp4 outpos.y, projectionMatrix[1], r6
  82. dp4 outpos.z, projectionMatrix[2], r6
  83. dp4 outpos.w, projectionMatrix[3], r6
  84.  
  85. ; outclr = inclr
  86. mov outclr, inclr
  87.  
  88. ; outuv = inuv
  89. mov outuv, inuv
  90.  
  91. ; Function termination
  92. end
  93. .end
Advertisement
Add Comment
Please, Sign In to add comment