Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c503acd
Cleanup
iwoplaza Nov 20, 2025
d59e8ba
Tweaks and docs
iwoplaza Dec 4, 2025
a2e96fb
Cleanup
iwoplaza Dec 4, 2025
7fbab34
Update to t3 instead of access
iwoplaza Dec 4, 2025
a3f5f9a
More docs
iwoplaza Dec 5, 2025
82109fc
Update index.ts
iwoplaza Dec 5, 2025
33da2e0
Simpler API
iwoplaza Dec 5, 2025
d66e5e3
Working on shorthands
iwoplaza Dec 5, 2025
ee1ab05
Using shorthands in attractor example
iwoplaza Dec 5, 2025
5a4888d
More refactors
iwoplaza Dec 5, 2025
0886c95
Using shorthands in other examples
iwoplaza Dec 5, 2025
5ff4950
Update sandboxModules.ts
iwoplaza Dec 5, 2025
2c0bd2d
working compute particles example
cieplypolar Nov 28, 2025
fb077da
TSL import
cieplypolar Nov 28, 2025
6e32fcf
our controls instead of inspector
cieplypolar Nov 28, 2025
4b67891
bumped down threejs, rewrite init in tgpu
cieplypolar Nov 28, 2025
0343769
all compute shaders in tgpu
cieplypolar Nov 28, 2025
2882b81
accessor naming convention
cieplypolar Dec 2, 2025
6753bc1
new api alignment
cieplypolar Dec 9, 2025
4eef60e
thumbnail
cieplypolar Dec 10, 2025
127052c
working three js compute geometry example
cieplypolar Nov 30, 2025
1cb6de5
controls + typescript happy
cieplypolar Dec 1, 2025
7b63297
tiny refactor
cieplypolar Dec 1, 2025
6e7f6be
no ts-ignore
cieplypolar Dec 2, 2025
f25d05c
all compute shaders in tgpu
cieplypolar Dec 2, 2025
da802c8
new api alignment
cieplypolar Dec 9, 2025
681d824
thumbnail
cieplypolar Dec 10, 2025
f80c61d
working compute particles example
cieplypolar Nov 28, 2025
3ed31bb
TSL import
cieplypolar Nov 28, 2025
01aefc9
our controls instead of inspector
cieplypolar Nov 28, 2025
04a6d19
bumped down threejs, rewrite init in tgpu
cieplypolar Nov 28, 2025
d33b431
all compute shaders in tgpu
cieplypolar Nov 28, 2025
538d7d6
accessor naming convention
cieplypolar Dec 2, 2025
0685012
new api alignment
cieplypolar Dec 9, 2025
7fb20c9
thumbnail
cieplypolar Dec 10, 2025
4e94772
pnpm lock
cieplypolar Dec 10, 2025
d25bf82
Merge branch 'feat/threejs-compute-particles' into feat/threejs-torso
cieplypolar Dec 10, 2025
685a00c
review changes
cieplypolar Dec 18, 2025
a6e0a4f
Merge branch 'feat/tgpu-three' into feat/threejs-compute-particles
cieplypolar Dec 18, 2025
263da97
Merge branch 'feat/threejs-compute-particles' into feat/threejs-torso
cieplypolar Dec 18, 2025
12149df
review changes
cieplypolar Dec 18, 2025
23a2e5d
Merge branch 'feat/threejs-compute-particles' into feat/threejs-torso
cieplypolar Dec 18, 2025
4e7fa5c
review changes + info about model loading
cieplypolar Dec 18, 2025
1f3458e
🦕
cieplypolar Dec 18, 2025
e8673cb
Merge branch 'feat/tgpu-three' into feat/threejs-torso
cieplypolar Dec 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Copy link
Contributor

Choose a reason for hiding this comment

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

image

Do we care that the licence is not listed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will add it, just in case

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...
20 changes: 20 additions & 0 deletions apps/typegpu-docs/src/examples/threejs/compute-geometry/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="loading">Model is loading...</div>
<canvas data-fit-to-container></canvas>
<style>
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 1.5rem;
color: white;
background: rgba(0, 0, 0, 0.7);
padding: 1rem;
border-radius: 0.5rem;
z-index: 10;
}

.loading.loaded {
display: none;
}
</style>
231 changes: 231 additions & 0 deletions apps/typegpu-docs/src/examples/threejs/compute-geometry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/*
* Based on: https://github.com/mrdoob/three.js/blob/master/examples/webgpu_compute_geometry.html
*/
import * as THREE from 'three/webgpu';
import * as TSL from 'three/tsl';
import { type GLTF, GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import * as t3 from '@typegpu/three';
import * as d from 'typegpu/data';
import * as std from 'typegpu/std';

const canvas = document.querySelector('canvas') as HTMLCanvasElement;
const renderer = new THREE.WebGPURenderer({ canvas, antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);

const camera = new THREE.PerspectiveCamera(
50,
canvas.clientWidth / canvas.clientHeight,
0.1,
10,
);
camera.position.set(0, 0, 1);

const scene = new THREE.Scene();

const bgColor = TSL.screenUV.y.mix(TSL.color(0x9f87f7), TSL.color(0xf2cdcd));
const bgVignette = TSL.screenUV.distance(0.5).remapClamp(0.3, 0.8).oneMinus();
const bgIntensity = 4;
scene.backgroundNode = bgColor.mul(
bgVignette.mul(TSL.color(0xa78ff6).mul(bgIntensity)),
);

const pointerPosition = t3.uniform(TSL.vec4(0), d.vec4f);
const elasticity = t3.uniform(0.4, d.f32);
const damping = t3.uniform(0.94, d.f32);
const brushSize = t3.uniform(0.25, d.f32);
const brushStrength = t3.uniform(0.22, d.f32);

const jelly = TSL.Fn(({ renderer, geometry, object }) => {
const count = geometry.attributes.position.count;

const positionStorageBufferAttribute = new THREE.StorageBufferAttribute(
count,
3,
);
geometry.setAttribute('storagePosition', positionStorageBufferAttribute);

const basePositionAccessor = t3.fromTSL(
TSL.storage(
geometry.attributes.position as THREE.BufferAttribute,
'vec3',
count,
),
d.arrayOf(d.vec3f),
);
const positionAccessor = t3.fromTSL(
TSL.storage(
positionStorageBufferAttribute,
'vec3',
count,
),
d.arrayOf(d.vec3f),
);
const speedAccessor = t3.fromTSL(
TSL.storage(
new THREE.StorageBufferAttribute(count, 3),
'vec3',
count,
),
d.arrayOf(d.vec3f),
);

const computeInit = t3.toTSL(() => {
'use gpu';
positionAccessor.$[t3.instanceIndex.$] =
basePositionAccessor.$[t3.instanceIndex.$];
}).compute(count).setName('Init Mesh');

const modelMatrixAccessor = t3.fromTSL(
TSL.objectWorldMatrix(object),
d.mat4x4f,
);

const computeUpdate = t3.toTSL(() => {
'use gpu';
const instanceIdx = t3.instanceIndex.$;
const basePosition = basePositionAccessor.$[instanceIdx];
let position = positionAccessor.$[instanceIdx];

if (pointerPosition.$.w === 1) {
const worldPosition = modelMatrixAccessor.$.mul(
d.vec4f(position, 1),
).xyz;
const dist = std.distance(worldPosition, pointerPosition.$.xyz);
const direction = std.normalize(
pointerPosition.$.xyz.sub(worldPosition),
);
const power = std.max(brushSize.$ - dist, 0) *
brushStrength.$;

positionAccessor.$[instanceIdx] = position.add(
direction.mul(power),
);
position = positionAccessor.$[instanceIdx];
}

const dist = std.distance(
basePosition,
position,
);
const force = basePosition
.sub(position)
.mul(elasticity.$ * dist);
const speed = speedAccessor.$[instanceIdx]
.add(force)
.mul(damping.$);

speedAccessor.$[instanceIdx] = d.vec3f(speed);
positionAccessor.$[instanceIdx] = position.add(speed);
}).compute(count).setName('Update Jelly');

computeUpdate.onInit(() => renderer.compute(computeInit));

return computeUpdate;
});

new GLTFLoader().load(
'/TypeGPU/assets/threejs/compute-geometry/LeePerrySmith.glb',
// on successful load
(gltf: GLTF) => {
const material = new THREE.MeshNormalNodeMaterial();
material.geometryNode = jelly() as unknown as () => THREE.Node;
material.positionNode = TSL.attribute('storagePosition'); // global

const mesh = gltf.scene.children[0] as THREE.Mesh;
mesh.scale.setScalar(0.1);
mesh.material = material;
scene.add(mesh);
document.querySelector('.loading')?.classList.add('loaded');
},
);

const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const onPointerMove = (event: PointerEvent) => {
const rect = canvas.getBoundingClientRect();
pointer.set(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1,
);

raycaster.setFromCamera(pointer, camera);

const intersects = raycaster.intersectObject(scene);

if (intersects.length > 0) {
const { point } = intersects[0];
pointerPosition.node.value.copy(new THREE.Vector4(...point, 1));
pointerPosition.node.value.w = 1; // enable
} else {
pointerPosition.node.value.w = 0; // disable
}
};
canvas.addEventListener('pointermove', onPointerMove);

const resizeObserver = new ResizeObserver(() => {
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
});
resizeObserver.observe(canvas);

const orbitControls = new OrbitControls(camera, canvas);
orbitControls.minDistance = 0.7;
orbitControls.maxDistance = 2;
if ('ontouchstart' in window) {
orbitControls.enableRotate = false; // disable rotation on mobile
}

function animate() {
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);

// #region Example controls and cleanup
export const controls = {
elasticity: {
initial: 0.4,
min: 0,
max: 0.5,
step: 0.01,
onSliderChange: (value: number) => {
elasticity.node.value = value;
},
},
damping: {
initial: 0.94,
min: 0.9,
max: 0.98,
step: 0.01,
onSliderChange: (value: number) => {
damping.node.value = value;
},
},
'brush size': {
initial: 0.25,
min: 0.1,
max: 0.5,
step: 0.01,
onSliderChange: (value: number) => {
brushSize.node.value = value;
},
},
'brush strength': {
initial: 0.22,
min: 0.1,
max: 0.3,
step: 0.01,
onSliderChange: (value: number) => {
brushStrength.node.value = value;
},
},
};

export function onCleanup() {
renderer.dispose();
resizeObserver.unobserve(canvas);
}

// #endregion
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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...
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Three.js - compute / geometry",
"category": "threejs",
"tags": ["experimental"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.