LitSolid.vert 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include "Uniforms.vert"
  2. #include "Transform.vert"
  3. #include "ScreenPos.vert"
  4. #include "Lighting.vert"
  5. varying vec2 vTexCoord;
  6. #ifdef HEIGHTFOG
  7. varying vec3 vWorldPos;
  8. #endif
  9. #ifdef PERPIXEL
  10. varying vec4 vLightVec;
  11. #ifdef SPECULAR
  12. varying vec3 vEyeVec;
  13. #endif
  14. #ifndef NORMALMAP
  15. varying vec3 vNormal;
  16. #endif
  17. #ifdef SHADOW
  18. varying vec4 vShadowPos[NUMCASCADES];
  19. #endif
  20. #ifdef SPOTLIGHT
  21. varying vec4 vSpotPos;
  22. #endif
  23. #ifdef POINTLIGHT
  24. varying vec3 vCubeMaskVec;
  25. #endif
  26. #else
  27. varying vec4 vVertexLight;
  28. varying vec3 vNormal;
  29. #ifdef NORMALMAP
  30. varying vec3 vTangent;
  31. varying vec3 vBitangent;
  32. #endif
  33. varying vec4 vScreenPos;
  34. #ifdef ENVCUBEMAP
  35. varying vec3 vReflectionVec;
  36. #endif
  37. #if defined(LIGHTMAP) || defined(AO)
  38. varying vec2 vTexCoord2;
  39. #endif
  40. #endif
  41. void main()
  42. {
  43. mat4 modelMatrix = iModelMatrix;
  44. vec3 worldPos = GetWorldPos(modelMatrix);
  45. gl_Position = GetClipPos(worldPos);
  46. vTexCoord = GetTexCoord(iTexCoord);
  47. #ifdef HEIGHTFOG
  48. vWorldPos = worldPos;
  49. #endif
  50. #if defined(PERPIXEL) && defined(NORMALMAP)
  51. vec3 vNormal;
  52. vec3 vTangent;
  53. vec3 vBitangent;
  54. #endif
  55. vNormal = GetWorldNormal(modelMatrix);
  56. #ifdef NORMALMAP
  57. vTangent = GetWorldTangent(modelMatrix);
  58. vBitangent = cross(vTangent, vNormal) * iTangent.w;
  59. #endif
  60. #ifdef PERPIXEL
  61. // Per-pixel forward lighting
  62. vec4 projWorldPos = vec4(worldPos, 1.0);
  63. #ifdef SHADOW
  64. // Shadow projection: transform from world space to shadow space
  65. for (int i = 0; i < NUMCASCADES; i++)
  66. vShadowPos[i] = GetShadowPos(i, projWorldPos);
  67. #endif
  68. #ifdef SPOTLIGHT
  69. // Spotlight projection: transform from world space to projector texture coordinates
  70. vSpotPos = cLightMatrices[0] * projWorldPos;
  71. #endif
  72. #ifdef POINTLIGHT
  73. vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * (cLightPos.xyz - worldPos);
  74. #endif
  75. #ifdef NORMALMAP
  76. mat3 tbn = mat3(vTangent, vBitangent, vNormal);
  77. #ifdef DIRLIGHT
  78. vLightVec = vec4(cLightDir * tbn, GetDepth(gl_Position));
  79. #else
  80. vLightVec = vec4((cLightPos.xyz - worldPos) * tbn * cLightPos.w, GetDepth(gl_Position));
  81. #endif
  82. #ifdef SPECULAR
  83. vEyeVec = (cCameraPos - worldPos) * tbn;
  84. #endif
  85. #else
  86. #ifdef DIRLIGHT
  87. vLightVec = vec4(cLightDir, GetDepth(gl_Position));
  88. #else
  89. vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
  90. #endif
  91. #ifdef SPECULAR
  92. vEyeVec = cCameraPos - worldPos;
  93. #endif
  94. #endif
  95. #else
  96. // Ambient & per-vertex lighting
  97. #if defined(LIGHTMAP) || defined(AO)
  98. // If using lightmap, disregard zone ambient light
  99. // If using AO, calculate ambient in the PS
  100. vVertexLight = vec4(0.0, 0.0, 0.0, GetDepth(gl_Position));
  101. vTexCoord2 = iTexCoord2;
  102. #else
  103. vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
  104. #endif
  105. #ifdef NUMVERTEXLIGHTS
  106. for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
  107. vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
  108. #endif
  109. vScreenPos = GetScreenPos(gl_Position);
  110. #ifdef ENVCUBEMAP
  111. vReflectionVec = worldPos - cCameraPos;
  112. #endif
  113. #endif
  114. }