kgl实现的玻璃体流体发散动画效果

代码语言:html

所属分类:粒子

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>Instancing Box &amp; Curl Noise</title>
    <style>
        html,
        body {
            height: 100%;
        }
        body {
            overflow: hidden;
            margin: 0;
        }
        canvas {
            width: 100%;
            height: 100%;
        }
    </style>

</head>
<body translate="no">
    <script type="x-shader/x-fragment" id="reset-velocity">
        precision highp float;

        void main () {
            gl_FragColor = vec4(vec3(0.), 1.);
        }
    </script>
    <script type="x-shader/x-fragment" id="reset-position">
        precision highp float;

        uniform vec2 size;

        // https://github.com/mattdesl/glsl-random
        highp float random(vec2 co) {
            highp float a = 12.9898;
            highp float b = 78.233;
            highp float c = 43758.5453;
            highp float dt = dot(co.xy, vec2(a, b));
            highp float sn = mod(dt, 3.14);
            return fract(sin(sn) * c);
        }

        void main () {
            vec2 nPosition = gl_FragCoord.st / size * 2. - 1.;
            vec4 position = vec4(
                nPosition * size,
                0.,
                random(nPosition)
            );
            gl_FragColor = position;
        }
    </script>
    <script type="x-shader/x-fragment" id="velocity">
        precision highp float;

        uniform vec2 size;
        uniform sampler2D prevVelocityTexture;
        uniform sampler2D prevPositionTexture;

        //
        // Description : Array and textureless GLSL 2D/3D/4D simplex
        //               noise functions.
        //      Author : Ian McEwan, Ashima Arts.
        //  Maintainer : ijm
        //     Lastmod : 20110822 (ijm)
        //     License : Copyright (C) 2011 Ashima Arts. All rights reserved.
        //               Distributed under the MIT License. See LICENSE file.
        //               https://github.com/ashima/webgl-noise
        //

        vec3 mod289(vec3 x) {
            return x - floor(x * (1.0 / 289.0)) * 289.0;
        }

        vec4 mod289(vec4 x) {
            return x - floor(x * (1.0 / 289.0)) * 289.0;
        }

        vec4 permute(vec4 x) {
            return mod289(((x*34.0)+1.0)*x);
        }

        vec4 taylorInvSqrt(vec4 r) {
            return 1.79284291400159 - 0.85373472095314 * r;
        }

        float snoise(vec3 v) {
            const vec2  C = vec2(1.0/6.0, 1.0/3.0);
            const vec4  D = vec4(0.0, 0.5, 1.0, 2.0);

            // First corner
            vec3 i = floor(v + dot(v, C.yyy));
            vec3 x0 = v - i + dot(i, C.xxx);

            // Other corners
            vec3 g = step(x0.yzx, x0.xyz);
            vec3 l = 1.0 - g;
            vec3 i1 = min(g.xyz, l.zxy);
            vec3 i2 = max(g.xyz, l.zxy);

            //   x0 = x0 - 0.0 + 0.0 * C.xxx;
            //   x1 = x0 - i1  + 1.0 * C.xxx.........完整代码请登录后点击上方下载按钮下载查看

网友评论0