webgl实现多彩烟雾流动动画效果代码
代码语言:html
所属分类:粒子
代码描述:webgl实现多彩烟雾流动动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/dat.gui-min.js"></script> <style> @font-face { font-family: 'iconfont'; src: url('iconfont.ttf') format('truetype'); } * { user-select: none; } html, body { overflow: hidden; background-color: #000; } body { margin: 0; position: fixed; width: 100%; height: 100%; } canvas { width: 100%; height: 100%; } .dg { opacity: 0.9; } .dg .property-name { overflow: visible; } .bigFont { font-size: 150%; color: #8C8C8C; } .cr.function.appBigFont { font-size: 150%; line-height: 27px; color: #A5F8D3; background-color: #023C40; } .cr.function.appBigFont .property-name { float: none; } .cr.function.appBigFont .icon { position: sticky; bottom: 27px; } .icon { font-family: 'iconfont'; font-size: 130%; float: right; } .twitter:before { content: 'a'; } .github:before { content: 'b'; } .app:before { content: 'c'; } .discord:before { content: 'd'; } .promo { display: none; /* display: table; */ position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; overflow: auto; color: lightblue; background-color: rgba(0,0,0,0.4); animation: promo-appear-animation 0.35s ease-out; } .promo-middle { display: table-cell; vertical-align: middle; } .promo-content { width: 80vw; height: 80vh; max-width: 80vh; max-height: 80vw; margin: auto; padding: 0; font-size: 2.8vmax; font-family: Futura, "Trebuchet MS", Arial, sans-serif; text-align: center; background-image: url("promo_back.png"); background-position: center; background-repeat: no-repeat; background-size: cover; border-radius: 15px; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19); } .promo-header { height: 10%; padding: 2px 16px; } .promo-close { width: 10%; height: 100%; text-align: left; float: left; font-size: 1.3em; /* transition: 0.2s; */ } .promo-close:hover { /* transform: scale(1.25); */ cursor: pointer; } .promo-body { padding: 8px 16px 16px 16px; margin: auto; } .promo-body p { margin-top: 0; mix-blend-mode: color-dodge; } .link { width: 100%; display: inline-block; } .link img { width: 100%; } @keyframes promo-appear-animation { 0% { transform: scale(2.0); opacity: 0; } 100% { transform: scale(1.0); opacity: 1; } } </style> <script> window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; </script> </head> <body> <canvas></canvas> <!-- Mother of God, pls forgive me --> <div class="promo"> <div class="promo-middle"> <div class="promo-content"> <div class="promo-header"> <span class="promo-close">×</span> </div> <div class="promo-body"> <p>Try Fluid Simulation app!</p> <div class="links-container"> <a class="link" id="apple_link" target="_blank"> <img class="link-img" alt="Download on the App Store" src="app_badge.png"/> </a> <a class="link" id="google_link" target="_blank"> <img class="link-img" alt="Get it on Google Play" src="gp_badge.png"/> </a> </div> </div> </div> </div> </div> <script> /* MIT License Copyright (c) 2017 Pavel Dobryakov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 'use strict'; // Mobile promo section // Simulation section const canvas = document.getElementsByTagName('canvas')[0]; resizeCanvas(); let config = { SIM_RESOLUTION: 128, DYE_RESOLUTION: 1024, CAPTURE_RESOLUTION: 512, DENSITY_DISSIPATION: 1, VELOCITY_DISSIPATION: 0.2, PRESSURE: 0.8, PRESSURE_ITERATIONS: 20, CURL: 30, SPLAT_RADIUS: 0.25, SPLAT_FORCE: 6000, SHADING: true, COLORFUL: true, COLOR_UPDATE_SPEED: 10, PAUSED: false, BACK_COLOR: { r: 0, g: 0, b: 0 }, TRANSPARENT: false, BLOOM: true, BLOOM_ITERATIONS: 8, BLOOM_RESOLUTION: 256, BLOOM_INTENSITY: 0.8, BLOOM_THRESHOLD: 0.6, BLOOM_SOFT_KNEE: 0.7, SUNRAYS: true, SUNRAYS_RESOLUTION: 196, SUNRAYS_WEIGHT: 1.0, } function pointerPrototype () { this.id = -1; this.texcoordX = 0; this.texcoordY = 0; this.prevTexcoordX = 0; this.prevTexcoordY = 0; this.deltaX = 0; this.deltaY = 0; this.down = false; this.moved = false; this.color = [30, 0, 300]; } let pointers = []; let splatStack = []; pointers.push(new pointerPrototype()); const { gl, ext } = getWebGLContext(canvas); if (isMobile()) { config.DYE_RESOLUTION = 512; } if (!ext.supportLinearFiltering) { config.DYE_RESOLUTION = 512; config.SHADING = false; config.BLOOM = false; config.SUNRAYS = false; } startGUI(); function getWebGLContext (canvas) { const params = { alpha: true, depth: false, stencil: false, antialias: false, preserveDrawingBuffer: false }; let gl = canvas.getContext('webgl2', params); const isWebGL2 = !!gl; if (!isWebGL2) gl = canvas.getContext('webgl', params) || canvas.getContext('experimental-webgl', params); let halfFloat; let supportLinearFiltering; if (isWebGL2) { gl.getExtension('EXT_color_buffer_float'); supportLinearFiltering = gl.getExtension('OES_texture_float_linear'); } else { halfFloat = gl.getExtension('OES_texture_half_float'); supportLinearFiltering = gl.getExtension('OES_texture_half_float_linear'); } gl.clearColor(0.0, 0.0, 0.0, 1.0); const halfFloatTexType = isWebGL2 ? gl.HALF_FLOAT : halfFloat.HALF_FLOAT_OES; let formatRGBA; let formatRG; let formatR; if (isWebGL2) { formatRGBA = getSupportedFormat(gl, gl.RGBA16F, gl.RGBA, halfFloatTexType); formatRG = getSupportedFormat(gl, gl.RG16F, gl.RG, halfFloatTexType); formatR = getSupportedFormat(gl, gl..........完整代码请登录后点击上方下载按钮下载查看
网友评论0