Skip to content

Commit 361a5ff

Browse files
committed
camera Position, Direction and FOV available in shaders, WIP Volume Raymarching Praktikum
1 parent f939553 commit 361a5ff

File tree

6 files changed

+287
-200
lines changed

6 files changed

+287
-200
lines changed

src/App.css

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,6 @@
22
@plugin "@tailwindcss/typography";
33
@import 'katex/dist/katex.min.css';
44

5-
/* Ensure inner scroll works nicely */
6-
.prose {
7-
max-width: 100%;
8-
min-width: 0;
9-
overflow-wrap: break-word;
10-
word-wrap: break-word;
11-
box-sizing: border-box;
12-
}
13-
14-
/* KaTeX horizontal scroll */
15-
.prose .katex-display {
16-
overflow-x: auto;
17-
overflow-y: hidden;
18-
max-width: 100%;
19-
margin: 1em 0;
20-
}
21-
.prose .katex {
22-
font-size: 1em;
23-
white-space: normal;
24-
}
25-
.prose .katex .katex-html {
26-
white-space: normal;
27-
max-width: 100%;
28-
overflow-wrap: break-word;
29-
}
30-
.prose .katex-display > .katex {
31-
display: inline-block;
32-
max-width: 100%;
33-
text-align: left;
34-
}
35-
36-
/* Code blocks */
37-
.prose pre {
38-
max-width: 100%;
39-
overflow-x: auto;
40-
white-space: pre-wrap;
41-
word-break: break-all;
42-
}
43-
.prose code {
44-
max-width: 100%;
45-
overflow-wrap: break-word;
46-
word-break: break-all;
47-
}
48-
49-
/* Tables */
50-
.prose table {
51-
display: block;
52-
max-width: 100%;
53-
overflow-x: auto;
54-
}
55-
56-
/* Images & embedded content */
57-
.prose img,
58-
.prose iframe,
59-
.prose video,
60-
.prose embed,
61-
.prose object {
62-
max-width: 100%;
63-
height: auto;
64-
}
65-
66-
/* Very long words */
67-
.prose p,
68-
.prose li,
69-
.prose td,
70-
.prose th {
71-
overflow-wrap: break-word;
72-
word-break: break-word;
73-
hyphens: auto;
74-
}
75-
76-
/* Smooth scrolling for inner scroll */
77-
.flex-1.overflow-y-auto {
78-
-webkit-overflow-scrolling: touch;
79-
}
80-
815
@custom-variant dark (&:is(.dark *));
826

837
@font-face {

src/lib/components/ShaderPreview.svelte

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
camera.position.set(0, 0, 1);
3636
camera.aspect = aspect;
3737
camera.updateProjectionMatrix();
38-
if (!sharedCameraRef) sharedCameraRef = camera;
38+
if (!sharedCameraRef)
39+
sharedCameraRef = camera;
3940
4041
// Renderer
4142
renderer = new THREE.WebGLRenderer({
@@ -83,13 +84,22 @@
8384
animate();
8485
}
8586
86-
// --- Animate loop ---
87+
// Call every frame
8788
function animate() {
8889
animationFrameId = requestAnimationFrame(animate);
8990
if (!renderer || !scene || !camera) return;
9091
92+
// Update Shader Uniforms
9193
controls?.update();
92-
if (shaderMaterial) shaderMaterial.uniforms.time.value = clock.getElapsedTime();
94+
if (shaderMaterial) {
95+
// Update Time
96+
shaderMaterial.uniforms.time.value = clock.getElapsedTime();
97+
98+
// Update Camera Position, Direction and FOV
99+
shaderMaterial.uniforms.cameraPosition.value.copy(camera.position);
100+
shaderMaterial.uniforms.cameraDirection.value.copy(camera.getWorldDirection(new THREE.Vector3()));
101+
shaderMaterial.uniforms.cameraFov.value = camera.fov * (Math.PI / 180); // convert degrees to radians
102+
}
93103
94104
renderer.render(scene, camera);
95105
}
@@ -139,6 +149,9 @@
139149
iResolution: {
140150
value: new THREE.Vector2(container.clientWidth * window.devicePixelRatio, container.clientHeight * window.devicePixelRatio)
141151
},
152+
cameraFov: { value: camera.fov * (Math.PI / 180) }, // convert degrees to radians
153+
cameraPosition: { value: camera.position.clone() },
154+
cameraDirection: { value: camera.getWorldDirection(new THREE.Vector3()) },
142155
},
143156
glslVersion: THREE.GLSL3,
144157
});

src/lib/components/TaskPanel.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<div class="h-full flex flex-col overflow-hidden">
2121
<!-- Header -->
22-
<div class="flex items-center justify-between p-6 flex-shrink-0">
22+
<div class="flex items-center justify-between p-6 shrink-0">
2323
{#if $taskStore?.task}
2424
<h1 class="text-2xl font-bold text-foreground">
2525
{$taskStore.task.title}

src/lib/data/tasks.json

Lines changed: 11 additions & 13 deletions
Large diffs are not rendered by default.

src/lib/data/tasks/SDFCircle.md

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)