@@ -131,9 +131,9 @@ To improve performance, you can precompute the gradients using either a *Static*
131
131
A static cache presumes that the domain of the noise function is fixed, and cannot change between shader invocations.
132
132
133
133
``` ts twoslash
134
- // 2d
135
134
import tgpu from ' typegpu' ;
136
135
import * as d from ' typegpu/data' ;
136
+ // ---cut---
137
137
import { perlin3d } from ' @typegpu/noise' ;
138
138
139
139
const root = await tgpu .init ();
@@ -143,4 +143,30 @@ const main = tgpu['~unstable'].fn([])(() => {
143
143
const value = perlin3d .sample (d .vec3f (0.5 , 0 , 0 ));
144
144
const wrappedValue = perlin3d .sample (d .vec3f (10.5 , 0 , 0 )); // the same as `value`!
145
145
});
146
- ```
146
+ ```
147
+ Or in WebGPU:
148
+ ``` ts
149
+ /// <reference types = " @webgpu/types" />
150
+ import * as d from ' typegpu/data' ;
151
+
152
+ declare const device: GPUDevice ;
153
+ // ---cut---
154
+ import tgpu from ' typegpu' ;
155
+ import { perlin3d } from ' @typegpu/noise' ;
156
+
157
+ const root = tgpu .initFromDevice ({ device });
158
+ const cache = perlin3d .staticCache ({ root , size: d .vec3u (10 , 10 , 1 ) });
159
+
160
+ const { code, layouts, catchall } = tgpu .superResolve ({
161
+ template: `
162
+ fn main() {
163
+ let value = perlin3d.sample(vec3f(0.5, 0., 0.));
164
+ let wrappedValue = perlin3d.sample(vec3f(10.5, 0., 0.)); // the same as 'value'!
165
+ // ...
166
+ }
167
+
168
+ // ...
169
+ ` ,
170
+ externals: { perlin3d },
171
+ });
172
+ ```
0 commit comments