Skip to content

Commit 2d69f58

Browse files
committed
chore: minor improvements
1 parent fdea030 commit 2d69f58

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

apps/website/components/EffectLayer.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import type { PropsWithChildren } from "react";
44
import { cn } from "#/lib/cn";
5+
import { getDevicePixelRatio } from "#/lib/get-device-pixel-ratio";
56
import glsl from "dedent";
67
import { Mesh, Program, Renderer, Triangle, Vec2, Vec3 } from "ogl";
78
import { useEffect, useRef } from "react";
@@ -210,11 +211,6 @@ function createRenderer(canvas: HTMLCanvasElement, width: number, height: number
210211
});
211212
}
212213

213-
function getDevicePixelRatio(precision = 3) {
214-
const factor = Math.pow(10, precision);
215-
return Math.round(window.devicePixelRatio * factor) / factor;
216-
}
217-
218214
export type EffectLayerProps = PropsWithChildren<{
219215
className?: string;
220216
}>;
@@ -233,7 +229,7 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
233229
const canvas = rCanvas.current;
234230
const rect = root.getBoundingClientRect();
235231
const uniforms = createUniforms(rect.width, rect.height);
236-
const renderer = createRenderer(canvas, rect.width, rect.height, getDevicePixelRatio());
232+
const renderer = createRenderer(canvas, rect.width, rect.height, getDevicePixelRatio(2));
237233

238234
const { gl } = renderer;
239235
const geometry = new Triangle(gl);
@@ -248,7 +244,7 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
248244
function update(time: number) {
249245
if (!isActive.current) return;
250246
uniforms.uTime.value = time * 0.001;
251-
renderer.dpr = getDevicePixelRatio();
247+
renderer.dpr = getDevicePixelRatio(2);
252248
renderer.render({ scene: mesh });
253249
rRaf.current = requestAnimationFrame(update);
254250
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function getDevicePixelRatio(fallback = 2, precision = 3) {
2+
if (typeof window === "undefined") return fallback;
3+
const factor = Math.pow(10, precision);
4+
return Math.round(window.devicePixelRatio * factor) / factor;
5+
}

0 commit comments

Comments
 (0)