Skip to content

Examples: Add WebGL <-> HTML Overlay Example#32849

Open
zalo wants to merge 13 commits intomrdoob:devfrom
zalo:example/webgl_overlay
Open

Examples: Add WebGL <-> HTML Overlay Example#32849
zalo wants to merge 13 commits intomrdoob:devfrom
zalo:example/webgl_overlay

Conversation

@zalo
Copy link
Copy Markdown
Contributor

@zalo zalo commented Jan 24, 2026

This PR adds an example for sandwiching HTML elements between WebGL elements so it feels like the HTML is embedded within the 3D space.

I was noticing the WebGPU Blocks trailer has a similar "all GL" example, and I figured the proper hybrid deserves a proper demonstration in the main repo's examples.

The basic example is optimized for line-count, functionality, and compatibility with both desktop and phone devices:

Basic Minimalist Example (this PR)

But the real magic comes from giving this context-friendly version to Claude with the frontend-design plugin (all single-file!):

Cyberpunk Example

Cyberpunk Example (Extreme Glow)

Vogue Magazine Layout Example

zalo and others added 9 commits January 23, 2026 14:16
Demonstrates a technique for rendering three.js canvases that integrate
with scrollable HTML content. 3D elements can appear both in front of
and behind HTML elements using dual WebGL renderers with split near/far
clipping planes.

Based on ThreeOverlay by Johnathon Selstad.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Use absolute positioning with transform on Safari browsers
- Conditionally allow scrolling in iframe for overlay examples
- Add screenshot/thumbnail for examples page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 24, 2026 23:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new example demonstrating how to visually sandwich HTML content between two WebGL layers, and wires it into the examples index with an accompanying screenshot and a Safari-specific scrolling fix.

Changes:

  • Add examples/webgl_overlay.html, a minimal overlay example using two WebGL renderers (background and foreground) synchronized with page scrolling and mapping paragraph elements into 3D Box3 helpers.
  • Add examples/screenshots/webgl_overlay.jpg as the thumbnail/screenshot for the new example.
  • Register the new example in examples/files.json and adjust the Safari iframe auto-resize logic in examples/index.html to allow scrolling specifically for overlay examples while preserving the Safari sizing workaround.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
examples/webgl_overlay.html New overlay example implementing dual WebGL renderers, scroll-synced camera, Safari handling, and 3D representations of HTML paragraphs.
examples/screenshots/webgl_overlay.jpg Screenshot asset for the new webgl_overlay example used in the examples gallery.
examples/index.html Update Safari iframe auto-resize workaround and allow scrolling for overlay examples by skipping scrolling="no" when the hash includes overlay.
examples/files.json Register the new webgl_overlay example so it appears in the examples listing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mrdoob
Copy link
Copy Markdown
Owner

mrdoob commented Jan 25, 2026

Haha!

The bloom is a bit overkill...

I think Cyberpunk Example is the best one. (Better than the minimalist)

@zalo
Copy link
Copy Markdown
Contributor Author

zalo commented Jan 25, 2026

I think Cyberpunk Example is the best one. (Better than the minimalist)

Yeah; I agree 😄

But, since it’s ~1200 lines, I figured a minimalist ~350 line example would be more useful for Claude to remix without getting biased by the Cyberpunk parts 🤔

Should I do both? Trying to think of the best way to make it useful while still showing it off…

zalo and others added 2 commits January 24, 2026 20:06
Regenerated screenshot for the webgl_overlay example.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 357.49
84.84
357.49
84.84
+0 B
+0 B
WebGPU 621.89
172.77
621.89
172.77
+0 B
-1 B
WebGPU Nodes 620.49
172.53
620.49
172.53
+0 B
-2 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 490.27
119.86
490.27
119.86
+0 B
+0 B
WebGPU 692.79
188.01
692.79
188.01
+0 B
+0 B
WebGPU Nodes 642.17
175.11
642.17
175.11
+0 B
+0 B

zalo and others added 2 commits January 24, 2026 22:17
Switch from system fonts to Google Fonts Roboto to ensure
consistent text rendering across different environments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@marcofugaro
Copy link
Copy Markdown
Contributor

Nice! I was looking for some approach to mix HTML in Three.js and also have proper transparency. Current examples don't have this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants