LitParticle.vert 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "Uniforms.vert"
  2. #include "Transform.vert"
  3. varying vec2 vTexCoord;
  4. #ifdef VERTEXCOLOR
  5. varying vec4 vColor;
  6. #endif
  7. varying vec4 vLightVec;
  8. #ifdef SPOTLIGHT
  9. varying vec4 vSpotPos;
  10. #endif
  11. #ifdef POINTLIGHT
  12. varying vec3 vCubeMaskVec;
  13. #endif
  14. void main()
  15. {
  16. mat4 modelMatrix = iModelMatrix;
  17. vec3 worldPos = GetWorldPos(modelMatrix);
  18. gl_Position = GetClipPos(worldPos);
  19. vTexCoord = GetTexCoord(iTexCoord);
  20. #ifdef VERTEXCOLOR
  21. vColor = iColor;
  22. #endif
  23. vec4 projWorldPos = vec4(worldPos, 1.0);
  24. #ifdef DIRLIGHT
  25. vLightVec = vec4(cLightDir, GetDepth(gl_Position));
  26. #else
  27. vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
  28. #endif
  29. #ifdef SPOTLIGHT
  30. // Spotlight projection: transform from world space to projector texture coordinates
  31. vSpotPos = cLightMatrices[0] * projWorldPos;
  32. #endif
  33. #ifdef POINTLIGHT
  34. vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec.xyz;
  35. #endif
  36. }