모션 패럴랙스

Motion parallax

시점이 옆으로 움직일 때 가까운 물체는 빠르게, 먼 물체는 느리게 지나가 보이는 현상. 양안 없이도 뇌가 깊이를 읽는 단서입니다.

다른 이름: Depth cueParallax depth
···
html
<div class="depth">
  <div class="layer far"></div>
  <div class="layer mid"></div>
  <div class="layer near"></div>
</div>
<div class="eye"></div>
css
.depth{position:absolute;inset:0;overflow:hidden;background:linear-gradient(180deg,#bcd7ea,#e9e6d8 65%)}
.layer{position:absolute;left:-15%;right:-15%;bottom:0}
.far{height:30%;background:#a9bdae;opacity:.6;
  clip-path:polygon(0 100%,0 58%,12% 32%,24% 62%,38% 22%,52% 56%,66% 18%,80% 50%,92% 26%,100% 56%,100% 100%)}
.mid{height:22%;background:#79a082;opacity:.8;
  clip-path:polygon(0 100%,0 42%,16% 72%,30% 22%,46% 62%,60% 12%,76% 56%,90% 26%,100% 60%,100% 100%)}
.near{height:15%;background:#3f5744;
  clip-path:polygon(0 100%,0 24%,10% 62%,22% 8%,34% 52%,48% 2%,60% 46%,74% 12%,86% 56%,100% 18%,100% 100%)}
.eye{position:absolute;left:50%;bottom:4%;width:6%;aspect-ratio:1.6;border-radius:3px;background:var(--fg);
  opacity:.7;transform:translateX(-50%)}
js
const far=document.querySelector('.far');
const mid=document.querySelector('.mid');
const near=document.querySelector('.near');
const eye=document.querySelector('.eye');
function frame(t){
  const shift=Math.sin(t*0.0007);
  far.style.transform='translateX('+(shift*3)+'%)';
  mid.style.transform='translateX('+(shift*10)+'%)';
  near.style.transform='translateX('+(shift*22)+'%)';
  eye.style.left=(50+shift*30)+'%';
  requestAnimationFrame(frame);
}
requestAnimationFrame(frame);

기차 창밖을 볼 때 가까운 전봇대는 순식간에 지나가지만 먼 산은 거의 움직이지 않는 것처럼 보입니다. 이건 착시가 아니라 기하학입니다 — 같은 속도로 시점이 이동해도, 시점에서 가까운 물체는 시야각 변화가 크고 먼 물체는 변화가 작기 때문입니다.

이 원리 덕분에 한쪽 눈만 있어도 뇌는 어느 것이 가깝고 먼지 순서를 읽어낼 수 있습니다 — 이것이 '모션 패럴랙스'가 깊이를 지각하는 단서(depth cue) 중 하나로 꼽히는 이유입니다. 양쪽 눈의 시차로 깊이를 읽는 입체시(binocular disparity)와는 다른 메커니즘입니다.

웹·게임 UI에서는 배경을 여러 레이어로 나누고, 스크롤이나 마우스 이동에 맞춰 레이어마다 다른 속도로 이동시켜 이 단서를 인공적으로 만듭니다. 데모는 같은 가로 이동값을 레이어마다 다른 배율로 곱해서, 하나의 '시점 이동'이 만들어내는 속도 차이를 보여줍니다.

언제 쓰나

스크롤 히어로 배경에서 깊이감을 주거나, 게임의 2.5D 배경을 구현할 때. 레이어가 너무 많거나 배율 차이가 크면 오히려 어지럽습니다.