Advertisement
Guest User

Untitled

a guest
Oct 17th, 2014
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. // VERTEX SHADER BODY
  2. code += "void main(void)\n";
  3. code += "{\n";
  4. // SKINNING
  5. if (options.skin) {
  6. code += " mat4 modelMatrix = vertex_boneWeights.x * getBoneMatrix(vertex_boneIndices.x) +\n";
  7. code += " vertex_boneWeights.y * getBoneMatrix(vertex_boneIndices.y) +\n";
  8. code += " vertex_boneWeights.z * getBoneMatrix(vertex_boneIndices.z) +\n";
  9. code += " vertex_boneWeights.w * getBoneMatrix(vertex_boneIndices.w);\n";
  10. if (lighting) {
  11. code += " mat3 normalMatrix = mat3(modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz);\n";
  12. }
  13. } else {
  14. code += " mat4 modelMatrix = matrix_model;\n";
  15. if (lighting) {
  16. code += " mat3 normalMatrix = matrix_normal;\n";
  17. }
  18. }
  19. code += "\n";
  20.  
  21. // TRANSFORM
  22. code += " vec4 positionW = modelMatrix * vec4(vertex_position, 1.0);\n";
  23. code += " gl_Position = matrix_viewProjection * positionW;\n\n";
  24. if (lighting) {
  25. code += " vec3 normalW = normalMatrix * vertex_normal;\n";
  26. code += " normalW = normalize(normalW);\n";
  27. if (options.normalMap && useTangents) {
  28. code += " vec3 tangentW = normalMatrix * vertex_tangent.xyz;\n";
  29. code += " tangentW = normalize(tangentW);\n";
  30. }
  31. }
  32. code += "\n";
  33.  
  34. // LIGHTING
  35. if (lighting) {
  36. if (options.normalMap && useTangents) {
  37. // Calculate the tangent space basis vectors
  38. code += " vec3 binormalW = cross(normalW, tangentW) * vertex_tangent.w;\n";
  39. code += " mat3 tbnMatrix = mat3(tangentW.x, binormalW.x, normalW.x,\n";
  40. code += " tangentW.y, binormalW.y, normalW.y,\n";
  41. code += " tangentW.z, binormalW.z, normalW.z);\n";
  42. code += " vViewDirW = tbnMatrix * (view_position - positionW.xyz);\n";
  43.  
  44. for (i = 0; i < totalLights; i++) {
  45. if (i < totalDirs) {
  46. code += " vLight" + i + "DirW = -(tbnMatrix * light" + i + "_direction);\n";
  47. }
  48. if (i >= totalDirs) {
  49. code += " vLight" + i + "DirW = tbnMatrix * (light" + i + "_position - positionW.xyz);\n";
  50. }
  51. if (i >= totalDirs + totalPnts) {
  52. code += " vLight" + i + "SpotDirW = tbnMatrix * light" + i + "_spotDirection;\n";
  53. }
  54. }
  55. } else {
  56. code += " vNormalW = normalW;\n";
  57. code += " vViewDirW = view_position - positionW.xyz;\n";
  58.  
  59. for (i = 0; i < totalLights; i++) {
  60. if (i < totalDirs) {
  61. code += " vLight" + i + "DirW = -light" + i + "_direction;\n";
  62. }
  63. if (i >= totalDirs) {
  64. code += " vLight" + i + "DirW = light" + i + "_position - positionW.xyz;\n";
  65. }
  66. if (i >= totalDirs + totalPnts) {
  67. code += " vLight" + i + "SpotDirW = light" + i + "_spotDirection;\n";
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement