Loading

Paste #pfhnuneca

  1. #version 330
  2.  
  3. layout (location = 0) in vec3 VertexPosition;
  4. layout (location = 1) in vec3 VertexVelocity;
  5. layout (location = 2) in float VertexStartTime;
  6. layout (location = 3) in vec3 VertexInitialVelocity;
  7.  
  8. out vec3 Position;   // To transform feedback
  9. out vec3 Velocity;   // To transform feedback
  10. out float StartTime; // To transform feedback
  11. out float Transp;    // To fragment shader
  12.  
  13. uniform float Time;  // Simulation time
  14. uniform float H;     // Elapsed time between frames
  15. uniform vec3 Accel;  // Particle acceleration
  16. uniform float ParticleLifetime;  // Particle lifespan
  17. uniform float MinParticleSize = 10.0;
  18. uniform float MaxParticleSize = 200.0;
  19.  
  20. uniform int passType;
  21.  
  22. uniform mat4 MVP;
  23.  
  24. void update() {
  25.  
  26.     // Update position & velocity for next frame
  27.     Position = VertexPosition;
  28.     Velocity = VertexVelocity;
  29.     StartTime = VertexStartTime;
  30.  
  31.     if( Time >= StartTime ) {
  32.  
  33.         float age = Time - StartTime;
  34.  
  35.         if( age > ParticleLifetime ) {
  36.             // The particle is past it's lifetime, recycle.
  37.             Position = vec3(0.0);
  38.             Velocity = VertexInitialVelocity;
  39.             StartTime = Time;
  40.         } else {
  41.             // The particle is alive, update.
  42.             Position += Velocity * H;
  43.             Velocity += Accel * H;
  44.         }
  45.     }
  46. }
  47.  
  48. void render() {
  49.     float age = Time - VertexStartTime;
  50.     Transp = 0.0;
  51.     if( Time >= VertexStartTime ) {
  52.         float agePct = age/ParticleLifetime;
  53.         Transp = 1.0 - agePct;
  54.         gl_PointSize = mix(MinParticleSize,MaxParticleSize,agePct);
  55.     }
  56.     gl_Position = MVP * vec4(VertexPosition, 1.0);
  57. }
  58.  
  59. void main()
  60. {
  61.     if (passType == 0) {
  62.         update();
  63.     } else {
  64.         render();
  65.     }
  66. }
  67.  
  68. //////////////////////////////
  69.  
  70.  
  71.  
  72. #version 330
  73.  
  74. uniform sampler2D ParticleTex;
  75.  
  76. in float Transp;
  77.  
  78. layout ( location = 0 ) out vec4 FragColor;
  79.  
  80. void main()
  81. {
  82.     FragColor = texture(ParticleTex, gl_PointCoord);
  83.     FragColor.a *= Transp;
  84. }
  85.  

Comments