BLACK FRIDAY
50% off
Want to learn more?

That's the end of the free part of this lesson

WebGPU & TSL Course new $45 VAT incl.
  • 21 lessons 路 24 hours of video
  • Quizzes 路 Certificate
  • Members-only Discord server 路 Future updates
00:00/00:00
3:22
00:03:22

Shortcuts 鈱笍

  • SPACE to play / pause
  • ARROW RIGHT or L to go forward
  • ARROW LEFT or J to go backward
  • ARROW UP to increase volume
  • ARROW DOWN to decrease volume
  • F to toggle fullscreen
  • M to toggle mute
  • 0 to 9 to go to the corresponding part of the video
  • SHIFT + , to decrease playback speed
  • SHIFT + . or ; to increase playback speed

鈿狅笍 Update

Since version 0.187.0 of Three.js, mx_worley_noise_float returns the real (Euclidean) distance, which is the square root of the old value.

To get the old result back, we need to square the new one with pow(2):

const worleyNoise = mx_worley_noise_float(vec3(worleyUv, time)).pow(2)

鈿狅笍 Update

Again, since version 0.187.0 of Three.js, mx_worley_noise_float returns the real (Euclidean) distance, which is the square root of the old value, and that's why the pattern looks different.

Keep following, we will fix it right after.

鈿狅笍 Update

Instead, use a power of 6 to fix the compensate the output of mx_worley_noise_float mentioned earlier:

const causticsNoise = mx_worley_noise_float(causticsInput).pow(6)

鈿狅笍 Update

Again, since version 0.187.0 of Three.js, mx_worley_noise_float returns the real (Euclidean) distance, which is the square root of the old value.

To get the old result back, we need to square the new one with pow(2):

const causticsNoise = mx_worley_noise_float(causticsInput).pow(2)

鈿狅笍 Update

Since the version 0.187.0 of Three.js, mx_worley_noise_float was updated, and the disks don't have the same size like in the video.

No need to apply the following trick.

Unlock content 馃敁

To get access to 93 hours of video, a members-only Discord server, subtitles, lesson resources, future updates and much more join us for only $95 $47.50!

Want to learn more? 馃枛

23%

That's the end of the free part of this lesson

WebGPU & TSL Course new $45 VAT incl.
  • 21 lessons 路 24 hours of video
  • Quizzes 路 Certificate
  • Members-only Discord server 路 Future updates
Next lesson
WebGPU & TSL
Chapter 02 路 Advanced Projects

09. Patterns

Difficulty: Medium01:03:39

Introduction 00:00

In the previous lessons, we discovered TSL and its many features. So many that you probably forgot most of them already. We need to practice them, bit by bit, which is why we鈥檒l redo some of the Shaders lesson in a familiar environment.

Let鈥檚 start with the Shader Patterns. Most of the patterns are simple; we can focus on fragments only (don鈥檛 worry, more vertex manipulation in the upcoming lessons), and we鈥檒l discover some tricks and make mistakes along the way.

Don鈥檛 worry, we鈥檙e not going to do all the patterns.

Like in the original lesson, if you鈥檙e looking for a challenge, try to do the patterns on your own. And remember that there are always many solutions. Some solutions can be more clever, some more performant, some make more sense, and some are more maintainable. As long as you practice, you鈥檙e in the right direction.

Setup 01:14

The starter already contains the following:

  • The plane on which we are going to draw the pattern
  • OrbitControls to rotate around
  • A floor to have a little bit of scenery
  • Running the WebGPURenderer with the Inspector

Pattern 1 01:39

Let鈥檚 start with the first pattern.

What you see is the UV coordinates of the plane, and it will be the main input of every upcoming pattern. But the first question is, how do we display this UV on the plane?

The material is an instance of MeshBasicNodeMaterial, meaning that we can already assign nodes.

We went for the Basic instead of a shaded material such as Phong, Lambert, or Standard to focus on the pattern without it being affected by light or shadow.

To output the pattern, we use the colorNode which expects a vec3() node:

// Pattern 1
material.colorNode = vec3()

Since we didn鈥檛 provide any argument to the vec3(), it used the default values which are 0 for the x, y and z (more like r, g and b since we use it as a color).

鈽濓笍

x, y, z, w, and r, g, b, a are interchangeable when it comes to TSL vectors.

Let鈥檚 try with some values.

material.colorNode = vec3(1, 0.5, 0.2)

It鈥檚 working, but now we want the UV gradient, which we can get from the uv() node as the first argument of vec3() and 1 as the last argument:

material.colorNode = vec3(uv().x, uv().y, 1)

This is a valid solution, but there is a shorter version. When sending a vector as an argument to a bigger vector, it鈥檒l take the respective properties in the order it was provided.

This means that we don鈥檛 have to explicitly provide the x and the y separately:

material.colorNode = vec3(uv(), 1)

Pattern 2 04:11

Here鈥檚 another easy one.

To create this linear gradient, we can use the x coordinate of uv() only, but on all 3 values of the vec3() so that we get a grayscale gradient:

// Pattern 2
material.colorNode = vec3(uv().x, uv().x, uv().x)

鈽濓笍

You can leave previous patterns without commenting them. Since we re-assign material.colorNode, they will be overridden.

And again, there is a shorter version. If we provide one value to a vector, this single value will be used as all properties of the vector:

material.colorNode = vec3(uv().x)

Pattern 3 05:13

Let鈥檚 try something harder.

Want to learn more?

That's the end of the free part of this lesson

WebGPU & TSL Course new $45 VAT incl.
  • 21 lessons 路 24 hours of video
  • Quizzes 路 Certificate
  • Members-only Discord server 路 Future updates

How to use it 馃

  • Download the Starter pack or Final project
  • Unzip it
  • Open your terminal and go to the unzip folder
  • Run npm install to install dependencies
    (if your terminal warns you about vulnerabilities, ignore it)
  • Run npm run dev to launch the local server
    (project should open on your default browser automatically)
  • Start coding
  • The JS is located in src/script.js
  • The HTML is located in src/index.html
  • The CSS is located in src/style.css

If you get stuck and need help, join the members-only Discord server:

Discord