Skip to content

Commit 1f70417

Browse files
committed
Update to typegpu 0.5.9
1 parent d1ab7d7 commit 1f70417

File tree

5 files changed

+55
-72
lines changed

5 files changed

+55
-72
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.7",
31+
"@typegpu/noise": "^0.0.9",
3232
"@typegpu/sdf": "workspace:*",
3333
"@types/react": "^18.0.2",
3434
"@types/react-dom": "^18.0.2",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export const accumulatedLayersAtom = atom(0);
5151
* @param mat_roughness
5252
*/
5353
const reflect = tgpu['~unstable']
54-
.fn([d.vec3f, d.vec3f, d.f32, d.ptrFn(d.f32)])(
55-
`(rayDir: vec3f, normal: vec3f, matRoughness: f32, outRoughness: ptr<function, f32>) -> vec3f {
54+
.fn([d.vec3f, d.vec3f, d.f32, d.ptrFn(d.f32)], d.vec3f)(
55+
`(rayDir, normal, matRoughness, outRoughness) {
5656
let slope = dot(rayDir, normal);
5757
let dn2 = 2. * slope;
5858
let refl_dir = rayDir - dn2 * normal;

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

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { sphere } from '@typegpu/sdf';
22
import { MarchParams, ShapeContext } from 'src/lib-ray-marching';
33
import tgpu, { type TgpuFnShell } from 'typegpu';
44
import * as d from 'typegpu/data';
5-
import { min, mul } from 'typegpu/std';
5+
import { abs, floor, min, mix, mul, pow } from 'typegpu/std';
66

77
export const Material = d.struct({
88
albedo: d.vec3f,
@@ -43,17 +43,13 @@ const objFloor = sdfShell((pos) => {
4343
});
4444

4545
const matFloor = tgpu['~unstable']
46-
.fn([
47-
d.vec3f,
48-
d.ptrFn(Material),
49-
])(/* wgsl */ `(pos: vec3f, mtr: ptr<function, Material>) {
50-
let uv = floor(5.0 * pos.xz);
51-
let c = 0.2 + 0.5 * ((uv.x + uv.y) - 2.0 * floor((uv.x + uv.y) / 2.0));
46+
.fn([d.vec3f, d.ptrFn(Material)])((pos, mtr) => {
47+
const uv = floor(mul(5, pos.xz));
48+
const c = 0.2 + 0.5 * ((uv.x + uv.y) - 2.0 * floor((uv.x + uv.y) / 2.0));
5249

53-
(*mtr).albedo = mix(vec3(1., 1., 1.), vec3(0., 0., 0.), c);
54-
(*mtr).roughness = 0.9;
55-
}`)
56-
.$uses({ Material })
50+
mtr.albedo = mix(d.vec3f(1., 1., 1.), d.vec3f(0., 0., 0.), c);
51+
mtr.roughness = 0.9;
52+
})
5753
.$name('mat_floor');
5854

5955
export const FAR = 100;
@@ -72,21 +68,10 @@ export const worldSdf = sdfShell((pos) => {
7268

7369
// MATERIALS
7470

75-
export const skyColor = tgpu['~unstable'].fn(
76-
[d.vec3f],
77-
d.vec3f,
78-
)(/* wgsl */ `(dir: vec3f) -> vec3f {
79-
let t = pow(min(abs(dir.y) * 4, 1.), 0.4);
80-
81-
let uv = floor(30.0 * dir.xy);
82-
let c = 0.2 + 0.5 * ((uv.x + uv.y) - 2.0 * floor((uv.x + uv.y) / 2.0));
83-
84-
return mix(
85-
vec3f(0.7, 0.7, 0.75), // horizon
86-
vec3f(0.35, 0.4, 0.6),
87-
t,
88-
);
89-
}`);
71+
export const skyColor = tgpu['~unstable'].fn([d.vec3f], d.vec3f)((dir) => {
72+
const t = pow(min(abs(dir.y) * 4, 1.), 0.4);
73+
return mix(d.vec3f(0.7, 0.7, 0.75), d.vec3f(0.35, 0.4, 0.6), t);
74+
});
9075

9176
export const worldMat = tgpu['~unstable']
9277
.fn([d.vec3f, ShapeContext, d.ptrFn(Material)])((pos, ctx, out) => {

pnpm-lock.yaml

Lines changed: 39 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ packages:
44

55
# Define a catalog of version ranges.
66
catalog:
7-
typegpu: https://pkg.pr.new/software-mansion/TypeGPU/typegpu@4b33dc38310dd6df3d00f3ddc6cc4bae09bfd3d8
8-
unplugin-typegpu: ^0.1.1
7+
typegpu: ^0.5.9
8+
unplugin-typegpu: ^0.1.4

0 commit comments

Comments
 (0)