-
-
Notifications
You must be signed in to change notification settings - Fork 51
feat: Add @typegpu/three package and Three.js integration example #1453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
c3c3953
feat: tgpu.comptime, tgpu.rawCodeSnippet and `this` allowed in TypeGPU
iwoplaza a10f989
Fix tests
iwoplaza 34212f4
Better docs for rawCodeSnippet
iwoplaza f9bcd96
Docs for comptime
iwoplaza e07faa9
- Namable comptime - Turned `extensionEnabled` into a comptime function
iwoplaza 9ff9990
Merge branch 'main' into feat/comptime-and-raw-code-snippet
iwoplaza 9d9c2fe
Fixes
iwoplaza f294e3e
Add @typegpu/three package and Three.js integration example (very WIP)
iwoplaza 6597b02
Update tgpuThree.ts
reczkok bd8f89a
Three.js types for example code view
iwoplaza 8eebe1d
More tweaks and experiments
iwoplaza 645bd4b
More work
iwoplaza 3403392
A bit more work
iwoplaza f36ab45
More work
iwoplaza 5b47386
Using @typegpu/noise in Three.js
iwoplaza 14b4a2a
Add a new example
iwoplaza dd85138
Testing compute in Three.js
iwoplaza 1d0e61e
Update examples
iwoplaza d03625c
Update typegpu-material.ts
iwoplaza d195d71
Update index.ts
iwoplaza 12d554f
Some more work
iwoplaza 473749a
Works again
iwoplaza f96ec92
TypeGPU compute shaders in TSL!
iwoplaza e74c1d4
A bit of a refactor of the cloth example
iwoplaza feb121b
Cleanup 🧹
iwoplaza 62b58e2
Comparing Three and TypeGPU output
iwoplaza edb9c3e
triNoise3D in TypeGPU
iwoplaza 8b5c1cd
comptime
iwoplaza f055ea8
Support for 'this' in TypeGPU shader functions
iwoplaza fe5cda4
Update verlet.ts
iwoplaza bdee185
feat: Attractors example (#1949)
aleksanderkatan e994076
Merge branch 'main' into feat/tgpu-three
iwoplaza d9e0446
Tweaks
iwoplaza 2076be6
feat: Tweaks to feat/tgpu-three (#1954)
iwoplaza 4ffd930
Some review fixes
iwoplaza 0be03fb
Thumbnails and tags
iwoplaza 4402f83
Comptime fromTSL
iwoplaza dac09e9
Update shellless.test.ts
iwoplaza 0de6b04
fix: Calling `toTSL` multiple times (#1974)
aleksanderkatan 7941dbb
feat: Inform user about type mismatches (#1988)
aleksanderkatan 5ca5c2f
Fix renderer resizing when browser zoom
iwoplaza 16d0188
docs: Cloth example controls (#1986)
lursz a861927
feat: ThreeJS 'Compute Particles' with tgpu (#1947)
cieplypolar 48a792b
feat: ThreeJS 'Compute Geometry' with tgpu (#1948)
cieplypolar 3eaa5db
feat: ThreeJS 'Compute Snow Particles' example in tgpu (#1972)
cieplypolar 10e82d9
fix: @typegpu/three toTSL should have a per-stage namespace (#1994)
iwoplaza 3ee568d
Merge branch 'main' into feat/tgpu-three
iwoplaza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+395 KB
apps/typegpu-docs/public/assets/threejs/compute-geometry/LeePerrySmith.glb
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
apps/typegpu-docs/public/assets/threejs/compute-geometry/LeePerrySmith_License.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Creative Commons Licence | ||
| Infinite, 3D Head Scan by Lee Perry-Smith is licensed under a Creative Commons Attribution 3.0 Unported License. | ||
| Based on a work at www.triplegangers.com. | ||
| Permissions beyond the scope of this license may be available at http://www.ir-ltd.net/ | ||
| Please remember: Do what you want with the files, but always mention where you got them from... |
101 changes: 101 additions & 0 deletions
101
apps/typegpu-docs/src/content/docs/ecosystem/typegpu-three.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --- | ||
| title: "@typegpu/three" | ||
| --- | ||
|
|
||
| [TSL (Three.js Shading Language)](https://github.com/mrdoob/three.js/wiki/Three.js-Shading-Language#function) is a node-based shader composition system for Three.js. Shader logic and control flow is built up by composing special functions, | ||
| with a focus on composability, intuitive sharing of logic across modules and customizability. TypeGPU fits naturally into this system thanks to the `@typegpu/three` package. You can choose to write your TSL building blocks in TypeGPU, which has a few benefits: | ||
| - Control-flow like `if` statements and `for` loops makes use of familiar JavaScript syntax instead of special functions. | ||
| - The code you write is semantically valid JavaScript, with types flowing through each expression. | ||
| - Unit-testability, since you can call these functions on the CPU | ||
|
|
||
| Below are a select few cases comparing TSL and TypeGPU: | ||
|
|
||
| import { Card, CardGrid } from '@astrojs/starlight/components'; | ||
|
|
||
| ## Node definition | ||
|
|
||
| TSL: | ||
| ```ts | ||
| const simulate = Fn(() => { | ||
| // | ||
| // ... TSL code ... | ||
| // | ||
| }); | ||
| ``` | ||
|
|
||
| TypeGPU: | ||
| ```ts twoslash | ||
| import * as t3 from '@typegpu/three'; | ||
| // ---cut--- | ||
| const simulate = t3.toTSL(() => { | ||
| 'use gpu'; | ||
| // | ||
| // ... TypeGPU code ... | ||
| // | ||
| }); | ||
| ``` | ||
|
|
||
| ## Function definition | ||
|
|
||
| TSL: | ||
| ```ts | ||
| const oscSine = Fn(([t = time]) => { | ||
| return t.add(0.75).mul(Math.PI * 2).sin().mul(0.5).add(0.5); | ||
| }); | ||
| ``` | ||
|
|
||
| TypeGPU: | ||
| ```ts twoslash | ||
| import * as std from 'typegpu/std'; | ||
| // ---cut--- | ||
| const oscSine = (t: number) => { | ||
| 'use gpu'; | ||
| return std.sin((t + 0.75) * Math.PI * 2) * 0.5 + 0.5; | ||
| }; | ||
| ``` | ||
|
|
||
| ## If statements | ||
|
|
||
| TSL: | ||
| ```ts | ||
| If(instanceIndex.greaterThanEqual(uint(vertexCount)), () => { | ||
| Return(); | ||
| }); | ||
| ``` | ||
|
|
||
| TypeGPU: | ||
| ```ts twoslash | ||
| import * as t3 from '@typegpu/three'; | ||
| declare const vertexCount: number; | ||
| const some = () => { | ||
| // ---cut-before--- | ||
| if (t3.instanceIndex.$ >= vertexCount) { | ||
| return; | ||
| } | ||
| // ---cut-after--- | ||
| }; | ||
| ``` | ||
|
|
||
| ## For loops | ||
|
|
||
| TSL: | ||
| ```ts | ||
| Loop({ start: ptrStart, end: ptrEnd, type: 'uint', condition: '<' }, ({ i }) => { | ||
| const springId = springListBuffer.element( i ).toVar( 'springId' ); | ||
| const springForce = springForceBuffer.element( springId ); | ||
| const springVertexIds = springVertexIdBuffer.element( springId ); | ||
| const factor = select( springVertexIds.x.equal( instanceIndex ), 1.0, - 1.0 ); | ||
| force.addAssign( springForce.mul( factor ) ); | ||
| }); | ||
| ``` | ||
|
|
||
| TypeGPU: | ||
| ```ts | ||
| for (let i = ptrStart; i < ptrEnd; i++) { | ||
| const springId = springListBuffer.$[i]; | ||
| const springForce = springForceBuffer.$[springId]; | ||
| const springVertexIds = springVertexIdBuffer.$[springId]; | ||
| const factor = std.select(-1, 1, springVertexIds.x === idx); | ||
| force = force.add(springForce.mul(d.f32(factor))); | ||
| } | ||
| ``` |
iwoplaza marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <canvas data-fit-to-container></canvas> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.