three实现三维破碎空间后处理特效效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维破碎空间后处理特效效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <script type="importmap"> { "imports": { "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/158/three.module.js", "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/158/jsm/" } } </script> <style> body{ overflow: hidden; margin: 0; } </style> </head> <body translate="no"> <script type="module"> import * as THREE from "three"; import { OrbitControls } from "three/addons/controls/OrbitControls.js"; import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js"; import { RenderPass } from "three/addons/postprocessing/RenderPass.js"; import { ShaderPass } from "three/addons/postprocessing/ShaderPass.js"; import { SepiaShader } from "three/addons/shaders/SepiaShader.js"; import { GammaCorrectionShader } from "three/addons/shaders/GammaCorrectionShader.js"; console.clear(); // load fonts await (async function () { async function loadFont(fontface) { await fontface.load(); document.fonts.add(fontface); } let fonts = [ new FontFace( "Michroma", "url(https://fonts.gstatic.com/s/michroma/v19/PN_zRfy9qWD8fEagAPg9pTk.woff2)" ) ]; for (let font in fonts) { //console.log(fonts[font]); await loadFont(fonts[font]); } })(); const ShaderShatter = { name: "ShatterShader", uniforms: { tDiffuse: { value: null }, time: { value: 0.0 }, aspect: { value: 1 }, signature: { value: (function(){ let c = document.createElement("canvas"); c.width = 1024; c.height = 128; let $ = c.getContext("2d"); $.clearRect(0, 0, c.width, c.height); $.font = `bold ${c.height * 0.7}px Michroma`; $.textAlign = "center"; $.textBaseline = "middle"; $.fillStyle = "#fff"; $.fillText("849 # Shattered", c.width * 0.5, c.height * 0.5); let cTex = new THREE.CanvasTexture(c); cTex.colorSpace = THREE.SRGBColorSpace; return cTex; }())} }, vertexShader: ` varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }`, fragmentShader: ` #include <common> uniform float time; uniform sampler2D tDiffuse; uniform sampler2D signature; uniform float aspect; varying vec2 vUv; vec2 N22(vec2 p){ vec3 a = fract(p.xyx * vec3(123.45, 234.56, 345.67)); a += dot(a, a+45.69); return fract(vec2(a.x * a.y, a.y * a.z)); } void main() { float t = time * PI; vec2 uv = (vUv - 0.5) * vec2(aspect, 1.) * 2.; float mult = 5.; uv *= mult; // Voronoi - https://www.youtube.com/watch?v=l-07BXzNdPw - Martijn Steinrucken vec2 gv = fract(uv) - 0.5; vec2 id = floor(uv); vec2 cId = vec2(0); float minDist = 100.; for(float y = -1.; y <= 1.; y++){ for(float x = -1.; x <= 1.; x++){ vec2 offset = vec2(x, y); vec2 n = N22(id + offset); vec2 snt = sin(n * t); vec2 p = offset + snt * 0.4; float d = distance(gv, p); if (d < minDist ) { minDist = d; cId = id + offset; } } } ///////// float sfBase = smoothstep(0.5, 1., length((cId + 0.5) / mult)); float sf = sfBase; //sf *= sf; sf = 0.05 + 0.95 * sf; vec2 randDir = N22(cId); randDir = length(randDir) == 0. ? randDir : normalize(randDir); randDir *= (1. / (mult * 4.)) * sf; vec2 baseUv = vUv * (1. - 0.05 * sfBase).........完整代码请登录后点击上方下载按钮下载查看
网友评论0