webgl实现粒子宇宙效果代码

代码语言:html

所属分类:粒子

代码描述:webgl实现粒子宇宙效果代码

代码标签: 宇宙 效果

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

<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">

  
  
  
<style>
html,body {
  background-color: black;
  text-align: center;
}
</style>



</head>

<body >
  <canvas id="display"></canvas>

<!-- vshader is where the magic happens !-->
<script id="vshader" type="gles/vshader">
precision mediump float;

attribute vec2 Vertex;
uniform float Time;

varying vec4 Color;

float voronoi(in vec2 uv) {
    vec2 lp = abs(uv)*10.;
    vec2 sp = fract(lp)-.5;
    lp = floor(lp);
    
    float d = 1.;
    
    for (int x = -1; x < 2; x++) {
        for (int y = -1; y < 2; y++) {
            
            vec2 mp = vec2(float(x),float(y));
            vec2 p = lp+mp;
            
            d = min(d,length(sp+((cos(p.x)+cos(p.y))*5.)*.3-mp));
            
        }
    }
    
    return d;
}

void main() {
gl_PointSize = 1.;

   vec2 v = Vertex;
   
   float ang = atan(v.y,v.x);
   float len = length(v);

   v = v*mod(Time+len,1.)+vec2(sin(ang+voronoi(v.yx)),cos(ang+voronoi(v.xy)))*.3;
  v = v*.75 + v*.25*mat2(sin(ang+cos(Vertex.y*23.435+Time)),cos(ang+cos(Vertex.x*23.234)),-cos(ang),sin(ang));


   Color = mix(vec4(0.2,0.4,1.,(cos(ang)*.3+.........完整代码请登录后点击上方下载按钮下载查看

网友评论0