Guide · Web 3D

설치 없이 웹에서 즐기는
3D 인터랙티브 게임의 원리

링크 하나를 누르면 3D 무대가 열리고, 음악에 맞춰 노트가 날아옵니다. 설치도, 다운로드도 없습니다. 어떻게 이런 일이 가능할까요? 이 글은 브라우저 3D 게임이 돌아가는 순서를 직접 만든 4레인 리듬게임을 예로 들어 설명합니다.

쿵이가족 2026년 11월 26일 약 9분
Advertisement
핵심 요약 · TL;DR
  • 구조: 브라우저 3D는 WebGL(최신은 WebGPU)로 그리기를 GPU에 맡기고, 실무에서는 three.js 같은 라이브러리로 장면을 다룹니다.
  • 성능: 60fps는 프레임당 16.7ms 예산입니다. 그리기 호출 수, 해상도 배율(DPR), 실시간 그림자가 가장 큰 비용입니다.
  • 판정: 리듬게임은 오디오 시계를 기준으로 시간을 재야 합니다. 블루투스 이어폰의 100~300ms 지연은 판정을 밀리게 합니다.
  • 자동 채보: 온셋 검출 + 적응 임계값 + 최소 간격(0.125초)으로 손이 따라갈 수 있는 밀도로 줄입니다.
  • 3D 위 버튼: 판정선의 3D 좌표를 매 프레임 화면 좌표로 투영해야 버튼과 노트가 어긋나지 않습니다.

① 3D가 화면에 나오기까지

브라우저에서 3D를 그리는 일은 WebGL(또는 최신 WebGPU)이 맡습니다. 자바스크립트가 “이 위치에 이 모양을 그려라”라고 명령하면, 그 명령이 GPU로 넘어가 수백만 개의 픽셀을 한 번에 계산합니다. CPU가 픽셀을 하나씩 칠하면 불가능한 일이, GPU에서는 순식간에 끝납니다.

다만 WebGL은 다루기가 꽤 번거롭습니다. 그래서 대부분은 three.js 같은 라이브러리를 씁니다. 장면(scene), 카메라(camera), 조명(light), 재질(material)을 객체로 만들어 두면, 라이브러리가 알아서 GPU 명령으로 바꿔 줍니다. 우리 게임도 이 방식으로 무대를 구성합니다.

// 개념을 보여 주는 최소 예시
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });

function frame(now) {
  // 1) 움직임 계산  2) 그리기
  cube.rotation.y += 0.01;
  renderer.render(scene, camera);
  requestAnimationFrame(frame);   // 다음 화면 갱신 요청
}
requestAnimationFrame(frame);

핵심은 마지막 두 줄입니다. 브라우저는 화면을 다시 그릴 때마다 함수를 불러 주고, 우리는 그 안에서 움직임과 그리기를 처리합니다. 이 반복을 프레임 루프라고 부릅니다.

② 16.7ms의 예산 — 60fps의 의미

화면이 1초에 60번 바뀌면 한 번 그리는 데 쓸 수 있는 시간은 약 16.7ms입니다. 이 안에 계산·충돌 판정·그리기를 모두 끝내야 부드럽게 보입니다. 넘기면 화면이 끊기고, 리듬게임에서는 그 끊김이 곧 판정 오차가 됩니다.

비용이 큰 작업왜 비싼가줄이는 방법
그리기 호출(draw call) 수물체마다 CPU·GPU 대화가 필요같은 재질·모양은 묶어서 한 번에(인스턴싱)
높은 해상도(DPR)픽셀 수가 4배면 GPU 부담도 크게 증가기기 해상도 배율을 1.5~2로 제한
실시간 그림자그림자 맵을 한 번 더 렌더링저사양 기기에서는 그림자 끄기
파티클 수수천 개를 매번 새로 만들면 메모리·GC 부담미리 만들어 두고 재사용(오브젝트 풀)
투명·블러 효과겹칠수록 채우기 비용 증가겹침 수를 줄이고 CSS로 대체

리듬게임에서는 여기에 하나가 더 붙습니다. 노트가 수백 개 날아오기 때문에, 화면에 보이지 않는 노트는 아예 계산하지 않도록 “지금 판정 구간의 노트만 갱신”하는 방식이 필요합니다. 이렇게 하면 곡이 5분이어도 프레임 비용은 거의 일정하게 유지됩니다.

③ 3D 위에 버튼을 정확히 얹는 법

리듬게임에서 가장 중요한 것은 “내가 누른 곳”과 “노트가 도착한 곳”이 같은 좌표라는 사실입니다. 그런데 3D 공간의 판정선은 카메라 각도에 따라 화면에서 위치가 계속 바뀝니다. 버튼을 화면 아래에 고정해 두면, 카메라를 조금만 돌려도 버튼과 판정선이 어긋납니다.

해결은 투영(projection)입니다. 3D 좌표를 카메라 행렬로 변환해 화면 좌표로 바꾸는 계산을 매 프레임 수행하고, 그 결과를 버튼의 위치로 씁니다.

// 3D 판정 지점 → 화면 좌표(px)
const v = new THREE.Vector3(laneX, padY, judgeZ).project(camera);
const x = (v.x * 0.5 + 0.5) * innerWidth;
const y = (-v.y * 0.5 + 0.5) * innerHeight;
pad.style.transform = `translate(${x}px, ${y}px)`;

이 한 줄 덕분에 카메라를 돌려도 패드가 판정선 위에 딱 붙어 있습니다. 여기에 누를 때마다 판정 지점에서 물방울 파동을 터뜨리는 연출을 더하면, “내 입력이 무대에 닿았다”는 감각이 생깁니다. 리듬게임의 손맛은 대개 이런 작은 일치에서 나옵니다.

④ 음악과 시간을 맞추는 일

판정의 기준은 “지금 몇 초인가”입니다. 그런데 브라우저에서 시간을 재는 방법은 여러 가지이고, 서로 조금씩 어긋납니다.

  • performance.now() — 정확하지만 오디오와 무관합니다.
  • audio.currentTime — 실제 재생 위치지만, 읽는 순간의 값이 프레임 사이에서 튈 수 있습니다.
  • Web Audio의 시계 — 오디오 장치의 실제 샘플 위치를 기준으로 하므로 드리프트가 가장 적습니다.

그래서 리듬게임은 보통 오디오 시계를 기준으로 삼고, 화면 갱신 사이의 시간을 보간합니다. 판정 창도 여기에 맞춰 밀리초 단위로 정합니다. 우리 게임은 Perfect ±85ms, Great ±155ms, Good ±230ms를 씁니다. 사람이 “동시에”라고 느끼는 범위가 대략 ±30~50ms이고, 그보다 넓게 잡아야 초보자도 즐길 수 있습니다.

블루투스 이어폰이 위험한 이유. 소리는 기기에서 나가 이어폰에 도착하기까지 100~300ms가 걸립니다. 화면은 이미 지나갔는데 소리는 나중에 들리니, 아무리 정확히 눌러도 판정이 밀립니다. 그래서 기록 도전에는 유선 이어폰이나 스피커를 권합니다.
Advertisement

⑤ 음악이 채보가 되기까지

채보를 사람이 미리 만들지 않고 실시간으로 뽑는 방식은 생각보다 단순한 원리로 동작합니다. 순서는 이렇습니다.

  1. 소리를 잘게 나눈다. 짧은 구간(예: 1024~2048 샘플)마다 주파수 성분을 계산합니다(FFT).
  2. 대역별 에너지를 잰다. 저역·중역·고역으로 나눠 각각의 세기를 기록합니다.
  3. 변화량을 본다. 직전 구간보다 에너지가 갑자기 늘면 ‘새 소리가 시작됐다’고 판단합니다(스펙트럴 플럭스).
  4. 주변과 비교해 거른다. 국소 중앙값을 기준으로 약한 잔향·노이즈를 버립니다(적응 임계값).
  5. 연주 가능하게 줄인다. 세기가 약한 하위 40%를 자르고, 노트 사이 최소 간격(0.125초)을 둡니다.
  6. 레인을 배정한다. 저역이 강한 타격은 바깥 레인, 고역이 강한 타격은 안쪽 레인으로 보내고, 한쪽으로 몰리지 않게 비율을 조정합니다.

이 방식의 장점은 어떤 곡이든 바로 플레이할 수 있다는 것입니다. 단점은 곡의 ‘의도된 리듬’을 완벽히 재현하지는 못한다는 점입니다. 사람이 만든 채보는 멜로디 라인까지 살리지만, 자동 채보는 주로 타격음을 따라갑니다. 그래서 드럼과 베이스가 또렷한 곡이 손맛이 좋고, 잔향이 많은 발라드는 노트가 적게 나옵니다.

⑥ 모바일에서 버티게 만드는 조건

실제 접속자의 절반 이상은 폰으로 들어옵니다. 데스크톱에서 잘 돌던 게임도 폰에서는 세 가지에서 무너집니다.

1) 화면이 좁다

가로 화면 기준으로 만든 4레인은 세로 화면에서 손가락 두 개가 겹칩니다. 그래서 세로일 때는 판정 바와 패드 위치를 다시 배치하고, 카메라 거리를 조정합니다. CSS의 env(safe-area-inset-*)도 함께 써야 노치나 홈 바에 버튼이 가리지 않습니다.

2) 성능이 낮다

해상도 배율을 1.5~2로 제한하고, 그림자와 안티앨리어싱을 끄고, 파티클 수를 줄입니다. 기기 성능을 직접 재기 어려우므로 matchMedia('(pointer: coarse)')와 화면 크기로 대략 판단해 처음부터 낮은 설정으로 시작하는 편이 안전합니다.

3) 배터리와 발열

3D는 GPU를 계속 쓰기 때문에 10분만 해도 폰이 뜨거워집니다. 화면이 가려졌을 때 requestAnimationFrame을 멈추고, 곡이 끝나면 루프를 정지시키는 처리만으로도 체감이 달라집니다.

직접 만들어 보고 싶다면

순서를 지키면 멀리 돌아가지 않습니다. 아래는 제가 실제로 권하는 학습 순서입니다.

  1. HTML/CSS/자바스크립트 기본 — 이벤트, 비동기, 배열 처리까지.
  2. three.js 튜토리얼 — 상자 하나를 회전시키고, 카메라를 움직여 보기.
  3. Web Audio — 소리를 재생하고, 분석기(AnalyserNode)로 스펙트럼 읽기.
  4. 작은 게임 하나 완성 — 3D 없이 2D로 만든 뒤 3D로 옮기는 편이 쉽습니다.
  5. 배포 — 정적 파일만으로도 GitHub Pages 같은 무료 호스팅에 올릴 수 있습니다.
가장 흔한 실수. 3D부터 꾸미려는 것입니다. 판정·점수·재시작 같은 게임의 뼈대를 먼저 만들고, 그 위에 조명과 파티클을 얹으세요. 순서를 바꾸면 예쁜데 안 되는 것을 오래 붙잡게 됩니다.

자주 묻는 질문

웹 게임은 앱보다 느리지 않나요?

간단한 3D라면 체감 차이가 거의 없습니다. 다만 첫 로딩에서 엔진과 리소스를 받아야 하므로, 파일 크기를 줄이는 것이 중요합니다. 두 번째 방문부터는 캐시로 빨라집니다.

아이폰에서도 잘 돌아가나요?

최신 Safari는 WebGL을 지원합니다. 다만 메모리 제한이 엄격해서 큰 텍스처를 여러 개 쓰면 탭이 새로고침될 수 있습니다. 텍스처 크기와 동시 로딩 수를 줄이는 것이 안전합니다.

음악 파일을 넣으면 서버로 올라가나요?

구현에 따라 다릅니다. 저희 게임은 브라우저 안에서만 파일을 읽고 분석하며 서버로 전송하지 않습니다. 다른 서비스를 쓸 때는 개인정보처리방침에서 확인하세요.

코드를 꼭 알아야 만들 수 있나요?

게임 제작 도구를 쓰면 코드 없이도 만들 수 있습니다. 다만 세부 조정(판정 폭, 카메라 각도, 레인 배치)은 코드를 다룰 때 훨씬 자유롭습니다.

쿵이가족

브라우저에서 도는 게임과 영상을 직접 만들며 남긴 기록입니다. 궁금한 점은 문의하기로 보내 주세요.

함께 보면 좋은 글

Advertisement
Guide · Web 3D

How browser 3D games work
with no install at all

A 3D rhythm game opens from a link, analyses your music and runs on a phone. Underneath that is a chain of plain engineering decisions: frame budgets, projection, audio clocks and note generation. This guide walks through the pieces that actually decide whether it feels good.

Koong Family 26 November 2026 9 min
Advertisement
TL;DR
  • Structure: WebGL (now also WebGPU) hands drawing to the GPU; in practice a library such as three.js manages the scene.
  • Performance: 60 fps means a 16.7 ms budget per frame. Draw calls, resolution scale (DPR) and real-time shadows cost the most.
  • Timing: a rhythm game must measure time against the audio clock. Bluetooth earphones add 100–300 ms and push every judgement late.
  • Auto-charting: onset detection + adaptive threshold + a 0.125 s minimum gap keeps the note density playable.
  • Buttons over 3D: the judge line’s 3D position must be projected to screen space every frame, or buttons drift away from the notes.

1. How 3D reaches the screen

Drawing 3D in a browser is the job of WebGL (and now WebGPU). JavaScript says “draw this shape at this position” and the instruction goes to the GPU, which computes millions of pixels at once. What would be impossible pixel by pixel on a CPU is instant on a GPU.

WebGL itself is fiddly, so most projects use a library such as three.js. Scene, camera, lights and materials become objects, and the library turns them into GPU commands. Our game builds its stage the same way.

// Minimal example of the concept
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
function frame(now) {
  // 1) update motion  2) draw
  cube.rotation.y += 0.01;
  renderer.render(scene, camera);
  requestAnimationFrame(frame);   // ask for the next frame
}
requestAnimationFrame(frame);

The last two lines are the point. The browser calls your function every time it repaints, and you handle motion and drawing inside it. That loop is what everyone calls the frame loop.

2. The 16.7 ms budget — what 60 fps means

At 60 refreshes a second, one frame gets about 16.7 ms. Physics, collisions and drawing all have to finish inside it to look smooth. Overrun and the image stutters; in a rhythm game that stutter is a timing error.

Expensive workWhy it costsHow to cut it
Draw callsEvery object is a CPU–GPU conversationBatch identical materials and shapes (instancing)
High resolution (DPR)Four times the pixels is far more than four times the costCap device pixel ratio at 1.5–2
Real-time shadowsAn extra render pass for the shadow mapTurn shadows off on low-end devices
Particle countCreating thousands each frame taxes memory and GCPre-allocate and reuse (object pools)
Transparency and blurOverdraw multiplies fill costReduce layers; substitute with CSS

A rhythm game adds one more: with hundreds of notes in flight, only the notes inside the current judgement window should be updated. Do that and the frame cost stays roughly constant even in a five-minute track.

3. Putting buttons exactly on top of 3D

In a rhythm game what matters is that “where I pressed” and “where the note arrived” are the same coordinate. But the judge line in 3D moves on screen as the camera angle changes. Pin the buttons to the bottom of the page and a small camera turn desynchronises them.

The fix is projection: convert the 3D coordinate through the camera matrix into screen coordinates every frame, and place the buttons there.

// 3D judgement point → screen pixels
const v = new THREE.Vector3(laneX, padY, judgeZ).project(camera);
const x = (v.x * 0.5 + 0.5) * innerWidth;
const y = (-v.y * 0.5 + 0.5) * innerHeight;
pad.style.transform = `translate(${x}px, ${y}px)`;

With those lines the pads stay glued to the judge line even when the camera moves. Add a ripple at the judgement point on each press and the input starts to feel like it lands on the stage. The feel of a rhythm game usually comes from a handful of small alignments like this one.

4. Keeping time with the music

Judgement rests on “what second is it now”. Browsers offer several ways to measure that, and they drift apart.

  • performance.now() — accurate, but unrelated to audio.
  • audio.currentTime — the real playback position, but its value can jump between frames.
  • The Web Audio clock — based on the audio device’s sample position, so it drifts the least.

So rhythm games run on the audio clock and interpolate between screen updates. Judgement windows are set in milliseconds on the same basis. Our game uses Perfect ±85 ms, Great ±155 ms, Good ±230 ms. People perceive “simultaneous” within roughly ±30–50 ms, and a wider window is what lets a beginner enjoy the game.

Why Bluetooth earphones are risky. Sound takes 100–300 ms to leave the device and reach the earphones. The picture has already moved on while the sound arrives late, so even a perfectly timed press registers late. For score attempts, use wired earphones or speakers.
Advertisement

5. From audio to a chart

Generating the chart live instead of authoring it is simpler than it sounds.

  1. Slice the sound. Compute the frequency content of short windows (e.g. 1024–2048 samples) with an FFT.
  2. Measure band energy. Split into low, mid and high and record the strength of each.
  3. Look for change. A sudden rise over the previous window means “a new sound started” (spectral flux).
  4. Compare with the neighbourhood. Discard weak reverb and noise against a local median (adaptive threshold).
  5. Reduce to something playable. Cut the weakest 40% and enforce a minimum gap of 0.125 s between notes.
  6. Assign lanes. Strong low-frequency hits go to the outer lanes, strong high-frequency hits inside, with a correction so one side is not overloaded.

The strength is that any track works immediately. The weakness is that it cannot reproduce a song’s intended rhythm — a human chart follows the melody, while automatic charting follows transients. Tracks with clear drums and bass feel best; a reverb-heavy ballad produces few notes.

6. Surviving on mobile

More than half of visitors arrive on a phone. A game that runs well on desktop breaks in three places on mobile.

1) The screen is narrow

Four lanes designed for landscape overlap under two thumbs in portrait. Re-lay the judge bar and pads for portrait and adjust camera distance. Use env(safe-area-inset-*) so buttons do not hide under a notch or home bar.

2) Performance is lower

Cap the pixel ratio at 1.5–2, turn off shadows and antialiasing, and reduce particles. Device power is hard to measure, so use matchMedia('(pointer: coarse)') and screen size as a rough signal and start low.

3) Battery and heat

3D keeps the GPU busy and a phone gets warm within ten minutes. Pausing requestAnimationFrame when the page is hidden, and stopping the loop when the track ends, makes a noticeable difference.

If you want to build one

Follow this order and you will not take the long way round.

  1. HTML, CSS and JavaScript basics — events, async, array handling.
  2. A three.js tutorial — rotate one box, move the camera.
  3. Web Audio — play a sound and read the spectrum with an AnalyserNode.
  4. Finish one small game — build it in 2D first, then move it to 3D.
  5. Ship it — static files are enough for free hosting such as GitHub Pages.
The most common mistake. Decorating the 3D first. Build the skeleton — judgement, score, restart — then add lights and particles. Do it the other way and you will spend weeks polishing something that does not work.

FAQ

Are web games slower than apps?

For simple 3D the difference is barely noticeable. The first load has to fetch the engine and assets, so file size matters; after that, caching makes it fast.

Do they run on iPhone?

Recent Safari supports WebGL, but memory limits are strict — several large textures can make the tab reload. Keep texture sizes and simultaneous loads low.

Is my music uploaded?

It depends on the implementation. Our game reads and analyses files inside the browser and never uploads them. Check the privacy policy of any other service.

Do I need to code?

Game-making tools can do it without code, but fine-tuning — timing windows, camera angles, lane layout — is far easier with code.

Koong Family

Notes from building games and video that run in the browser. Send questions via contact.

Read next

Advertisement