-
-
Notifications
You must be signed in to change notification settings - Fork 22
docs: Generator slot #1665
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
Open
cieplypolar
wants to merge
77
commits into
main
Choose a base branch
from
docs/generator-slot
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.
Open
docs: Generator slot #1665
Changes from all commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
1de9166
Histograms
cieplypolar 7462dfa
Normal, Exp
cieplypolar 2a69945
Work on cauchy
cieplypolar 98dfac7
All continuous
cieplypolar 73a6eef
3d scatter
cieplypolar e7ae4ea
on unit sphere
cieplypolar 86e10cc
onUnitCube
cieplypolar d228417
Something
cieplypolar 71c4a0b
Updated docs
cieplypolar 7ec72e8
Restored old pnpm lock file
cieplypolar f086faa
Restored old pnpm lock file
cieplypolar f27fdb1
typos
cieplypolar 1912024
Corrected docs
cieplypolar a6a657a
Skeleton of an example
cieplypolar 60871d5
Nice html layout + camera reset
cieplypolar 450b303
Added tag
cieplypolar c745a53
Small refactor
cieplypolar 5cbd897
Dont care about 0
cieplypolar 4216899
More refactor
cieplypolar 0b38fff
Histogram plot
cieplypolar 19d8aa6
All plots
cieplypolar f00de44
thumbnail
cieplypolar 18954d5
Optimized replotting
cieplypolar 04c2d14
Left console.logs
cieplypolar da6696e
Not working animations
cieplypolar 1659a3a
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 028ba89
Fixed force reexe
cieplypolar 515d56e
Working transitions!
cieplypolar 70f85c5
Not this bool
cieplypolar 8c5d66b
Fixed seed
cieplypolar 03afea4
Docs update
cieplypolar 2839bfe
Math in docs
cieplypolar b85304e
Refactor in plotter
cieplypolar 88e6b66
Refactor in plotter
cieplypolar 516ba05
Added controls popup
cieplypolar e604da9
deno fmt
cieplypolar 37ab92f
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 6e0cce0
Broken lockfile
cieplypolar 2a29e5b
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 3fc3050
Example tests alignment
cieplypolar 8763ef6
Some review fixes
cieplypolar 8d2c97c
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar abc9b2a
rescaling instead of clamping
cieplypolar 1c05a69
Brutal replotFlag
cieplypolar e5a8dff
Review changes
cieplypolar 3eae7b5
Reseed button and minor changes
cieplypolar b4f0831
Fix randf.sampleExclusive
cieplypolar 641e621
Bind Group Layouts
cieplypolar e7d370c
Buffer cache
cieplypolar 5521cb3
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 4c5bf8e
Pipeline cache
cieplypolar b2bb9d2
Generator slot docs
cieplypolar 31b9131
more docs
cieplypolar bcd57b1
Visual uniformity test
cieplypolar cabf42a
Typos
cieplypolar 553b6ea
Nice uniformity test
cieplypolar 2c70cee
Merge branch 'main' into feat/uniform01-derivatives
cieplypolar 21442d1
Example resolution test
cieplypolar c739ecd
Merge branch 'feat/uniform01-derivatives' into docs/generator-slot
cieplypolar a751ae7
More controls and thumbnail
cieplypolar 63ebd3e
Resolution test
cieplypolar df71137
final polish
cieplypolar 19acd22
Merge branch 'main' into docs/generator-slot
cieplypolar 6b0aff3
Broken pnpm-lock
cieplypolar a433a0a
Merge branch 'main' into docs/generator-slot
cieplypolar 9e34138
nits
cieplypolar c89dc3b
typo
cieplypolar 8c9a9a9
shellless
cieplypolar 6c3ca10
Merge branch 'main' into docs/generator-slot
cieplypolar 339309a
optional seeds
cieplypolar d2b47b3
Merge branch 'main' into docs/generator-slot
cieplypolar e693bd8
Merge branch 'main' into docs/generator-slot
cieplypolar a6bf42a
Merge branch 'main' into docs/generator-slot
cieplypolar 3f112be
more descriptive function name
cieplypolar eb33788
Fix example test
cieplypolar 23e8f7d
Merge branch 'main' into docs/generator-slot
cieplypolar a08f37d
Merge branch 'main' into docs/generator-slot
cieplypolar 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { PRNG } from './prngs.ts'; | ||
|
||
export const gridSizes = [10, 25, 50, 100, 200, 500, 700, 1000]; | ||
export const initialGridSize = gridSizes[3]; | ||
export const initialPRNG = PRNG.BPETER; | ||
export const prngs: PRNG[] = Object.values(PRNG); |
21 changes: 21 additions & 0 deletions
21
apps/typegpu-docs/src/examples/tests/uniformity/fragment.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,21 @@ | ||
import tgpu from 'typegpu'; | ||
import type { TgpuUniform } from 'typegpu'; | ||
import * as d from 'typegpu/data'; | ||
import * as std from 'typegpu/std'; | ||
import { randf } from '@typegpu/noise'; | ||
|
||
export const bindFullScreenGridFSWithUniforms = ( | ||
gridSizeUniform: TgpuUniform<d.F32>, | ||
canvasRatioUniform: TgpuUniform<d.F32>, | ||
) => | ||
tgpu['~unstable'].fragmentFn({ | ||
in: { uv: d.vec2f }, | ||
out: d.vec4f, | ||
})((input) => { | ||
const uv = input.uv.add(1).div(2).mul(d.vec2f(canvasRatioUniform.$, 1)); | ||
const gridedUV = std.floor(uv.mul(gridSizeUniform.$)); | ||
|
||
randf.seed2(gridedUV); | ||
|
||
return d.vec4f(d.vec3f(randf.sample()), 1.0); | ||
}); |
37 changes: 37 additions & 0 deletions
37
apps/typegpu-docs/src/examples/tests/uniformity/helpers.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,37 @@ | ||
import type { TgpuRenderPipeline, TgpuRoot, TgpuUniform } from 'typegpu'; | ||
import { randomGeneratorSlot } from '@typegpu/noise'; | ||
import type * as d from 'typegpu/data'; | ||
|
||
import { fullScreenTriangleVertexShader } from './vertex.ts'; | ||
import { bindFullScreenGridFSWithUniforms } from './fragment.ts'; | ||
import { getPRNG, type PRNG } from './prngs.ts'; | ||
|
||
export const preparePipeline = ( | ||
root: TgpuRoot, | ||
presentationFormat: GPUTextureFormat, | ||
prng: PRNG, | ||
gridSizeUniform: TgpuUniform<d.F32>, | ||
canvasRatioUniform: TgpuUniform<d.F32>, | ||
): TgpuRenderPipeline => | ||
root['~unstable'] | ||
.with(randomGeneratorSlot, getPRNG(prng)) | ||
.withVertex(fullScreenTriangleVertexShader, {}) | ||
.withFragment( | ||
bindFullScreenGridFSWithUniforms(gridSizeUniform, canvasRatioUniform), | ||
{ | ||
format: presentationFormat, | ||
}, | ||
) | ||
.createPipeline(); | ||
|
||
export const executePipeline = ( | ||
pipeline: TgpuRenderPipeline, | ||
context: GPUCanvasContext, | ||
) => | ||
pipeline | ||
.withColorAttachment({ | ||
view: context.getCurrentTexture().createView(), | ||
loadOp: 'clear', | ||
storeOp: 'store', | ||
}) | ||
.draw(3); |
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> |
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,94 @@ | ||
import tgpu, { type TgpuRenderPipeline } from 'typegpu'; | ||
import * as d from 'typegpu/data'; | ||
|
||
import * as c from './constants.ts'; | ||
import type { PRNG } from './prngs.ts'; | ||
import { executePipeline, preparePipeline } from './helpers.ts'; | ||
|
||
const root = await tgpu.init(); | ||
|
||
const canvas = document.querySelector('canvas') as HTMLCanvasElement; | ||
const context = canvas.getContext('webgpu') as GPUCanvasContext; | ||
const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); | ||
context.configure({ | ||
device: root.device, | ||
format: presentationFormat, | ||
alphaMode: 'premultiplied', | ||
}); | ||
|
||
const gridSizeUniform = root.createUniform(d.f32, c.initialGridSize); | ||
const canvasRatioUniform = root.createUniform( | ||
d.f32, | ||
canvas.width / canvas.height, | ||
); | ||
const pipelineCache = new Map<PRNG, TgpuRenderPipeline>(); | ||
let prng: PRNG = c.initialPRNG; | ||
|
||
const redraw = (value: PRNG) => { | ||
let pipeline = undefined; | ||
if (!pipelineCache.has(value)) { | ||
pipeline = preparePipeline( | ||
root, | ||
presentationFormat, | ||
value, | ||
gridSizeUniform, | ||
canvasRatioUniform, | ||
); | ||
pipelineCache.set(value, pipeline); | ||
} else { | ||
pipeline = pipelineCache.get(value); | ||
} | ||
executePipeline(pipeline as TgpuRenderPipeline, context); | ||
}; | ||
|
||
// #region Example controls & Cleanup | ||
export const controls = { | ||
'PRNG': { | ||
initial: c.initialPRNG, | ||
options: c.prngs, | ||
onSelectChange: (value: PRNG) => { | ||
prng = value; | ||
redraw(value); | ||
}, | ||
}, | ||
'Grid Size': { | ||
initial: c.initialGridSize, | ||
options: c.gridSizes, | ||
onSelectChange: (value: number) => { | ||
gridSizeUniform.write(value); | ||
redraw(prng); | ||
}, | ||
}, | ||
'Test Resolution': import.meta.env.DEV && { | ||
onButtonClick: () => { | ||
c.prngs | ||
.map((prng) => | ||
tgpu.resolve({ | ||
externals: { | ||
f: preparePipeline( | ||
root, | ||
presentationFormat, | ||
prng, | ||
gridSizeUniform, | ||
canvasRatioUniform, | ||
), | ||
}, | ||
}) | ||
) | ||
.map((r) => root.device.createShaderModule({ code: r })); | ||
}, | ||
}, | ||
}; | ||
|
||
const resizeObserver = new ResizeObserver(() => { | ||
canvasRatioUniform.write(canvas.width / canvas.height); | ||
redraw(prng); | ||
}); | ||
resizeObserver.observe(canvas); | ||
|
||
export function onCleanup() { | ||
resizeObserver.disconnect(); | ||
root.destroy(); | ||
} | ||
|
||
// #endregion |
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,31 @@ | ||
import tgpu from 'typegpu'; | ||
import * as d from 'typegpu/data'; | ||
import * as std from 'typegpu/std'; | ||
import type { StatefulGenerator } from '@typegpu/noise'; | ||
|
||
export const LCG: StatefulGenerator = (() => { | ||
const seed = tgpu.privateVar(d.u32); | ||
|
||
const u32To01Float = tgpu.fn([d.u32], d.f32)`(val){ | ||
let exponent: u32 = 0x3f800000; | ||
let mantissa: u32 = 0x007fffff & val; | ||
var ufloat: u32 = (exponent | mantissa); | ||
return bitcast<f32>(ufloat) - 1f; | ||
}`; | ||
|
||
return { | ||
seed: (value: number) => { | ||
'kernel'; | ||
seed.$ = d.u32(value * std.pow(32, 3)); | ||
}, | ||
seed2: (value: d.v2f) => { | ||
'kernel'; | ||
seed.$ = d.u32(value.x * std.pow(32, 3) + value.y * std.pow(32, 2)); | ||
}, | ||
sample: () => { | ||
'kernel'; | ||
seed.$ = seed.$ * 1664525 + 1013904223; // % 2 ^ 32 | ||
return u32To01Float(seed.$); | ||
}, | ||
}; | ||
})(); |
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,6 @@ | ||
{ | ||
"title": "Uniformity", | ||
"category": "tests", | ||
"tags": ["experimental"], | ||
"dev": true | ||
} |
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,17 @@ | ||
import { BPETER, type StatefulGenerator } from '@typegpu/noise'; | ||
|
||
import { LCG } from './lcg.ts'; | ||
|
||
export const PRNG = { | ||
BPETER: 'bpeter (default)', | ||
LCG: 'lcg', | ||
} as const; | ||
|
||
export type PRNG = typeof PRNG[keyof typeof PRNG]; | ||
|
||
const PRNG_MAP = { | ||
[PRNG.BPETER]: BPETER, | ||
[PRNG.LCG]: LCG, | ||
}; | ||
|
||
export const getPRNG = (prng: PRNG): StatefulGenerator => PRNG_MAP[prng]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
import tgpu from 'typegpu'; | ||
import * as d from 'typegpu/data'; | ||
|
||
export const fullScreenTriangleVertexShader = tgpu['~unstable'].vertexFn({ | ||
in: { vertexIndex: d.builtin.vertexIndex }, | ||
out: { pos: d.builtin.position, uv: d.vec2f }, | ||
})((input) => { | ||
const pos = [d.vec2f(-1, -1), d.vec2f(3, -1), d.vec2f(-1, 3)]; | ||
|
||
return { | ||
pos: d.vec4f(pos[input.vertexIndex], 0.0, 1.0), | ||
uv: pos[input.vertexIndex], | ||
}; | ||
}); |
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
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.