多视角3D逼真HTML5水波动画

2020-04-24 18:56:57易采站长站整理

    void main() {  
      /* get vertex info */  
      vec4 info = texture2D(texture, coord);  
        
      /* add the drop to the height */  
      float drop = max(0.0, 1.0 – length(center * 0.5 + 0.5 – coord) / radius);  
      drop = 0.5 – cos(drop * PI) * 0.5;  
      info.r += drop * strength;  
        
      gl_FragColor = info;  
    }  
  ‘);   
  this.updateShader = new GL.Shader(vertexShader, ‘  
    uniform sampler2D texture;  
    uniform vec2 delta;  
    varying vec2 coord;  
    void main() {  
      /* get vertex info */  
      vec4 info = texture2D(texture, coord);  
        
      /* calculate average neighbor height */  
      vec2 dx = vec2(delta.x, 0.0);  
      vec2 dy = vec2(0.0, delta.y);  
      float average = (  
        texture2D(texture, coord – dx).r +  
        texture2D(texture, coord – dy).r +  
        texture2D(texture, coord + dx).r +  
        texture2D(texture, coord + dy).r  
      ) * 0.25;  
        
      /* change the velocity to move toward the average */  
      info.g += (average – info.r) * 2.0;  
        
      /* attenuate the velocity a little so waves do not last forever */