webgl实现燃烧的火圈鼠标悬浮点击交互动画效果代码
代码语言:html
所属分类:动画
代码描述:webgl实现燃烧的火圈鼠标悬浮点击交互动画效果代码,鼠标悬浮和点击会出现炫酷的动画效果。
代码标签: webgl 燃烧 火圈 鼠标 悬浮 点击 交互 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
body, html {
margin: 0;
padding: 0;
}
.page {
background: radial-gradient(#ACB6E5, #74ebd5);
font-family: sans-serif;
color: #eeeeee;
}
canvas#ring_shape-canvas {
display: block;
z-index: 2;
}
.title {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 2vh;
text-align: center;
z-index: 2;
}
.control {
position: absolute;
top: 0;
right: 0;
padding: 10px;
display: flex;
align-items: center;
font-size: .9em;
opacity: .8;
}
</style>
</head>
<body>
<!-- partial:index.partial.html -->
<div class="page">
<div class="title">
<div>hover & click</div>
</div>
<canvas id="ring_shape-canvas"></canvas>
<div class="control">
<label for="transparency-switch">shader transparency</label>
<input type="checkbox" id="transparency-switch">
</div>
</div>
<script type="x-shader/x-fragment" id="vertShader">
precision mediump float;
varying vec2 vUv;
attribute vec2 a_position;
void main() {
vUv = .5 * (a_position + 1.);
gl_Position = vec4(a_position, 0.0, 1.0);
}
</script>
<script type="x-shader/x-fragment" id="fragShader">
precision mediump float;
varying vec2 vUv;
uniform float u_time;
uniform float u_ratio;
uniform float u_click_time;
uniform vec2 u_pointer;
uniform vec2 u_click;
uniform float u_transparency;
#define TWO_PI 6.28318530718
#define PI 3.14159265358979323846
// ------------------------------------------------
// Generic fractional Brownian motion (fBm) noise
float rand(vec2 n) {
return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float noise(vec2 n) {
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}
float fbm(vec2 n) {
float total = 0.0, amplitude = .4;
for (int i = 0; i < 4; i++) {
total += noise(n) * amplitude;
n += n;
amplitude *= 0.6;
}
return total;
}
// ------------------------------------------------
float get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {
float distance = length(uv);
float line_width = outerRadius - innerRadius;
float ringValue = smoothstep(innerRadius, innerRadius + line_width, distance);
ringValue -= smoothstep(outerRadius, outerRadius + line_width, distance);
return clamp(ringValue, 0., 1.);
}
float get_dot_shape(vec2 uv, vec2 center, float pwr) {
float mouse_center_dist = length(center);
float pointer_shape = 1. - length(uv - center);
pointer_shape = clamp(pointer_shape, 0., 1.);
pointer_shape = pow(pointer_shape, pwr);
pointer_shape *= .18;
return pointer_shape;
}
float get_sym_impulse(float v, float pwr) {
return 1. - pow(1. - pow(2. * v - 1., 4.), pwr);
}
// ------------------------------------------------
void main() {
vec2 uv = vUv * 2. - 1.;
uv.x *= u_ratio;
float noise_scale = 6.;
// overall speed
float t = .0003 * u_time;
float t_click = .001 * u_click_time;
// timing
float expl_duration = 3.5;
float t_click_explosion = (1. - step(expl_duration, t_click)) * t_click;
t_click_explosion = .........完整代码请登录后点击上方下载按钮下载查看
网友评论0