Skip to content

Commit 18f23bc

Browse files
committed
Updated to new function API
1 parent ae1466c commit 18f23bc

File tree

11 files changed

+127
-130
lines changed

11 files changed

+127
-130
lines changed

apps/phoure-www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@radix-ui/react-tooltip": "^1.1.6",
2929
"@typegpu/color": "workspace:*",
3030
"@typegpu/common": "workspace:*",
31-
"@typegpu/noise": "^0.0.3",
31+
"@typegpu/noise": "^0.0.5",
3232
"@typegpu/sdf": "workspace:*",
3333
"@types/react": "^18.0.2",
3434
"@types/react-dom": "^18.0.2",

apps/phoure-www/src/lib-filter/bicubicFilter.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const fullScreenQuadVertexFn = tgpu['~unstable']
2121
texelSizeY: vec2f,
2222
coordHG: vec2f,
2323
},
24-
})
25-
.does(/* wgsl */ `(input: VertexInput) -> VertexOutput {
24+
})(/* wgsl */ `{
2625
const SCREEN_RECT = array<vec2f, 6>(
2726
vec2f(-1.0, -1.0),
2827
vec2f(1.0, -1.0),
@@ -45,14 +44,14 @@ const fullScreenQuadVertexFn = tgpu['~unstable']
4544
4645
let viewport_size = vec2f(textureDimensions(texture));
4746
48-
var output: VertexOutput;
49-
output.pos = vec4f(SCREEN_RECT[input.idx], 0.0, 1.0);
50-
output.uv = UVS[input.idx];
47+
var output: Out;
48+
output.pos = vec4f(SCREEN_RECT[in.idx], 0.0, 1.0);
49+
output.uv = UVS[in.idx];
5150
output.texelSizeX = vec2f(1. / f32(viewport_size.x), 0);
5251
output.texelSizeY = vec2f(0, 1. / f32(viewport_size.y));
5352
5453
// calc filter texture coordinates where [0,1] is a single texel
55-
output.coordHG = UVS[input.idx] * viewport_size - vec2f(0.5f, 0.5f); // fetch offsets and weights from filter texture
54+
output.coordHG = UVS[in.idx] * viewport_size - vec2f(0.5f, 0.5f); // fetch offsets and weights from filter texture
5655
5756
return output;
5857
}`)
@@ -72,16 +71,15 @@ const resampleCubic = tgpu['~unstable']
7271
coordHG: vec2f,
7372
},
7473
out: vec4f,
75-
})
76-
.does(/* wgsl */ `(input: FragmentInput) -> @location(0) vec4f {
77-
var hg_x = textureSample(hgLookup, wrappingSampler, input.coordHG.x).xyz;
78-
var hg_y = textureSample(hgLookup, wrappingSampler, input.coordHG.y).xyz; // determine linear sampling coordinates
79-
var coord_source10 = input.uv + hg_x.x * input.texelSizeX;
80-
var coord_source00 = input.uv - hg_x.y * input.texelSizeX;
81-
var coord_source11 = coord_source10 + hg_y.x * input.texelSizeY;
82-
var coord_source01 = coord_source00 + hg_y.x * input.texelSizeY;
83-
coord_source10 = coord_source10 - hg_y.y * input.texelSizeY;
84-
coord_source00 = coord_source00 - hg_y.y * input.texelSizeY; // fetch four linearly interpolated inputs
74+
})(/* wgsl */ `{
75+
var hg_x = textureSample(hgLookup, wrappingSampler, in.coordHG.x).xyz;
76+
var hg_y = textureSample(hgLookup, wrappingSampler, in.coordHG.y).xyz; // determine linear sampling coordinates
77+
var coord_source10 = in.uv + hg_x.x * in.texelSizeX;
78+
var coord_source00 = in.uv - hg_x.y * in.texelSizeX;
79+
var coord_source11 = coord_source10 + hg_y.x * in.texelSizeY;
80+
var coord_source01 = coord_source00 + hg_y.x * in.texelSizeY;
81+
coord_source10 = coord_source10 - hg_y.y * in.texelSizeY;
82+
coord_source00 = coord_source00 - hg_y.y * in.texelSizeY; // fetch four linearly interpolated inputs
8583
var tex_source00 = textureSample(texture, clampingSampler, coord_source00);
8684
var tex_source10 = textureSample(texture, clampingSampler, coord_source10);
8785
var tex_source01 = textureSample(texture, clampingSampler, coord_source01);

apps/phoure-www/src/lib-phoure/combineShader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ export const combinationEntryFn = tgpu['~unstable']
1616
.fragmentFn({
1717
in: { coord_f: d.builtin.position, uv: d.vec2f },
1818
out: d.vec4f,
19-
})
20-
.does(/* wgsl */ `(input: FragmentInput) -> @location(0) vec4f {
21-
let coord = vec2u(floor(input.coord_f.xy));
19+
})(/* wgsl */ `{
20+
let coord = vec2u(floor(in.coord_f.xy));
2221
2322
let blurred = textureLoad(
2423
blurredTexture,

apps/phoure-www/src/lib-phoure/menderStep.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ const entryComputeFn = tgpu['~unstable']
155155
in: {
156156
gid: d.builtin.globalInvocationId,
157157
},
158-
})
159-
.does(/* wgsl */ `(input: Input) {
158+
})(/* wgsl */ `{
160159
var result: array<f32, OUT_CHANNELS>;
160+
161161
for (var i = 0; i < OUT_CHANNELS; i += 1) {
162162
result[i] = biases[i];
163163
}
164164
165-
menderConvolveFn(input.gid.xy, &result);
165+
menderConvolveFn(in.gid.xy, &result);
166166
167167
if (reluSlot) {
168168
applyReLU(&result);
@@ -171,8 +171,8 @@ const entryComputeFn = tgpu['~unstable']
171171
let canvasSize = accessViewportSize;
172172
173173
let output_buffer_begin =
174-
(input.gid.y * u32(canvasSize.x) +
175-
input.gid.x) * OUT_CHANNELS;
174+
(in.gid.y * u32(canvasSize.x) +
175+
in.gid.x) * OUT_CHANNELS;
176176
177177
for (var i: u32 = 0; i < OUT_CHANNELS; i++) {
178178
output_buffer[output_buffer_begin + i] = result[i];

apps/phoure-www/src/lib/GameEngine/blipDifferenceStep/blipDifferenceStep.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@ type Options = {
99
textures: [() => GPUTextureView, () => GPUTextureView];
1010
};
1111

12-
const fragFn = tgpu['~unstable']
13-
.fragmentFn({ in: { coordFloat: d.builtin.position }, out: d.vec4f })
14-
.does(`(input: FragmentInput) -> @location(0) vec4f {
15-
var coord = vec2u(floor(input.coordFloat.xy));
12+
const fragFn = tgpu['~unstable'].fragmentFn({
13+
in: { coordFloat: d.builtin.position },
14+
out: d.vec4f,
15+
})(`{
16+
var coord = vec2u(floor(in.coordFloat.xy));
1617
17-
let color_a = textureLoad(
18-
texture_a,
19-
coord,
20-
0
21-
);
18+
let color_a = textureLoad(
19+
texture_a,
20+
coord,
21+
0
22+
);
2223
23-
let color_b = textureLoad(
24-
texture_b,
25-
coord,
26-
0
27-
);
24+
let color_b = textureLoad(
25+
texture_b,
26+
coord,
27+
0
28+
);
2829
29-
return vec4f(abs(color_a.rgb - color_b.rgb), 1.0);
30-
}`);
30+
return vec4f(abs(color_a.rgb - color_b.rgb), 1.0);
31+
}`);
3132

3233
export const BlipDifferenceStep = ({
3334
root,

apps/phoure-www/src/lib/GameEngine/gBufferDebugger.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const mainFragFn = tgpu['~unstable']
2222
.fragmentFn({
2323
in: { coord_f: d.builtin.position, uv: d.vec2f },
2424
out: d.vec4f,
25-
})
26-
.does(/* wgsl */ `(input: FragmentInput) -> @location(0) vec4f {
27-
let coord = vec2<i32>(floor(input.coord_f.xy));
25+
})(/* wgsl */ `{
26+
let coord = vec2<i32>(floor(in.coord_f.xy));
2827
let channel_mode = getChannelModeSlot();
2928
3029
let blurred = textureLoad(
@@ -48,7 +47,7 @@ const mainFragFn = tgpu['~unstable']
4847
4948
var result: vec4<f32>;
5049
51-
let c = input.uv;
50+
let c = in.uv;
5251
if (channel_mode == CHANNEL_SPLIT) {
5352
if (c.x < 0.33) {
5453
// NORMALS

apps/phoure-www/src/lib/GameEngine/postProcessingStep.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ const mainFragFn = tgpu['~unstable']
2121
.fragmentFn({
2222
in: { coord_f: d.builtin.position, uv: d.vec2f },
2323
out: d.vec4f,
24-
})
25-
.does(`(input: FragmentInput) -> @location(0) vec4f {
26-
var coord = vec2u(floor(input.coord_f.xy));
24+
})(`{
25+
var coord = vec2u(floor(in.coord_f.xy));
2726
2827
let color = textureLoad(
2928
sourceTexture,

apps/phoure-www/src/lib/GameEngine/sdfRenderer/sdfRenderer.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { convertRgbToY } from '@typegpu/color';
22
import { accessViewportSize } from '@typegpu/common';
3-
import { DefaultGenerator, rand } from '@typegpu/noise';
3+
import { randf } from '@typegpu/noise';
44
import { atom } from 'jotai';
55
import {
66
Camera,
@@ -50,8 +50,12 @@ export const accumulatedLayersAtom = atom(0);
5050
* @param mat_roughness
5151
*/
5252
const reflect = tgpu['~unstable']
53-
.fn([d.vec3f, d.vec3f, d.f32, d.ptrFn(d.f32)])
54-
.does(`(ray_dir: vec3f, normal: vec3f, mat_roughness: f32, out_roughness: ptr<function, f32>) -> vec3f {
53+
.fn([
54+
d.vec3f,
55+
d.vec3f,
56+
d.f32,
57+
d.ptrFn(d.f32),
58+
])(`(ray_dir: vec3f, normal: vec3f, mat_roughness: f32, out_roughness: ptr<function, f32>) -> vec3f {
5559
let slope = dot(ray_dir, normal);
5660
let dn2 = 2. * slope;
5761
let refl_dir = ray_dir - dn2 * normal;
@@ -64,7 +68,7 @@ const reflect = tgpu['~unstable']
6468
new_ray_dir = mix(refl_dir, new_ray_dir, roughness);
6569
return normalize(new_ray_dir);
6670
}`)
67-
.$uses({ randOnHemisphere: rand.onHemisphere })
71+
.$uses({ randOnHemisphere: randf.onHemisphere })
6872
.$name('reflect');
6973

7074
const renderSubPixel = tgpu['~unstable']
@@ -185,12 +189,11 @@ const mainComputeFn = tgpu['~unstable']
185189
.computeFn({
186190
workgroupSize: [BlockSize, BlockSize],
187191
in: { gid: d.builtin.globalInvocationId },
188-
})
189-
.does(/* wgsl */ `(input: Input) {
190-
setupRandomSeed(vec2f(input.gid.xy) * ${Math.random()} + getRandomSeedPrimer * ${Math.random()});
192+
})(/* wgsl */ `{
193+
setupRandomSeed(vec2f(in.gid.xy) * ${Math.random()} + getRandomSeedPrimer * ${Math.random()});
191194
192195
let prev_layers = getAccumulatedLayers;
193-
let prev_render = textureLoad(previousRender, input.gid.xy, 0);
196+
let prev_render = textureLoad(previousRender, in.gid.xy, 0);
194197
195198
var acc = vec3f(0., 0., 0.);
196199
for (var sx = 0u; sx < SUPER_SAMPLES; sx++) {
@@ -200,7 +203,7 @@ const mainComputeFn = tgpu['~unstable']
200203
(f32(sy) + 0.5) * ONE_OVER_SUPER_SAMPLES,
201204
);
202205
203-
acc += renderSubPixel(vec2f(input.gid.xy) + offset);
206+
acc += renderSubPixel(vec2f(in.gid.xy) + offset);
204207
}
205208
}
206209
@@ -215,14 +218,14 @@ const mainComputeFn = tgpu['~unstable']
215218
new_render = (prev_render * prev_layers + vec4(acc, 1.0)) / (prev_layers + 1);
216219
}
217220
218-
textureStore(mainOutput, input.gid.xy, new_render);
221+
textureStore(mainOutput, in.gid.xy, new_render);
219222
}`)
220223
.$uses({
221224
SUPER_SAMPLES,
222225
ONE_OVER_SUPER_SAMPLES,
223226
previousRender: mainLayout.bound.previousRender,
224227
mainOutput: mainLayout.bound.mainOutput,
225-
setupRandomSeed: DefaultGenerator.seed,
228+
setupRandomSeed: randf.seed2,
226229
renderSubPixel,
227230
getRandomSeedPrimer,
228231
getAccumulatedLayers,
@@ -238,8 +241,7 @@ const auxComputeFn = tgpu['~unstable']
238241
.computeFn({
239242
workgroupSize: [BlockSize, BlockSize],
240243
in: { gid: d.builtin.globalInvocationId },
241-
})
242-
.does(/* wgsl */ `(input: Input) {
244+
})(/* wgsl */ `{
243245
let offset = vec2f(
244246
0.5,
245247
0.5,
@@ -249,7 +251,7 @@ const auxComputeFn = tgpu['~unstable']
249251
var shape_ctx: ShapeContext;
250252
shape_ctx.rayPos = constructRayPos();
251253
shape_ctx.rayDir = constructRayDir(
252-
vec2f(input.gid.xy) + offset
254+
vec2f(in.gid.xy) + offset
253255
);
254256
shape_ctx.rayDistance = 0.;
255257
@@ -288,7 +290,7 @@ const auxComputeFn = tgpu['~unstable']
288290
289291
// TODO: maybe apply gamma correction to the albedo luminance parameter??
290292
291-
textureStore(auxOutput, input.gid.xy, aux);
293+
textureStore(auxOutput, in.gid.xy, aux);
292294
}`)
293295
.$uses({
294296
MAX_STEPS: MarchParams.maxSteps,
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
import tgpu from 'typegpu';
22
import { builtin, vec2f } from 'typegpu/data';
33

4-
export const fullScreenQuadVertexFn = tgpu['~unstable']
5-
.vertexFn({
6-
in: { idx: builtin.vertexIndex },
7-
out: { pos: builtin.position, uv: vec2f },
8-
})
9-
.does(/* wgsl */ `(input: VertexInput) -> VertexOutput {
10-
const SCREEN_RECT = array<vec2f, 6>(
11-
vec2f(-1.0, -1.0),
12-
vec2f(1.0, -1.0),
13-
vec2f(-1.0, 1.0),
4+
export const fullScreenQuadVertexFn = tgpu['~unstable'].vertexFn({
5+
in: { idx: builtin.vertexIndex },
6+
out: { pos: builtin.position, uv: vec2f },
7+
})(/* wgsl */ `{
8+
const SCREEN_RECT = array<vec2f, 6>(
9+
vec2f(-1.0, -1.0),
10+
vec2f(1.0, -1.0),
11+
vec2f(-1.0, 1.0),
1412
15-
vec2f(1.0, -1.0),
16-
vec2f(-1.0, 1.0),
17-
vec2f(1.0, 1.0),
18-
);
13+
vec2f(1.0, -1.0),
14+
vec2f(-1.0, 1.0),
15+
vec2f(1.0, 1.0),
16+
);
1917
20-
const UVS = array<vec2f, 6>(
21-
vec2f(0.0, 1.0),
22-
vec2f(1.0, 1.0),
23-
vec2f(0.0, 0.0),
18+
const UVS = array<vec2f, 6>(
19+
vec2f(0.0, 1.0),
20+
vec2f(1.0, 1.0),
21+
vec2f(0.0, 0.0),
2422
25-
vec2f(1.0, 1.0),
26-
vec2f(0.0, 0.0),
27-
vec2f(1.0, 0.0),
28-
);
23+
vec2f(1.0, 1.0),
24+
vec2f(0.0, 0.0),
25+
vec2f(1.0, 0.0),
26+
);
2927
30-
var output: VertexOutput;
31-
output.pos = vec4f(SCREEN_RECT[input.idx], 0.0, 1.0);
32-
output.uv = UVS[input.idx];
33-
return output;
34-
}`);
28+
var output: Out;
29+
output.pos = vec4f(SCREEN_RECT[in.idx], 0.0, 1.0);
30+
output.uv = UVS[in.idx];
31+
return output;
32+
}`);

0 commit comments

Comments
 (0)