Three.js-shader有趣的动画效果、模拟粒子骨骼动画
const uniforms = {
uSize: { value: 100 },
uSpace: { value: 0.5 },
}
mesh.material.onBeforeCompile = (shader) => {
// console.log(shader.vertexShader)
// console.log(shader.fragmentShader)
Object.assign(shader.uniforms, uniforms)
shader.vertexShader = shader.vertexShader.replace('#include ' ,
`
#include
varying vec2 vUv;
`
)
shader.vertexShader = shader.vertexShader.replace('#include ' ,
`
#include
vUv = uv;
`
)
shader.fragmentShader = shader.fragmentShader.replace('#include ' ,
`
#include
varying vec2 vUv;
uniform float uSize;
uniform float uSpace;
`
)
shader.fragmentShader = shader.fragmentShader.replace('#include ' ,
`
#include
float sx =float(fract(uSize * vUv.x) > uSpace);
float sy =float(fract(uSize * vUv.y) > uSpace);
if(sx*sy == 0.0) discard;
`
)
};