Skip to content

Instantly share code, notes, and snippets.

@DefinitelyMaybe
Created June 17, 2024 00:46
Show Gist options
  • Save DefinitelyMaybe/144e5f754c1b29df6e7d90b40b0cdfa1 to your computer and use it in GitHub Desktop.
Save DefinitelyMaybe/144e5f754c1b29df6e7d90b40b0cdfa1 to your computer and use it in GitHub Desktop.
donut to monkey point cloud
const material = new SpriteNodeMaterial({ transparent: true, depthWrite: false, blending: THREE.AdditiveBlending})
// Mixed position
const getMixed Position = tslFn(([origin, target]) =>
{
// Noises
const noiseOrigin = simplexNoise3d(vec3(origin.mul(noiseScaleUniform)))
const noiseTarget = simplexNoise3d(vec3(target.mul<noiseScaleUniform)))
const noise = mix(noiseOrigin, noiseTarget, progressUniform).smoothstep(-1, 1)
// Transition
const duration = transitionRatioUniform
const delay = duration.oneMinus).mul(noise)
const end = delay.add(duration)
const progress = smoothstep(delay, end, progressUniform)
// Color varying
const colorVarying = varying(vec3(), 'colorVarying').assign(mix(colorOriginUniform, colorTargetUniform, noise))
// Output
return mix(origin, target, progress)
})
material.positionNode = getMixed Position(particles.buffers[0], particles.buffers[1])
// Scale
material.scaleNode = scalesAttribute.mul(scaleUniform)
// Color
material.colorNode = tslFn(() => {
const colorVarying = varying(vec3(), 'colorVarying')
const alpha = float(0.05).div(uv().sub(0.5).length()).sub(0.1)
return vec4(colorVarying, alpha)
})()
// Methods
const morph = (index) => {
// Update attributes
material.positionNode = getMixed Position(particles.buffers[particles.index], particles.buffers[index])
material.needsUpdate = true
// Animate uProgress
gsap.fromTo(
progressUniform,
{ value: 0 },
{ value: 1, duration: 3, ease: 'linear' }
)
// Save index
particles.index = index
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment