Three.js Animation with K-d (Christmas) Tree Algorithm

In this festive ALL YOUR HTML coding session we’ll decompile the animation seen on the website of ONE-OFF using the K-d tree algorithm and Three.js shape creation. We’ll also be using GLSL to create the visuals.

This coding session was streamed live on December 26, 2021.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Three.js Animation with K-d (Christmas) Tree Algorithm appeared first on Codrops.

Pixelated Distortion Effect with Three.js

In this ALL YOUR HTML stream and coding session we’ll be recreating the interactive pixel distortion effect seen on the website for the music video covers of “Infinite Bad Guy” made as an AI Experiment at Google and YouTube. We’ll be using Three.js and datatexture to achieve the look.

This coding session was streamed live on December 12, 2021.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Pixelated Distortion Effect with Three.js appeared first on Codrops.

Teleportation Transition with Three.js

In this ALL YOUR HTML stream and coding session we’ll be creating a teleportation-like transition with Three.js using some quaternions, and fragment shaders! The original effect comes from Marseille 2021 by La Phase 5.

This coding session was streamed live on December 5, 2021.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Teleportation Transition with Three.js appeared first on Codrops.

Animated 3D Ribbons with Three.js

In this ALL YOUR HTML stream and coding session we will recreate the interesting looking 3D ribbon effect seen on the website of iad-lab and made by mutoco.ch. We’ll apply some geometrical tricks and use the Three.js API.

This coding session was streamed live on November 28, 2021.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Animated 3D Ribbons with Three.js appeared first on Codrops.

Ripple Effect on a Texture with Three.js

In this ALL YOUR HTML coding session you will learn how to recreate the interesting ripple effect seen on the homunculus.jp website with Three.js. We’ll have a look at render targets and use a little bit of math.

This coding session was streamed live on November 21, 2021.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Ripple Effect on a Texture with Three.js appeared first on Codrops.

Replicating the Particles Animation from DNA Capital with Three.js

In this ALL YOUR HTML coding session you will learn how to recreate the beautiful particles animation from the website of DNA Capital using Three.js. The website was made by Immersive Garden.

This coding session was streamed live on October 17, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Replicating the Particles Animation from DNA Capital with Three.js appeared first on Codrops.

Deconstructing the homunculus.jp Distortion with Three.js

In this ALL YOUR HTML coding session we will be deconstructing the pixel river distortion seen on homunculus.jp with Three.js, and also trying out Theatre.js.

This coding session was streamed live on October 3, 2021.

Check out the live demo.

Try to change values and animate them; use the icon on the top left corner of the website.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Deconstructing the homunculus.jp Distortion with Three.js appeared first on Codrops.

Curly Tubes from the Lusion Website with Three.js

In this ALL YOUR HTML coding session we’re going to look at recreating the curly noise tubes with light scattering from the fantastic website of Lusion using Three.js.

This coding session was streamed live on May 16, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Curly Tubes from the Lusion Website with Three.js appeared first on Codrops.

Noisy Strokes Texture with Three.js and GLSL

In this ALL YOUR HTML coding session you’ll learn how to recreate the amazing noisy strokes texture seen on the website of Leonard, the inventive agency, using Three.js with GLSL. The wonderful effect was originally made by Damien Mortini.

This coding session was streamed live on May 9, 2021.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Noisy Strokes Texture with Three.js and GLSL appeared first on Codrops.

Texture Ripples and Video Zoom Effect with Three.js and GLSL

In this ALL YOUR HTML coding session we’ll be replicating the ripples and video zoom effect from The Avener by TOOSOON studio using Three.js and GLSL coding.

This coding session was streamed live on April 25, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Texture Ripples and Video Zoom Effect with Three.js and GLSL appeared first on Codrops.

Wobbly 2D Physics with Matter.js and Paper.js

In this ALL YOUR HTML coding session you’ll learn how to recreate the effect seen on Cédric Pereira’s website, developed by Serge Wsevolojsky. We’ll get into some cool wobbly 2D physics using Matter.js with lots of help from the Paper.js library.

This coding session was streamed live on April 11, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Wobbly 2D Physics with Matter.js and Paper.js appeared first on Codrops.

Tropical Particles Rain Animation with Three.js

People always want more. More of everything. And there is nothing better in the world to fulfil that need than particle systems. Because you can have thousands of particles easily. And that’s what I did for this demo.

Creating a particle system

You start with just one particle. I like to use classes for that, because that perfectly describes the behaviour of particles. It usually it looks like this:

class Particle{
	// just setting initial position and speed
	constructor(){}
	// updating velocity according to position and physics
	updateVelocity(){}
	// finally update particle position, 
	// sometimes these last two could be merged
	updatePosition(){}
}

And after all of that, you could render them. Sounds easy, right? It is!

Physics

So the particles need to move. For that we need to establish some rules for their movement. The easiest one is: gravity. Implemented in the particle it would look like this:

updateVelocity(){
	this.speed.y = gravity; // some constant
}

updatePosition{
	// this could have been just one line, but imagine there are some other factors for speed, not just gravity.
	this.position.y += this.speed.y;

	// also some code to bring particle back to screen, once it is outside
}

With that you will get this simple rain. I also randomized gravity for each particle. Why? Because I can!

But just rain didn’t seem enough, and I decided to add a little bit of physics to change the speed of the particles. To slow them down or speed them up, depending on the… image. Yup, I took the physics for the particles from the image. My friend @EncharmDre proposed to use some oscillations for the particles, and I also added some colors palettes here. It looked amazing! Like a real tropical rain.

Still, the physics part is the computational bottleneck for this animation. It is possible to animate millions of particles by using GPGPU techniques, and the GPU to calculate the positions. But 10000 particles seemed enough for my demo, and I got away with CPU calculations this time. 10s of thousands also were possible because I saved some performance on rendering.

Rendering

There are a lot of ways to render particles: HTML, Canvas2D, WebGL, SVG, you name it. But so far the fastest one is of course WebGL. It is even faster than Canvas2D rendering. I mean, of course Canvas2D works perfectly fine for particles. But with WebGL you could have MORE OF THEM! Which is the point of this whole adventure =).

So, WebGL narrowed down the search for rendering to a couple of frameworks. PIXI.js is actually very nice for rendering 2D particle systems, but because I love three.js, and because its always nice to have another dimension as a backup (the more dimensions the better, remember?), I chose three.js for this job.

There is already an object specifically for this job: THREE.Points. I also decided to use shaders (because it’s cool) but you could actually easily avoid that for this demo.

The simplified code looks somewhat like this:

// initialization
for (let i = 0; i < numberOfParticles; i++) {
  // because we are animating them in 2D, z=0
  positions.set([x, y, 0], i * 3);
  this.particles.push(
    new Particle({
      x,
      y
    })
  );
}
geometry.setAttribute(
  "position",
  new THREE.BufferAttribute(positions, 3)
);

// animation loop
particles.forEach(particle => {
  particle.updateSpeedAndPosition();
});

To make it even cooler, I decided to create trails for the particles. For that I just used the previous rendering frame, and faded it a little bit. And here is what I got:

Now combining everything, we could achieve this final look:

Final words

I beg you to try this yourself, and experiment with different parameters for particles, or write your own logic for their behavior. It is a lot of fun. And you could be the ruler of thousands or even millions of… particles!

GitHub link coming soon!

The post Tropical Particles Rain Animation with Three.js appeared first on Codrops.

Rotating Loading Animation of 3D Shapes with Three.js

All things we see around are 3D shapes. Some of them are nice looking, some of them you’d like to touch and squeeze. But because it’s still quarantine time, and I don’t have many things around, I decided to create some virtual things to twist around. 🙂 Here’s what I ended up with:

How to do that?

To render everything I used Three.js, just like Mario Carillo in his amazing demo, go check it out! Three.js is the best and most popular library to do things with WebGL at the moment. And if you are just starting your 3D path, it is definitely the easiest way to get something working.

If you just rotate the shape, its nothing special, its just rotating.

Interesting things start to happen when you rotate different parts of the shape with different speeds. Let’s say I want the bottom part of the object to rotate first, and than the rest, let’s see whats going to happen.

To do something like that, you would need to use a Vertex shader. I used a little bit of math and rotated parts of the object depending on the Y or Z coordinate. The simplified code looks like this:

vec3 newposition = rotate(oldPosition, angle*Y_COORDINATE);

So with a coordinate change, the rotation would change as well. The rotate function itself includes a lot of Sine-Cosine’s and matrices. All the math you need to rotate a point around some axis. To give it a more natural feel, I also change the easing function, so it looks like elastic rubber.

Visuals, MatCap

To create a nice look for objects, we could have used lights and shadows and complicated materials. But because there’s not so much in the scene, we got away with the most simple kind of material: MatCaps. So instead of making complicated calculations, you just use a simple image to reference the lighting and color. Here is how it looks like:

And here is how the torus shape looks like with this texture applied to it:

Amazing, isn’t it? And so simple.

So combining Matcaps and a rotation method, we can create a lot of cool shape animations that look great, and have this rubber feeling.

Go and create your shape with this technique and make sure to share it with us! Hope this simple technique will inspire you to create your own animation! Have a good day!

The post Rotating Loading Animation of 3D Shapes with Three.js appeared first on Codrops.

How to Code the Travelling Particles Animation from “Volt for Drive”

In this ALL YOUR HTML coding session you’ll learn how to recreate Volt for Drive’s glowing particles that endlessly travel through city streets. The website was made by the team of Red Collar. We’ll use Three.js and some shader magic to implement the animation.

This coding session was streamed live on January 31, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post How to Code the Travelling Particles Animation from “Volt for Drive” appeared first on Codrops.

Recreating Frontier Development Lab’s Sun in Three.js

In this ALL YOUR HTML coding session you’ll learn how to recreate the sun from Frontier Development Lab’s Sun Challenge, using numerous shaders, lots of layers of noise and CubeCamera.

This coding session was streamed live on January 24, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Recreating Frontier Development Lab’s Sun in Three.js appeared first on Codrops.