CSS 개발자를 위한 GPU 2D 에디터 만들기
Guide
CSS Matrix
Guide
CSS Matrix
  • Part 0. CSS에서 GPU로 사고 전환

    • CSS 박스가 사라지면 무엇이 남는가
    • Canvas는 DOM이 아니라 픽셀 버퍼다
    • CSS pixel, device pixel, backing store
    • scene model과 renderer 분리하기
    • retained mode vs immediate mode
    • DOM event target 없이 hit testing 하기
  • Part 1. Canvas editor의 기본 뼈대

    • render loop와 frame lifecycle
    • viewport와 camera
    • screen/world/local 좌표계 복습
    • cursor anchored zoom
    • grid와 ruler를 canvas에 그리기
    • overlay layer와 control layer 분리
  • Part 2. WebGL 2D renderer

    • WebGL context와 첫 triangle
    • clip space와 화면 좌표
    • shader를 CSS transform 관점으로 읽기
    • rectangle을 두 triangle로 그리기
    • matrix uniform으로 camera 적용하기
    • 색상, alpha, blending
    • 여러 rectangle을 buffer에 담기
    • batching과 draw call 줄이기
    • instanced rectangle renderer
    • line/outline renderer
  • Part 3. Editor tool math

    • pointer 좌표를 world 좌표로 바꾸기
    • CPU hit testing
    • selection bounds
    • hover outline
    • move tool
    • resize handles
    • rotation handle
    • marquee selection
    • snapping과 smart guides
    • group transform
  • Part 4. Figma-like scene graph

    • node tree 설계
    • transform inheritance
    • layer order와 z sorting
    • frame과 clipping
    • fill, stroke, effect 모델
    • command model과 undo/redo
    • JSON export/import
    • renderer-independent editor core
  • Part 5. Image, text, vector

    • texture로 image node 그리기
    • texture atlas 기본
    • text rendering 전략
    • SVG/text를 GPU editor에서 다루는 경계
    • vector path는 어디까지 직접 구현할 것인가
  • Part 6. WebGPU로 옮기기

    • WebGPU adapter/device/context
    • WGSL과 render pipeline
    • WebGL renderer를 WebGPU renderer로 바꾸기
    • uniform buffer와 bind group
    • WebGPU instancing
    • WebGL/WebGPU fallback 전략
  • Part 7. Capstone

    • editor shell 만들기
    • toolbar / layer panel / inspector 연결
    • mini Figma-like editor 완성
    • 성능 점검과 디버깅
    • 배포와 브라우저 호환성 체크
  • Part 8. Three.js로 WebGL 개발하기

    • Three.js를 WebGL renderer로 쓰는 기준
    • Scene, Camera, Renderer, render loop
    • OrthographicCamera로 2D editor 좌표계 만들기
    • BufferGeometry, Material, ShaderMaterial
    • Raycaster와 editor picking
    • Three.js renderer를 editor core 뒤에 붙이기
    • Three.js 프로젝트 세팅과 renderer lifecycle
    • Object3D transform과 editor scene graph 매핑
    • InstancedMesh로 많은 rectangle 그리기
    • Texture, CanvasTexture, Sprite로 이미지/텍스트 다루기
    • Three.js에서 outline, selection, overlay 만들기
    • dispose, cache, renderer.info로 성능 관리하기
    • WebGPURenderer와 TSL로 넘어가는 길
    • RenderTarget을 이용한 picking buffer
    • Three.js를 쓰면 안 좋은 경우
  • Appendix A. GPU editor debugging

    • WebGL/WebGPU 디버그 overlay 만들기
    • 좌표계, matrix, bounds readout 설계
    • frame time, draw call, buffer upload 측정하기
    • Spector.js / Chrome DevTools로 WebGL 프레임 보기
  • Appendix B. Browser and GPU compatibility

    • WebGL/WebGPU feature detection 체크리스트
    • DPR, resize, context lost 처리
    • Safari/Chrome/Firefox 차이와 fallback 정책
    • GPU memory와 texture size 제한
  • Appendix C. Asset pipeline

    • 이미지 로딩, ImageBitmap, texture upload
    • SVG를 texture로 쓸지 vector로 유지할지
    • 폰트 로딩과 text metrics
    • export용 PNG/SVG/JSON 생성 전략
  • Appendix D. Interaction polish and motion

    • inertial pan과 smooth zoom
    • snapping feedback animation
    • selection/hover transition
    • timeline 없이 필요한 최소 모션 수학
  • Appendix E. Production architecture

    • renderer worker / OffscreenCanvas를 고려하는 기준
    • document model versioning과 migration
    • plugin architecture와 command API
    • test 가능한 renderer abstraction 만들기
  • Appendix F. 2D renderer engine patterns

    • renderable type 선택: shape, sprite, mesh
    • static subtree를 texture cache로 굽기
    • render layer와 render group 설계
    • viewport culling과 spatial index
    • clipping 구현: scissor, stencil, mask texture
    • filters와 blend modes가 batch를 깨는 이유
    • interactivity budget: pickable, hitArea, skip children
    • texture GC와 idle resource eviction
    • dynamic text update 비용과 bitmap/glyph 전략
    • Canvas/WebGL editor의 accessibility layer
  • Appendix G. Rendering editor production gaps

    • render invalidation과 dirty flag
    • color space, premultiplied alpha, export 색상
    • stroke join/cap/dash/fill rule
    • editable text: DOM overlay, IME, caret, metrics
    • tool state machine과 pointer capture
    • pixel test와 renderer regression test

texture atlas 기본

이미지나 glyph를 그릴 때 texture를 자주 바꾸면 비용이 커집니다. 작은 이미지들을 하나의 큰 texture에 모아두고, uv 범위만 다르게 쓰는 방법이 texture atlas입니다.

atlas rect를 uv로 바꾸는 코드

atlas 안의 pixel rect를 shader가 읽을 uv rect로 변환합니다.

function atlasRectToUv(rect, atlas) {
  return {
    u0: rect.x / atlas.width,
    v0: rect.y / atlas.height,
    u1: (rect.x + rect.width) / atlas.width,
    v1: (rect.y + rect.height) / atlas.height
  };
}

function pushAtlasQuad(vertices, node, uv) {
  const x0 = node.x;
  const y0 = node.y;
  const x1 = node.x + node.width;
  const y1 = node.y + node.height;

  vertices.push(
    x0, y0, uv.u0, uv.v0,
    x1, y0, uv.u1, uv.v0,
    x0, y1, uv.u0, uv.v1,
    x0, y1, uv.u0, uv.v1,
    x1, y0, uv.u1, uv.v0,
    x1, y1, uv.u1, uv.v1
  );
}

같은 atlas texture를 쓰는 quad는 같은 gl.bindTexture 상태로 이어서 그릴 수 있습니다. 이것이 atlas가 batching에 유리한 이유입니다.

atlas는 이미지 묶음이다

여러 작은 이미지를 하나의 큰 texture에 배치합니다.

atlas texture
  icon A: x, y, w, h
  icon B: x, y, w, h
  glyph ㄱ: x, y, w, h

각 sub image는 atlas 안의 rect를 가집니다.

uv rect를 계산한다

atlas pixel rect를 0..1 uv 범위로 바꿉니다.

u0 = x / atlasWidth
v0 = y / atlasHeight
u1 = (x + width) / atlasWidth
v1 = (y + height) / atlasHeight

renderer는 node마다 이 uv rect를 vertex나 instance data로 보낼 수 있습니다.

atlas는 batching에 좋다

같은 atlas texture를 쓰는 image quad들은 texture bind를 바꾸지 않고 한 batch로 그릴 수 있습니다.

same shader
same texture atlas
many quads

text rendering에서도 glyph atlas를 쓰면 많은 글자를 같은 texture로 그릴 수 있습니다.

오늘의 핵심

texture atlas는 texture 전환을 줄이기 위한 렌더링 자료구조입니다.

many small images
-> one texture
-> many uv rects
-> fewer state changes

문서 모델에는 atlas packing 결과가 아니라 asset reference와 layout 정보가 남아야 합니다.

최근 수정: 26. 5. 16. PM 12:53
Contributors: jinho.park.s3
Prev
texture로 image node 그리기
Next
text rendering 전략