Skip to content

Commit c8fdf42

Browse files
committed
refactor(StarsShader): mount only once & minor fixes
1 parent 69a01f2 commit c8fdf42

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/assets/shaders/stars.fragment.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ vec3 Unity_Blackbody_float(float Temperature) {
4040
}
4141

4242
void main() {
43-
const float stars_threshold = 8.0; // modifies the number of stars that are visible
43+
const float stars_threshold = 10.0; // modifies the number of stars that are visible
4444
const float stars_exposure = 500.0; // modifies the overall strength of the stars
4545

4646
// Normalized pixel coordinates (from 0 to 1)

src/components/misc/ShaderContainer.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
22
/** biome-ignore-all lint/style/noNonNullAssertion: ignore */
33
4+
import { onMount } from "svelte";
5+
46
interface Props {
57
fragmentShader: string;
68
followReducedAnimation?: boolean;
@@ -15,7 +17,8 @@ let {
1517
1618
let canvas: HTMLCanvasElement;
1719
18-
$effect(() => {
20+
onMount(() => {
21+
let cancel = false;
1922
let gl: WebGLRenderingContext;
2023
let u_resolution: WebGLUniformLocation;
2124
let u_time: WebGLUniformLocation;
@@ -91,13 +94,18 @@ $effect(() => {
9194
init();
9295
canvas.setAttribute("style", "opacity: unset");
9396
frame = requestAnimationFrame(function loop(time) {
97+
if (cancel) return;
9498
frame = requestAnimationFrame(loop);
9599
96100
gl.uniform2f(u_resolution, canvas.width, canvas.height);
97101
gl.uniform1f(u_time, time / 1000.0);
98102
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
99103
});
100104
});
105+
106+
return () => {
107+
cancel = true;
108+
};
101109
});
102110
</script>
103111

src/pages/about.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const { Content } = await render(aboutPost);
2121
<div class="flex w-full rounded-[var(--radius-large)] overflow-hidden relative min-h-32">
2222
<div class="card-base relative w-full z-10">
2323
<DarkThemeContainer client:load>
24-
<ShaderContainer client:only fragmentShader={starsShader} class="w-full h-full absolute -z-[50]"/>
24+
<ShaderContainer client:only fragmentShader={starsShader} class="w-full h-full absolute"/>
2525
</DarkThemeContainer>
2626
<Markdown class="mt-2 px-9 py-6">
2727
<Content />

0 commit comments

Comments
 (0)