Skip to content

Commit 90aa897

Browse files
committed
Merge branch 'release'
2 parents d90c703 + 8678073 commit 90aa897

4 files changed

Lines changed: 58 additions & 8 deletions

File tree

apps/typegpu-docs/src/components/shaderhunt/ChallengesSignupPopover.astro

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,38 @@
9898

9999
const dialogBoxes = Array.from(popovers).map((popover) => new DialogBox(popover));
100100

101+
function isElementVisible(element: Element): boolean {
102+
// Check if the element or any of its ancestors have display: none
103+
let current: Element | null = element;
104+
while (current) {
105+
const style = window.getComputedStyle(current);
106+
if (style.display === 'none') {
107+
return false;
108+
}
109+
current = current.parentElement;
110+
}
111+
return true;
112+
}
113+
114+
function getVisibleDialogBox(): DialogBox | undefined {
115+
// Find a dialog box whose link element is actually visible
116+
for (let i = 0; i < dialogBoxes.length; i++) {
117+
const popover = popovers[i];
118+
const linkElement = popover?.querySelector('a');
119+
if (linkElement && isElementVisible(linkElement)) {
120+
return dialogBoxes[i];
121+
}
122+
}
123+
// Fallback to first dialog box if none are visibly rendered
124+
return dialogBoxes[0];
125+
}
126+
101127
// Check if URL hash indicates popover should be open
102128
if (window.location.hash === '#challenges-signup') {
103-
const firstDialogBox = dialogBoxes[0]
104-
if (!firstDialogBox) {
129+
const visibleDialogBox = getVisibleDialogBox();
130+
if (!visibleDialogBox) {
105131
throw new Error('Expected at least one dialog box');
106132
}
107-
firstDialogBox.dialogElement.showModal();
133+
visibleDialogBox.dialogElement.showModal();
108134
}
109135
</script>

apps/typegpu-docs/src/examples/common/setup-orbit-camera.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const Camera = d.struct({
66
targetPos: d.vec4f,
77
view: d.mat4x4f,
88
projection: d.mat4x4f,
9+
viewInverse: d.mat4x4f,
10+
projectionInverse: d.mat4x4f,
911
});
1012

1113
export interface CameraOptions {
@@ -56,11 +58,16 @@ export function setupOrbitCamera(
5658
cameraState.pitch = Math.asin(cameraVector.y / cameraState.radius);
5759
cameraState.target = tgt;
5860

61+
const view = calculateView(newPos, cameraState.target);
62+
const projection = calculateProj(canvas.clientWidth / canvas.clientHeight);
63+
5964
callback(Camera({
6065
position: newPos,
6166
targetPos: cameraState.target,
62-
view: calculateView(newPos, cameraState.target),
63-
projection: calculateProj(canvas.clientWidth / canvas.clientHeight),
67+
view,
68+
projection,
69+
viewInverse: invertMat(view),
70+
projectionInverse: invertMat(projection),
6471
}));
6572
}
6673

@@ -82,8 +89,11 @@ export function setupOrbitCamera(
8289
cameraState.yaw,
8390
);
8491

92+
const newView = calculateView(newCameraPos, cameraState.target);
93+
8594
callback({
86-
view: calculateView(newCameraPos, cameraState.target),
95+
view: newView,
96+
viewInverse: invertMat(newView),
8797
position: newCameraPos,
8898
});
8999
}
@@ -104,13 +114,17 @@ export function setupOrbitCamera(
104114
);
105115
const newView = calculateView(newPos, cameraState.target);
106116

107-
callback({ view: newView, position: newPos });
117+
callback({
118+
view: newView,
119+
viewInverse: invertMat(newView),
120+
position: newPos,
121+
});
108122
}
109123

110124
// resize observer
111125
const resizeObserver = new ResizeObserver(() => {
112126
const projection = calculateProj(canvas.clientWidth / canvas.clientHeight);
113-
callback({ projection });
127+
callback({ projection, projectionInverse: invertMat(projection) });
114128
});
115129
resizeObserver.observe(canvas);
116130

@@ -236,3 +250,7 @@ function calculateView(position: d.v4f, target: d.v4f) {
236250
function calculateProj(aspectRatio: number) {
237251
return m.mat4.perspective(Math.PI / 4, aspectRatio, 0.1, 1000, d.mat4x4f());
238252
}
253+
254+
function invertMat(matrix: d.m4x4f) {
255+
return m.mat4.invert(matrix, d.mat4x4f());
256+
}

packages/typegpu/tests/examples/individual/gravity.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ describe('gravity example', () => {
181181
targetPos: vec4f,
182182
view: mat4x4f,
183183
projection: mat4x4f,
184+
viewInverse: mat4x4f,
185+
projectionInverse: mat4x4f,
184186
}
185187
186188
@group(0) @binding(0) var<uniform> camera: Camera;
@@ -234,6 +236,8 @@ describe('gravity example', () => {
234236
targetPos: vec4f,
235237
view: mat4x4f,
236238
projection: mat4x4f,
239+
viewInverse: mat4x4f,
240+
projectionInverse: mat4x4f,
237241
}
238242
239243
@group(0) @binding(0) var<uniform> camera_1: Camera;

packages/typegpu/tests/examples/individual/phong-reflection.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ describe('phong reflection example', () => {
3232
targetPos: vec4f,
3333
view: mat4x4f,
3434
projection: mat4x4f,
35+
viewInverse: mat4x4f,
36+
projectionInverse: mat4x4f,
3537
}
3638
3739
@group(0) @binding(0) var<uniform> cameraUniform: Camera;

0 commit comments

Comments
 (0)