-
-
Notifications
You must be signed in to change notification settings - Fork 47
docs: ducks #2018
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
Draft
lursz
wants to merge
64
commits into
main
Choose a base branch
from
docs/duck
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
docs: ducks #2018
Changes from all commits
Commits
Show all changes
64 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 70b2bd0
init
lursz e32f466
getting some errors
lursz 2cff28a
pool works
lursz ac5e215
can see ducks
lursz 7a6b5f5
clean up your room
lursz 2cb8348
moved fns out
lursz 7941dbb
feat: Inform user about type mismatches (#1988)
aleksanderkatan b399827
init not in index
lursz 69f1db3
Merge branch 'feat/tgpu-three' into docs/duck
lursz 5ca5c2f
Fix renderer resizing when browser zoom
iwoplaza 16d0188
docs: Cloth example controls (#1986)
lursz 7bfd811
Merge branch 'feat/tgpu-three' into docs/duck
lursz b31f66d
zooming bug fix
lursz a4e4cca
stuff in consts
lursz d2b674d
ducklings location fix
lursz ef344de
bug na bugu bug pogania
lursz 3cc7730
vertex fix
lursz 1805005
merge main
lursz b4e30ea
example controls
lursz 1a3a24c
cya og-3js
lursz ba048f3
🦕🦕🦕
lursz a85db60
water fix
lursz eda29f1
move to consts
lursz 5dbcf8b
Merge branch 'main' into docs/duck
lursz 95ad4ee
final touch
lursz 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
40 changes: 40 additions & 0 deletions
40
apps/typegpu-docs/src/examples/threejs/ducklings/consts.ts
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,40 @@ | ||
| import * as d from 'typegpu/data'; | ||
|
|
||
| // water | ||
| export const WIDTH = 256; | ||
| export const BOUNDS = 6; | ||
| export const BOUNDS_HALF = BOUNDS * 0.5; | ||
| export const limit = BOUNDS_HALF - 0.2; | ||
|
|
||
| export const waterMaxHeight = 0.1; | ||
|
|
||
| // ducklings | ||
| export const SPEED = 5.0; | ||
| export const NUM_DUCKS = 100; | ||
| export const DUCK_STRIDE = 3; | ||
| export const Y_OFFSET = -0.04; | ||
| export const VERTICAL_RESPONSE_FACTOR = 0.98; | ||
| export const WATER_PUSH_FACTOR = 0.015; | ||
| export const LINEAR_DAMPING = 0.92; | ||
| export const BOUNCE_DAMPING = -0.4; | ||
|
|
||
| // controls | ||
| export const INITIAL_VISCOSITY = 0.96; | ||
| export const INITIAL_MOUSE_SIZE = 0.12; | ||
| export const INITIAL_MOUSE_DEEP = 0.2; | ||
|
|
||
| //sun | ||
| export const SUN_POSITION = [-1, 2.6, 1.4]; | ||
|
|
||
| // STRUCTS | ||
| export const NeighborIndices = d.struct({ | ||
| northIndex: d.u32, | ||
| southIndex: d.u32, | ||
| eastIndex: d.u32, | ||
| westIndex: d.u32, | ||
| }); | ||
|
|
||
| export const Normals = d.struct({ | ||
| normalX: d.f32, | ||
| normalY: d.f32, | ||
| }); |
75 changes: 75 additions & 0 deletions
75
apps/typegpu-docs/src/examples/threejs/ducklings/gpuHelpers.ts
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,75 @@ | ||
| import type * as t3 from '@typegpu/three'; | ||
| import * as d from 'typegpu/data'; | ||
| import * as std from 'typegpu/std'; | ||
| import type { StorageBufferNode, UniformNode } from 'three/webgpu'; | ||
| import { BOUNDS, NeighborIndices, Normals, WIDTH } from './consts.ts'; | ||
|
|
||
| export function createGpuHelpers( | ||
| heightStorageA: t3.TSLAccessor<d.WgslArray<typeof d.f32>, StorageBufferNode>, | ||
| heightStorageB: t3.TSLAccessor<d.WgslArray<typeof d.f32>, StorageBufferNode>, | ||
| readFromA: t3.TSLAccessor<typeof d.u32, UniformNode<number>>, | ||
| ) { | ||
| const getNeighborIndices = (index: number) => { | ||
| 'use gpu'; | ||
| const width = d.u32(WIDTH); | ||
| const x = d.i32(std.mod(index, WIDTH)); | ||
| const y = d.i32(std.div(index, WIDTH)); | ||
|
|
||
| const leftX = std.max(0, std.sub(x, 1)); | ||
| const rightX = std.min(std.add(x, 1), std.sub(d.i32(width), 1)); | ||
| const bottomY = std.max(0, std.sub(y, 1)); | ||
| const topY = std.min(std.add(y, 1), std.sub(d.i32(width), 1)); | ||
|
|
||
| const westIndex = d.u32(std.add(std.mul(y, d.i32(width)), leftX)); | ||
| const eastIndex = d.u32(std.add(std.mul(y, d.i32(width)), rightX)); | ||
| const southIndex = d.u32(std.add(std.mul(bottomY, d.i32(width)), x)); | ||
| const northIndex = d.u32(std.add(std.mul(topY, d.i32(width)), x)); | ||
|
|
||
| return NeighborIndices({ northIndex, southIndex, eastIndex, westIndex }); | ||
| }; | ||
|
|
||
| const getCurrentHeight = (index: number) => { | ||
| 'use gpu'; | ||
| return std.select( | ||
| heightStorageB.$[index], | ||
| heightStorageA.$[index], | ||
| readFromA.$ === 1, | ||
| ); | ||
| }; | ||
|
|
||
| const getCurrentNormals = (index: number) => { | ||
| 'use gpu'; | ||
| const neighbors = getNeighborIndices(index); | ||
| const north = std.select( | ||
| heightStorageB.$[neighbors.northIndex], | ||
| heightStorageA.$[neighbors.northIndex], | ||
| readFromA.$ === 1, | ||
| ); | ||
| const south = std.select( | ||
| heightStorageB.$[neighbors.southIndex], | ||
| heightStorageA.$[neighbors.southIndex], | ||
| readFromA.$ === 1, | ||
| ); | ||
| const east = std.select( | ||
| heightStorageB.$[neighbors.eastIndex], | ||
| heightStorageA.$[neighbors.eastIndex], | ||
| readFromA.$ === 1, | ||
| ); | ||
| const west = std.select( | ||
| heightStorageB.$[neighbors.westIndex], | ||
| heightStorageA.$[neighbors.westIndex], | ||
| readFromA.$ === 1, | ||
| ); | ||
|
|
||
| const normalX = std.mul(std.sub(west, east), std.div(WIDTH, BOUNDS)); | ||
| const normalY = std.mul(std.sub(south, north), std.div(WIDTH, BOUNDS)); | ||
|
|
||
| return Normals({ normalX, normalY }); | ||
| }; | ||
|
|
||
| return { | ||
| getNeighborIndices, | ||
| getCurrentHeight, | ||
| getCurrentNormals, | ||
| }; | ||
| } | ||
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></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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔