Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • Backend vs Frontend: What Runs Where, and Why the Server Is the One You Trust
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • Running a Next.js Admin Starter Kit: Route Groups, Theme Tokens and npm run dev
  • Remotion Basics: A Video as One Composition Object, Frames, Sequences and the Player
  • Spline: Put a 3D Scene on a Landing Page Without Writing 3D Code
  • Framer: A Launch Page Without Code, From a Free Animated Template
  • Three.js: What It Can Do on Real Sites, and How to Let Your AI Agent Use It
  • Animated Component Libraries (Magic UI, Aceternity UI): Copy-In Motion and When It Becomes Noise
  • WebGPU and Three.js Shaders in TSL: A Living Gradient, 4,500 Particles and a Hover Ripple
  • Deploy Many Vite Demos as One Static Site: A Gallery Page, One Build Command and import.meta.env.BASE_URL
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Finishing a Remotion Video Editor: Timeline Sync, Track Order, Trims and Fades, and the Server MP4 Render
  • A 3D Product Page in React and Three.js: Scroll Becomes a Number, One Camera Shot per Panel, One Choice Drives Everything
  • A Personal 3D Portfolio Room in React Three Fiber: Hover Glow, Click to Open, Pointer Drift and a Contact Form to FastAPI
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  • Supabase as a Backend: Postgres, Instant APIs, Row Level Security and the Two Keys
  • Email Login With Supabase in Next.js: Three Clients, Server Actions, the Callback Route and Middleware
  • Google Sign-In With Supabase in Next.js: Which Address Goes Where
  • hCaptcha on a Supabase Login Page: Site Key in the Browser, Secret in Supabase
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

WebGPU and Three.js Shaders in TSL: A Living Gradient, 4,500 Particles and a Hover Ripple

A shader is a stamp pressed on every pixel at once. Write it once in TSL, hand it to WebGPURenderer, and it runs on WebGPU or quietly on WebGL2. Read three effects from the sample project and the four habits that keep them light.

Chaand Sheikh

·27 November 2026·Updated 29 November 2026Fundamentals

What you will learn

  • Explain a shader as a tiny program run once per pixel, in parallel on the GPU
  • Start a WebGPURenderer that falls back to WebGL2 and report which backend you got
  • Read three TSL effects: a sin-warped gradient, instanced particles with per-dot easing, and a hover ripple with a colour split
  • Keep shaders kind to the device: DPR cap, pause off screen, freeze for reduced motion

Before you start

  • JavaScript basics
  • Three.js: what it can do on real sites

This lesson is about effects that run on the graphics card: a living gradient, particles that follow the mouse, and a ripple when you hover an image, plus a fallback for browsers without WebGPU. We cover the foundations only. AI can generate shaders for you; you need to know what each one does so the code makes sense when your app grows.

What a shader is

Think of your screen as a floor of tiles. Each tile is one pixel, and a full HD screen has about two million of them. Now imagine a stamp. The stamp is the shader: a tiny program that runs once for every tile. You give it the tile's position, x and y, and it gives back a colour. Press it on every tile and the picture appears. The graphics card has thousands of small workers, so it stamps all the tiles at the same time. That's why shaders are fast.

Write once: WebGPU first, WebGL2 fallback

You write the shader in TSL, Three Shading Language, which looks like normal JavaScript. You hand it to the WebGPU renderer, and it picks the best backend for the browser: WebGPU where it's supported (the lecture names Chrome, Edge and Safari), otherwise it quietly falls back to WebGL2 and the same shader still works.

  const renderer = new WebGPURenderer({ antialias: true, alpha: true })
  renderer.setClearColor(0x000000, 0)
  await renderer.init()
  // ...
  onBackend?.((renderer.backend as { isWebGPUBackend?: boolean }).isWebGPUBackend ? 'WebGPU' : 'WebGL2')

Create the renderer, await init(), and one more line tells you which backend you got. In the project, a small badge in the corner shows it.

One shader, two backends TSL shader written once WebGPURenderer await init() WebGPU navigator.gpu exists WebGL2 fallback same shader still works
You don't write two versions; the renderer picks the backend.

Effect 1: a living gradient

The page background keeps moving. The shader is one function, the colour node, in effects/gradient.ts. Trimmed to its core:

  material.colorNode = Fn(() => {
    // centred, aspect-corrected coordinates
    const p = uv().sub(0.5).mul(vec2(uAspect, 1)).mul(1.8).toVar()
    // ... the pointer pushes the pattern away from itself ...

    // domain warp: sin() of the coordinates, fed back into the coordinates, twice
    const t = uTime.mul(0.1)
    p.addAssign(vec2(sin(p.y.mul(2.1).add(t)), sin(p.x.mul(1.7).sub(t.mul(1.3)))).mul(0.5))
    p.addAssign(vec2(sin(p.y.mul(3.3).sub(t.mul(0.8))), sin(p.x.mul(2.9).add(t))).mul(0.25))

    // two flowing 0..1 "noise" fields
    const n1 = sin(p.x.mul(2.0).add(sin(p.y.mul(2.5).add(t.mul(2))))).mul(0.5).add(0.5)
    const n2 = sin(p.y.mul(3.0).add(sin(p.x.mul(2.0).sub(t.mul(1.5))))).mul(0.5).add(0.5)

    // palette: ink -> violet -> magenta, with a rare warm highlight
    const ink = color('#07061a')
    const violet = color('#4a2bd0')
    const magenta = color('#e0409a')
    const amber = color('#ff9a5a')
    const c = mix(ink, violet, smoothstep(0.15, 0.85, n1)).toVar()
    c.assign(mix(c, magenta, smoothstep(0.55, 1.0, n2).mul(0.6)))
    c.addAssign(amber.mul(pow(n1.mul(n2), 7).mul(0.7)))
    // ... vignette, then return the colour
  })()

Position in: take this pixel's position and centre it. sin bends the position so the pattern waves, and t, the time, keeps it moving. mix picks a colour between ink and violet (then magenta, with a touch of amber), and that's returned. Position in, sin to bend it, mix to pick a colour out.

Effect 2: particles that follow the mouse

Move the pointer left, then right, and a cloud of dots follows. In effects/particles.ts, COUNT is 4500, drawn with an InstancedMesh: one draw call for all of them. Each dot's soft glow is smoothstep on the length from its centre. The following part is plain JavaScript run every frame:

      const k = dt * 60
      for (let i = 0; i < COUNT; i++) {
        const a = phase[i] + time * spin[i]
        const r = radius[i] * scale * (0.7 + 0.3 * Math.sin(time * 0.7 + phase[i]))
        const gx = tx + Math.cos(a) * r
        const gy = ty + Math.sin(a) * r * 0.75
        const e = Math.min(ease[i] * k, 1)
        px[i] += (gx - px[i]) * e
        py[i] += (gy - py[i]) * e
      }

Each dot has its own ease, a lazy speed between 0.01 and 0.06. Every frame it moves that fraction of the way toward its goal near the pointer. Different speeds stretch the cloud into a trail. One draw call, every dot at its own pace.

Effect 3: a hover distortion

With the pointer away, the picture is calm. Put the pointer on the moon in the image, and rings spread out. From effects/hoverImage.ts:

    const ripple = sin(dist.mul(34).sub(uTime.mul(4))) // outward travelling wave
    const warp = dir.mul(ripple).mul(fall).mul(0.018).sub(d.div(squash).mul(fall).mul(0.14)) // ripple + lens bulge
    // ...
    const r = texture(tex, coverUv.add(warp).add(split)).r
    const g = texture(tex, coverUv.add(warp)).g
    const b = texture(tex, coverUv.add(warp).sub(split)).b

The first line makes the ripple, a sine wave travelling outward from the pointer. The second turns it into a warp, a small push on the picture's coordinates. Then the colour trick: read red, green and blue a little apart from each other. That small shift gives the rainbow edge.

One number, a new look

  • Gradient: change the four colour values for a new palette, or the speed number.
  • Particles: change COUNT. Fewer dots for a calm look, more for a storm.
  • Hover: change the 34, and the rings get thinner or wider.

Small numbers, big changes. This is where AI is a great helper: describe the look, and it changes the numbers.

Shaders are fast; still be kind

From lib/stage.ts:

    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) // cap DPR at 2
  // ...
  // Do not burn GPU on a canvas that is scrolled out of view.
  let visible = true
  const io = new IntersectionObserver(([entry]) => { visible = entry.isIntersecting })
  io.observe(host)

  renderer.setAnimationLoop(now => {
    if (!visible) { last = now; return }
    const dt = prefersReducedMotion() ? 0 : Math.min((now - last) / 1000, 0.05)
    // ...
  })
  1. Fallback: no WebGPU, no problem; the same code runs on WebGL2.
  2. Cap the pixel ratio at 2 pixels per CSS pixel. A phone doesn't need more.
  3. Pause off screen: a canvas scrolled out of view stops drawing.
  4. Respect reduced motion: dt becomes 0, so time and the particles freeze.

And test on a phone, not just your laptop.

Try it yourself

Change the four gradient colours, set COUNT to 1000 and then 9000, and change the 34 in the ripple. The project files and sample prompts are in the community, free to join.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in React · 55 of 75

Previous
Animated Component Libraries (Magic UI, Aceternity UI): Copy-In Motion and When It Becomes Noise
Next post
Deploy Many Vite Demos as One Static Site: A Gallery Page, One Build Command and import.meta.env.BASE_URL

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Related posts

Backend vs Frontend: What Runs Where, and Why the Server Is the One You Trust

Every web app has two halves. The front end runs on the user's device and is trusted with nothing; the back end holds the data, the secrets and the rules. Checked with real requests to a Django blog.

One Request, Two Answers: the Same Post as an HTML Page and as JSON

Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.

A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx

Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.

How a Web Page Works: HTML Tags, Elements and Attributes

A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.

On this page

  • What a shader is
  • Write once: WebGPU first, WebGL2 fallback
  • Effect 1: a living gradient
  • Effect 2: particles that follow the mouse
  • Effect 3: a hover distortion
  • One number, a new look
  • Shaders are fast; still be kind
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

The Python Architect Masterclass: Full Stack to AI Engineer

Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.