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
39 changes: 19 additions & 20 deletions apps/typegpu-docs/src/content/docs/ecosystem/typegpu-noise.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -277,34 +277,33 @@ const f = tgpu.computeFn({ workgroupSize: [1] })(() => {
});
// ---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;
});

return {
seed2: (value: d.v2f) => {
'use gpu';
seed.$ = d.u32(value.x * std.pow(32, 3) + value.y * std.pow(32, 2));
},
sample: () => {
'use gpu';
seed.$ = seed.$ * 1664525 + 1013904223; // % 2 ^ 32
return u32To01Float(seed.$);
},
};
const multiplier = 1664525;
const increment = 1013904223;

return {
seed: tgpu.fn([d.f32])((value) => {
seed.$ = hash(d.u32(value));
}),

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

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

This file was deleted.

Loading
Loading