Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 19 additions & 19 deletions apps/typegpu-docs/src/content/docs/ecosystem/typegpu-noise.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -272,39 +272,39 @@ import { randf } from '@typegpu/noise';
const root = await tgpu.init();

const b = root.createMutable(d.f32);
const f = tgpu.computeFn({ workgroupSize: [1] })(() => {
const f = () => {
'use gpu';
b.$ = randf.sample();
});
};
// ---cut---
import {
hash,
randomGeneratorShell,
randomGeneratorSlot,
u32To01F32,
type StatefulGenerator,
} from '@typegpu/noise';

const LCG: StatefulGenerator = (() => {
const LCG32: StatefulGenerator = (() => {
const seed = tgpu.privateVar(d.u32);

const u32To01Float = tgpu.fn([d.u32], d.f32)((value) => {
const mantissa = value >> 9;
const bits = 0x3F800000 | mantissa;
const f = std.bitcastU32toF32(bits);
return f - 1;
});
const multiplier = tgpu.accessor(d.u32, 1664525);
const increment = tgpu.accessor(d.u32, 1013904223);

return {
seed2: (value: d.v2f) => {
'use gpu';
seed.$ = d.u32(value.x * std.pow(32, 3) + value.y * std.pow(32, 2));
},
sample: () => {
seed: tgpu.fn([d.f32])((value) => {
seed.$ = hash(std.bitcastF32toU32(value));
}),

sample: randomGeneratorShell(() => {
'use gpu';
seed.$ = seed.$ * 1664525 + 1013904223; // % 2 ^ 32
return u32To01Float(seed.$);
},
seed.$ = multiplier.$ * seed.$ + increment.$; // % 2 ^ 32
return u32To01F32(seed.$);
}).$name('sample'),
};
})();

const pipeline = root
.with(randomGeneratorSlot, LCG)
.createComputePipeline({ compute: f });
.with(randomGeneratorSlot, LCG32)
.createGuardedComputePipeline(f);
```
6 changes: 0 additions & 6 deletions apps/typegpu-docs/src/examples/tests/uniformity/constants.ts

This file was deleted.

Loading
Loading