shader.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. export const vertexShader = `
  2. attribute float randam;
  3. attribute float sprite;
  4. attribute float centerHeight; //add
  5. //uniform float fireHeight; //add
  6. uniform float time;
  7. uniform float size;
  8. uniform float heightOfNearPlane;
  9. //varying float heightRatio;
  10. varying float vSprite;
  11. varying float vOpacity;
  12. float PI = 3.14;
  13. float quadraticIn( float t )
  14. {
  15. float tt = t * t;
  16. return tt * tt;
  17. //变化曲线 越来越快
  18. }
  19. void main() {
  20. float progress = fract( time + ( 2.0 * randam - 1.0 ) );
  21. float progressNeg = 1.0 - progress;
  22. float ease = quadraticIn( progress );
  23. float influence = sin( PI * ease );
  24. //vec3 newPosition = position * vec3( 1.0, 1.0 , ease);
  25. vec3 newPosition = position;
  26. newPosition.z = (newPosition.z - centerHeight) * ease + centerHeight;
  27. gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );
  28. gl_PointSize = ( heightOfNearPlane * size ) / gl_Position.w;
  29. vOpacity = min( influence * 4.0, 1.0 ) * progressNeg;
  30. vSprite = sprite;
  31. //heightRatio = (newPosition.z - centerHeight) / fireHeight ;
  32. }
  33. `
  34. export const fragmentShader = `
  35. uniform vec3 color;
  36. uniform sampler2D u_sampler;
  37. varying float vSprite;
  38. varying float vOpacity;
  39. //varying float heightRatio;
  40. void main()
  41. {
  42. vec2 texCoord = vec2(gl_PointCoord.x * 0.25 + vSprite, gl_PointCoord.y);
  43. gl_FragColor = vec4( texture2D( u_sampler, texCoord ).xyz * color * vOpacity, 1.0 );
  44. }
  45. `