LitParticle.vert 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "Uniforms.vert"
  2. #include "Transform.vert"
  3. #include "Lighting.vert"
  4. varying vec2 vTexCoord;
  5. #ifdef HEIGHTFOG
  6. varying vec3 vWorldPos;
  7. #endif
  8. #ifdef VERTEXCOLOR
  9. varying vec4 vColor;
  10. #endif
  11. #ifdef PERPIXEL
  12. varying vec4 vLightVec;
  13. #ifdef SPOTLIGHT
  14. varying vec4 vSpotPos;
  15. #endif
  16. #ifdef POINTLIGHT
  17. varying vec3 vCubeMaskVec;
  18. #endif
  19. #else
  20. varying vec4 vVertexLight;
  21. #endif
  22. void main()
  23. {
  24. mat4 modelMatrix = iModelMatrix;
  25. vec3 worldPos = GetWorldPos(modelMatrix);
  26. gl_Position = GetClipPos(worldPos);
  27. vTexCoord = GetTexCoord(iTexCoord);
  28. #ifdef HEIGHTFOG
  29. vWorldPos = worldPos;
  30. #endif
  31. #ifdef VERTEXCOLOR
  32. vColor = iColor;
  33. #endif
  34. #ifdef PERPIXEL
  35. // Per-pixel forward lighting
  36. vec4 projWorldPos = vec4(worldPos, 1.0);
  37. #ifdef DIRLIGHT
  38. vLightVec = vec4(cLightDir, GetDepth(gl_Position));
  39. #else
  40. vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
  41. #endif
  42. #ifdef SPOTLIGHT
  43. // Spotlight projection: transform from world space to projector texture coordinates
  44. vSpotPos = cLightMatrices[0] * projWorldPos;
  45. #endif
  46. #ifdef POINTLIGHT
  47. vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec.xyz;
  48. #endif
  49. #else
  50. // Ambient & per-vertex lighting
  51. vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
  52. #ifdef NUMVERTEXLIGHTS
  53. for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
  54. vVertexLight.rgb += GetVertexLightVolumetric(i, worldPos) * cVertexLights[i * 3].rgb;
  55. #endif
  56. #endif
  57. }