2
2
3
3
import type { PropsWithChildren } from "react" ;
4
4
import { cn } from "#/lib/cn" ;
5
+ import { getDevicePixelRatio } from "#/lib/get-device-pixel-ratio" ;
5
6
import glsl from "dedent" ;
6
7
import { Mesh , Program , Renderer , Triangle , Vec2 , Vec3 } from "ogl" ;
7
8
import { useEffect , useRef } from "react" ;
@@ -210,11 +211,6 @@ function createRenderer(canvas: HTMLCanvasElement, width: number, height: number
210
211
} ) ;
211
212
}
212
213
213
- function getDevicePixelRatio ( precision = 3 ) {
214
- const factor = Math . pow ( 10 , precision ) ;
215
- return Math . round ( window . devicePixelRatio * factor ) / factor ;
216
- }
217
-
218
214
export type EffectLayerProps = PropsWithChildren < {
219
215
className ?: string ;
220
216
} > ;
@@ -233,7 +229,7 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
233
229
const canvas = rCanvas . current ;
234
230
const rect = root . getBoundingClientRect ( ) ;
235
231
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 ) ) ;
237
233
238
234
const { gl } = renderer ;
239
235
const geometry = new Triangle ( gl ) ;
@@ -248,7 +244,7 @@ export function EffectLayer({ children, className }: EffectLayerProps) {
248
244
function update ( time : number ) {
249
245
if ( ! isActive . current ) return ;
250
246
uniforms . uTime . value = time * 0.001 ;
251
- renderer . dpr = getDevicePixelRatio ( ) ;
247
+ renderer . dpr = getDevicePixelRatio ( 2 ) ;
252
248
renderer . render ( { scene : mesh } ) ;
253
249
rRaf . current = requestAnimationFrame ( update ) ;
254
250
}
0 commit comments