Heim > Web-Frontend > H5-Tutorial > Multiperspektivische 3D-realistische HTML5-Wasserwellenanimation _html5-Tutorial-Fähigkeiten

Multiperspektivische 3D-realistische HTML5-Wasserwellenanimation _html5-Tutorial-Fähigkeiten

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-05-16 15:45:38
Original
2135 Leute haben es durchsucht

Dies ist ein 3D-Wasserwellen-Spezialeffekt, der auf HTML5 basiert. Sein Effekt ist sehr realistisch. Wir können die „G“-Taste drücken, um die Steine ​​im Pool auf und ab zu schweben, und die „L“-Taste drücken Lichteffekte hinzufügen. Das Design ist ziemlich perfekt. Bitte beachten Sie gleichzeitig, dass diese 3D-Wasserwellenanimation auf der WebGL-Rendering-Technologie basiert. Sie können mehr über WebGL erfahren.

Online-Vorschau Quellcode-Download

HTML-Code

XML/HTML-CodeInhalt in die Zwischenablage kopieren
  1. <img id="tiles" src="tiles.jpg">
  2. <img id="xneg" src="xneg.jpg">
  3. <img id="xpos" src="xpos.jpg">
  4. <img id="ypos" src="ypos.jpg">
  5. <img id="zneg" src="zneg.jpg">
  6. <img id="zpos" src="zpos.jpg">

JavaScript-Code

JavaScript-CodeInhalt in die Zwischenablage kopieren
  1. Funktion Water() {   
  2.   var vertexShader = '  
  3.     variierende vec2 koord;  
  4.     void main() {  
  5.       coord = gl_Vertex.xy * 0.5   0.5;  
  6.       gl_Position = vec4(gl_Vertex.xyz, 1.0);  
  7.     }  
  8.   ';   
  9.   this.plane = GL.Mesh.plane();   
  10.   if (!GL.Texture.canUseFloatingPointTextures()) {   
  11.     throw neu Fehler('Für diese Demo ist die Erweiterung OES_texture_float erforderlich');   
  12.   }   
  13.   var filter = GL.Texture.canUseFloatingPointLinearFiltering() ? gl.LINEAR : gl.NEAREST;   
  14.   this.textureA = new GL.Texture(256, 256, { type: gl.FLOAT, Filter: Filter});   
  15.   this.textureB = new GL.Texture(256, 256, { type: gl.FLOAT, Filter: Filter });   
  16.   this.dropShader = new GL.Shader(vertexShader, '  
  17.     const float PI = 3.141592653589793;  
  18.     einheitliche Sampler2D-Textur;  
  19.     einheitliches vec2 center;  
  20.     einheitlicher Schwimmradius;  
  21.     gleichmäßige Schwimmstärke;  
  22.     variierende vec2 koord;  
  23.     void main() {  
  24.       /* Scheitelpunktinformationen abrufen */  
  25.       vec4 info = texture2D(texture, coord);  
  26.         
  27.       /* füge den Abfall zur Höhe hinzu */  
  28.       float drop = max(0.0, 1.0 - length(center * 0.5   0.5 - coord) / radius);  
  29.       drop = 0,5 - cos(drop * PI) * 0,5;  
  30.       info.r  = drop * strength;  
  31.         
  32.       gl_FragColor = info;  
  33.     } 
  34.   ');   
  35.   this.updateShader = new GL.Shader(vertexShader, '  
  36.     einheitliche Sampler2D-Textur;  
  37.     uniformes vec2 delta;  
  38.     variierende vec2 koord;  
  39.     void main() {  
  40.       /* Scheitelpunktinformationen abrufen */  
  41.       vec4 info = texture2D(texture, coord);  
  42.         
  43.       /* durchschnittliche Nachbarngröße berechnen */  
  44.       vec2 dx = vec2(delta.x, 0.0);  
  45.       vec2 dy = vec2(0.0, delta.y);  
  46.       Float-Durchschnitt = (  
  47.         texture2D(texture, coord - dx).r   
  48.         texture2D(texture, coord - dy).r   
  49.         texture2D(texture, coord   dx).r   
  50.         texture2D(texture, coord   dy).r  
  51.       ) * 0,25;  
  52.         
  53.       /* Ändere die Geschwindigkeit, um sich in Richtung des Durchschnitts zu bewegen.*/  
  54.       info.g  = (average - info.r) * 2.0;  
  55.         
  56.       /* Dämpft die Geschwindigkeit ein wenig, damit Wellen nicht ewig dauern.*/  
  57.       info.g *= 0,995;  
  58.         
  59.       /* verschieben den Scheitelpunkt entlang der Geschwindigkeit */  
  60.       info.r  = info.g;  
  61.         
  62.       gl_FragColor = info;  
  63.     } 
  64.   ');   
  65.   this.normalShader = new GL.Shader(vertexShader, '  
  66.     einheitliche Sampler2D-Textur;  
  67.     uniformes vec2 delta;  
  68.     variierende vec2 koord;  
  69.     void main() {  
  70.       /* Scheitelpunktinformationen abrufen */  
  71.       vec4 info = texture2D(texture, coord);  
  72.         
  73.       /* aktualisiere das normale */  
  74.       vec3 dx = vec3(delta.x, texture2D(texture, vec2(coord.x   delta.x, coord.y)).r - info.r, 0.0);  
  75.       vec3 dy = vec3(0.0, texture2D(texture, vec2(coord.x, coord.y   delta.y)).r - info.r, delta.y);  
  76.       info.ba = normalize(cross(dy, dx)).xz;  
  77.         
  78.       gl_FragColor = info;  
  79.     }  
  80.   ');   
  81.   this.sphereShader = new GL.Shader(vertexShader, '  
  82.     einheitliche Sampler2D-Textur;  
  83.     uniform vec3 oldCenter;  
  84.     uniform vec3 newCenter;  
  85.     einheitlicher Schwimmradius;  
  86.     variierende vec2 koord;  
  87.       
  88.     float volumeInSphere(vec3 center) {  
  89.       vec3 toCenter = vec3(coord.x * 2.0 - 1.0, 0.0, coord.y * 2.0 - 1.0) - center;  
  90.       float t = length(toCenter) / radius;  
  91.       float dy = exp(-pow(t * 1.5, 6.0));  
  92.       float ymin = min(0.0, center.y - dy);  
  93.       float ymax = min(max(0.0, center.y   dy), ymin   2.0 * dy);  
  94.       return (ymax - ymin) * 0,1;  
  95.     } 
  96.       
  97.     void main() {  
  98.       /* Scheitelpunktinformationen abrufen */  
  99.       vec4 info = texture2D(texture, coord);  
  100.         
  101.       /* alte Volume hinzufügen */  
  102.       info.r  = volumeInSphere(oldCenter);  
  103.         
  104.       /* subtrahiere das neue Volumen */  
  105.       info.r -= volumeInSphere(newCenter);  
  106.         
  107.       gl_FragColor = info;  
  108.     }  
  109.   ');   
  110. }   
  111.   
  112. Water.prototype.addDrop = Funktion(x, y, Radius, Stärke) {   
  113.   var this_ = this;   
  114.   dieses.textureB.drawTo(function() {   
  115.     this_.textureA.bind();   
  116.     this_.dropShader.uniforms({   
  117.       Mitte: [x, y],   
  118.       Radius: Radius,   
  119.       Stärke: Stärke   
  120.     }).draw(this_.plane);   
  121.   });   
  122.   this.textureB.swapWith(this.textureA);   
  123. };   
  124.   
  125. Water.prototype.moveSphere = Funktion(oldCenter, newCenter, radius) {   
  126.   var this_ = this;   
  127.   this.textureB.drawTo(function() {   
  128.     this_.textureA.bind();   
  129.     this_.sphereShader.uniforms({   
  130.       oldCenter: oldCenter,   
  131.       newCenter: newCenter,   
  132.       Radius: Radius   
  133.     }).draw(this_.plane);   
  134.   });   
  135.   this.textureB.swapWith(this.textureA);   
  136. };   
  137.   
  138. Water.prototype.stepSimulation = function() {   
  139.   var this_ = this;   
  140.   this.textureB.drawTo(function() {   
  141.     this_.textureA.bind();   
  142.     this_.updateShader.uniforms({   
  143.       delta: [1 / this_.textureA.width, 1 / this_.textureA.height]   
  144.     }).draw(this_.plane);   
  145.   });   
  146.   this.textureB.swapWith(this.textureA);   
  147. };   
  148.   
  149. Water.prototype.updateNormals = function() {   
  150.   var this_ = this;   
  151.   this.textureB.drawTo(function() {   
  152.     this_.textureA.bind();   
  153.     this_.normalShader.uniforms({   
  154.       delta: [1 / this_.textureA.width, 1 / this_.textureA.height]   
  155.     }).draw(this_.plane);   
  156.   });   
  157.   this.textureB.swapWith(this.textureA);   
  158. };   

以上就是本文的全部内容,希望对大家的学习有所帮助.

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
HTML5-Validierung für Symfony 2.1
Aus 1970-01-01 08:00:00
0
0
0
Der Unterschied zwischen HTML und HTML5
Aus 1970-01-01 08:00:00
0
0
0
html5 anzeigen ausblenden
Aus 1970-01-01 08:00:00
0
0
0
HTML5-Formularvalidierung
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage