particles.vertex.js 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Do not edit.
  2. import { ShaderStore } from "../Engines/shaderStore.js";
  3. import "./ShadersInclude/clipPlaneVertexDeclaration.js";
  4. import "./ShadersInclude/fogVertexDeclaration.js";
  5. import "./ShadersInclude/logDepthDeclaration.js";
  6. import "./ShadersInclude/clipPlaneVertex.js";
  7. import "./ShadersInclude/fogVertex.js";
  8. import "./ShadersInclude/logDepthVertex.js";
  9. const name = "particlesVertexShader";
  10. const shader = `attribute vec3 position;attribute vec4 color;attribute float angle;attribute vec2 size;
  11. #ifdef ANIMATESHEET
  12. attribute float cellIndex;
  13. #endif
  14. #ifndef BILLBOARD
  15. attribute vec3 direction;
  16. #endif
  17. #ifdef BILLBOARDSTRETCHED
  18. attribute vec3 direction;
  19. #endif
  20. #ifdef RAMPGRADIENT
  21. attribute vec4 remapData;
  22. #endif
  23. attribute vec2 offset;uniform mat4 view;uniform mat4 projection;uniform vec2 translationPivot;
  24. #ifdef ANIMATESHEET
  25. uniform vec3 particlesInfos;
  26. #endif
  27. varying vec2 vUV;varying vec4 vColor;varying vec3 vPositionW;
  28. #ifdef RAMPGRADIENT
  29. varying vec4 remapRanges;
  30. #endif
  31. #if defined(BILLBOARD) && !defined(BILLBOARDY) && !defined(BILLBOARDSTRETCHED)
  32. uniform mat4 invView;
  33. #endif
  34. #include<clipPlaneVertexDeclaration>
  35. #include<fogVertexDeclaration>
  36. #include<logDepthDeclaration>
  37. #ifdef BILLBOARD
  38. uniform vec3 eyePosition;
  39. #endif
  40. vec3 rotate(vec3 yaxis,vec3 rotatedCorner) {vec3 xaxis=normalize(cross(vec3(0.,1.0,0.),yaxis));vec3 zaxis=normalize(cross(yaxis,xaxis));vec3 row0=vec3(xaxis.x,xaxis.y,xaxis.z);vec3 row1=vec3(yaxis.x,yaxis.y,yaxis.z);vec3 row2=vec3(zaxis.x,zaxis.y,zaxis.z);mat3 rotMatrix= mat3(row0,row1,row2);vec3 alignedCorner=rotMatrix*rotatedCorner;return position+alignedCorner;}
  41. #ifdef BILLBOARDSTRETCHED
  42. vec3 rotateAlign(vec3 toCamera,vec3 rotatedCorner) {vec3 normalizedToCamera=normalize(toCamera);vec3 normalizedCrossDirToCamera=normalize(cross(normalize(direction),normalizedToCamera));vec3 row0=vec3(normalizedCrossDirToCamera.x,normalizedCrossDirToCamera.y,normalizedCrossDirToCamera.z);vec3 row2=vec3(normalizedToCamera.x,normalizedToCamera.y,normalizedToCamera.z);
  43. #ifdef BILLBOARDSTRETCHED_LOCAL
  44. vec3 row1=direction;
  45. #else
  46. vec3 crossProduct=normalize(cross(normalizedToCamera,normalizedCrossDirToCamera));vec3 row1=vec3(crossProduct.x,crossProduct.y,crossProduct.z);
  47. #endif
  48. mat3 rotMatrix= mat3(row0,row1,row2);vec3 alignedCorner=rotMatrix*rotatedCorner;return position+alignedCorner;}
  49. #endif
  50. #define CUSTOM_VERTEX_DEFINITIONS
  51. void main(void) {
  52. #define CUSTOM_VERTEX_MAIN_BEGIN
  53. vec2 cornerPos;cornerPos=(vec2(offset.x-0.5,offset.y -0.5)-translationPivot)*size;
  54. #ifdef BILLBOARD
  55. vec3 rotatedCorner;
  56. #ifdef BILLBOARDY
  57. rotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.y=0.;rotatedCorner.xz+=translationPivot;vec3 yaxis=position-eyePosition;yaxis.y=0.;vPositionW=rotate(normalize(yaxis),rotatedCorner);vec3 viewPos=(view*vec4(vPositionW,1.0)).xyz;
  58. #elif defined(BILLBOARDSTRETCHED)
  59. rotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.z=0.;rotatedCorner.xy+=translationPivot;vec3 toCamera=position-eyePosition;vPositionW=rotateAlign(toCamera,rotatedCorner);vec3 viewPos=(view*vec4(vPositionW,1.0)).xyz;
  60. #else
  61. rotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.y=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.z=0.;rotatedCorner.xy+=translationPivot;vec3 viewPos=(view*vec4(position,1.0)).xyz+rotatedCorner;vPositionW=(invView*vec4(viewPos,1)).xyz;
  62. #endif
  63. #ifdef RAMPGRADIENT
  64. remapRanges=remapData;
  65. #endif
  66. gl_Position=projection*vec4(viewPos,1.0);
  67. #else
  68. vec3 rotatedCorner;rotatedCorner.x=cornerPos.x*cos(angle)-cornerPos.y*sin(angle);rotatedCorner.z=cornerPos.x*sin(angle)+cornerPos.y*cos(angle);rotatedCorner.y=0.;rotatedCorner.xz+=translationPivot;vec3 yaxis=normalize(direction);vPositionW=rotate(yaxis,rotatedCorner);gl_Position=projection*view*vec4(vPositionW,1.0);
  69. #endif
  70. vColor=color;
  71. #ifdef ANIMATESHEET
  72. float rowOffset=floor(cellIndex*particlesInfos.z);float columnOffset=cellIndex-rowOffset/particlesInfos.z;vec2 uvScale=particlesInfos.xy;vec2 uvOffset=vec2(offset.x ,1.0-offset.y);vUV=(uvOffset+vec2(columnOffset,rowOffset))*uvScale;
  73. #else
  74. vUV=offset;
  75. #endif
  76. #if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6) || defined(FOG)
  77. vec4 worldPos=vec4(vPositionW,1.0);
  78. #endif
  79. #include<clipPlaneVertex>
  80. #include<fogVertex>
  81. #include<logDepthVertex>
  82. #define CUSTOM_VERTEX_MAIN_END
  83. }`;
  84. // Sideeffect
  85. ShaderStore.ShadersStore[name] = shader;
  86. /** @internal */
  87. export const particlesVertexShader = { name, shader };
  88. //# sourceMappingURL=particles.vertex.js.map