레슨 4 / 8·20분
텍스처와 머티리얼
텍스처 로딩과 적용
텍스처(Texture)는 3D 객체의 표면에 이미지를 입혀 사실적인 외관을 만듭니다. Three.js의 TextureLoader를 사용하여 이미지를 로드하고, 머티리얼의 map 속성에 할당합니다. 다양한 맵(normalMap, roughnessMap, displacementMap 등)을 조합하면 PBR(물리 기반 렌더링)으로 매우 사실적인 질감을 표현할 수 있습니다.
javascript
import * as THREE from 'three';
// TextureLoader로 이미지 텍스처 로딩
const loader = new THREE.TextureLoader();
// 단일 텍스처 로드
const colorMap = loader.load('/textures/brick_color.jpg');
// 텍스처를 머티리얼에 적용
const material = new THREE.MeshStandardMaterial({
map: colorMap, // 색상 텍스처 (기본)
metalness: 0.1,
roughness: 0.8,
});
const cube = new THREE.Mesh(
new THREE.BoxGeometry(2, 2, 2),
material
);
scene.add(cube);PBR 머티리얼과 다중 텍스처 맵
javascript
const loader = new THREE.TextureLoader();
// 여러 텍스처 맵을 조합한 PBR 머티리얼
const pbrMaterial = new THREE.MeshStandardMaterial({
map: loader.load('/textures/stone_color.jpg'), // 색상 맵
normalMap: loader.load('/textures/stone_normal.jpg'), // 법선 맵 (입체감)
roughnessMap: loader.load('/textures/stone_rough.jpg'), // 거칠기 맵
aoMap: loader.load('/textures/stone_ao.jpg'), // 앰비언트 오클루전
displacementMap: loader.load('/textures/stone_disp.jpg'),// 변위 맵
displacementScale: 0.1,
});
const sphere = new THREE.Mesh(
new THREE.SphereGeometry(1, 64, 64),
pbrMaterial
);
scene.add(sphere);
// 텍스처 반복 설정
const texture = loader.load('/textures/tile.jpg');
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(4, 4);javascript
// 환경 맵(Environment Map)으로 반사 효과
const cubeTextureLoader = new THREE.CubeTextureLoader();
const envMap = cubeTextureLoader.load([
'/textures/env/px.jpg', '/textures/env/nx.jpg',
'/textures/env/py.jpg', '/textures/env/ny.jpg',
'/textures/env/pz.jpg', '/textures/env/nz.jpg',
]);
scene.environment = envMap;
const chromeMatl = new THREE.MeshStandardMaterial({
color: 0xffffff,
metalness: 1.0,
roughness: 0.05,
envMap: envMap,
envMapIntensity: 1.0,
});
const chromeSphere = new THREE.Mesh(
new THREE.SphereGeometry(1, 32, 32),
chromeMatl
);
scene.add(chromeSphere);- •map — 기본 색상 텍스처, 객체의 외관 색을 결정
- •normalMap — 표면의 미세한 요철을 시뮬레이션 (입체감)
- •roughnessMap — 픽셀별 거칠기를 제어
- •displacementMap — 실제로 정점을 이동시켜 높낮이 표현
- •envMap — 환경 반사 맵, 금속이나 유리 재질에 사용
💡
텍스처 파일은 2의 거듭제곱 크기(512x512, 1024x1024 등)가 GPU에서 가장 효율적입니다. 큰 텍스처는 메모리를 많이 차지하므로, 필요에 따라 적절한 해상도를 선택하세요.