three实现变色粒子在容器中碰撞动画效果代码

代码语言:html

所属分类:粒子

代码描述:three实现变色粒子在容器中碰撞动画效果代码

代码标签: three 粒子 碰撞 变色

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

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

<head>

 
<meta charset="UTF-8">

 
<meta name="viewport" content="width=device-width, initial-scale=1">
 
 
 
<style>
@import url("https://fonts.googleapis.com/css?family=Inconsolata:400,400i,700");
* {
 
margin: 0;
 
padding: 0;
}

html
,
body
{
 
overflow: hidden;
 
font-family: Inconsolata, sans-serif;
 
color: #eee;
}
h1
{
 
position: relative;
 
z-index: 1;
 
padding: 1rem;
 
font-weight: 400;
 
font-size: 1rem;
}
.webgl {
 
position: fixed;
 
top: 0;
 
left: 0;
 
outline: none;
}
</style>



</head>

<body  >
 
<canvas class="webgl"></canvas>


<script type="x-shader/x-vertex" id="vertexShader">
  uniform mat4 projectionMatrix
;
uniform mat4 viewMatrix
;
uniform mat4 modelMatrix
;
attribute vec3 position
;
attribute vec2 uv
;
varying vec2 vUv
;

void main()
{
    vec4 pos
=vec4(position,1.);
    vec4 modelPosition
=modelMatrix*vec4(position,1.);
    vec4 viewPosition
=viewMatrix*modelPosition;
    vec4 projectedPosition
=projectionMatrix*viewPosition;
    vUv
=uv;
    gl_Position
=projectedPosition;
}
</script>

<script type="x-shader/x-fragment" id="fragmentShader">
  precision mediump float;

uniform float u_time;
varying vec2 vUv;

#define PI 3.141592653589
#define TWO_PI 6.28318530718

float rand(float x) { return fract(sin(x * 1.14529) * 43758.5453123); }

vec3 light_point(vec2 xy, vec2 center, vec3 color, float strength, float threshold) {
  vec3 clr = vec3(0.0);
  float l = length(xy - center);
  clr += (strength / l) * smoothstep(0.0, threshold, strength / l);
  return clr * color;
}

vec3 hsl2rgb(vec3 c) {
  vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.........完整代码请登录后点击上方下载按钮下载查看

网友评论0