html5水墨效果,html5 canvas水墨风格的云雾动画特效

这篇博客介绍了如何使用HTML5 Canvas创建水墨风格的云雾动画特效。通过GLSL纹理噪声函数,配合Perlin噪声算法,实现云雾的细腻变化。代码包括经典Perlin噪声的计算以及平滑处理,最终应用于3D动画中,营造出逼真的水墨云雾效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

特效描述:html5 canvas水墨风格 云雾动画特效。html5 canvas云雾动画、水墨云雾特效

代码结构

1. 引入JS

2. HTML代码

//

// GLSL textureless classic 3D noise "cnoise",

// with an RSL-style periodic variant "pnoise".

// Author: Stefan Gustavson ([email protected])

// Version: 2011-10-11

//

// Many thanks to Ian McEwan of Ashima Arts for the

// ideas for permutation and gradient selection.

//

// Copyright (c) 2011 Stefan Gustavson. 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;

}

vec3 fade(vec3 t) {

return t*t*t*(t*(t*6.0-15.0)+10.0);

}

// Classic Perlin noise

float cnoise(vec3 P)

{

vec3 Pi0 = floor(P); // Integer part for indexing

vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1

Pi0 = mod289(Pi0);

Pi1 = mod289(Pi1);

vec3 Pf0 = fract(P); // Fractional part for interpolation

vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0

vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);

vec4 iy = vec4(Pi0.yy, Pi1.yy);

vec4 iz0 = Pi0.zzzz;

vec4 iz1 = Pi1.zzzz;

vec4 ixy = permute(permute(ix) + iy);

vec4 ixy0 = permute(ixy + iz0);

vec4 ixy1 = permute(ixy + iz1);

vec4 gx0 = ixy0 * (1.0 / 7.0);

vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;

gx0 = fract(gx0);

vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);

vec4 sz0 = step(gz0, vec4(0.0));

gx0 -= sz0 * (step(0.0, gx0) - 0.5);

gy0 -= sz0 * (step(0.0, gy0) - 0.5);

vec4 gx1 = ixy1 * (1.0 / 7.0);

vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;

gx1 = fract(gx1);

vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);

vec4 sz1 = step(gz1, vec4(0.0));

gx1 -= sz1 * (step(0.0, gx1) - 0.5);

gy1 -= sz1 * (step(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值